<avr/pgmspace.h> issues, "pgm_read_byte_far is not defined in this scope"

Discussion in 'Programmer's Corner' started by magnet18, Oct 7, 2013.

  1. magnet18

    Thread Starter Senior Member

    Dec 22, 2010
    1,232
    124
    Hello,
    I'm trying to store a large amount of data, and access it later, and keep having problems with the pgmspace.h library

    here is some sample code I'm trying to get to work-
    Code ( (Unknown Language)):
    1. #include <avr/pgmspace.h>
    2. #include <avr/io.h>
    3.  
    4. const PROGMEM prog_uint32_t values[464] = {0,0,0,0,0,0,0,0,1257748416,2229081720,1240970799,2245859341,2764547699,1044158077,145805968,1665077079,3543340382,3647850701,783502585,1027380462,1161462934,1734760853,3576895619,3681405940,3560117998,3631073085,1257748418,2212304103,112250734,1631521837,766724968,1044158079,3419021935,1631521837,1257748418,2229081722,1161462934,1734760853,3543340381,3427764041,3170838271,2900333579,1161462934,1734760853,1257748416,2245859343,2307288137,1751538471,3720504383,4146893830,2093295842,2923692692,3170838271,2900333579,3368689078,1648299456,2256955281,1768316091,3419021935,1631521837,1619258661,3681405943,1619258661,3681405943,2102920994,2977155184,223386377,3648407043,3368689077,1648299459,1257748418,2229081722,1619258662,3681405940,2153253851,2960377565,240163998,3598074184,4100743723,606269605,3419021935,1631521837,625947228,414840686,2256955281,1768316091,2256955282,1768316088,1257748418,2245859341,162583588,1648299459,3419021932,1631521838,609169610,465173540,2256955280,1768316090,1257748416,2212304101,0,0,145805968,1665077079,4007399933,2740290906,1240970797,2245859343,2714214840,1060935698,2076518223,2974025549,3419021935,1631521837,2307288139,1751538469,1257748416,2245859343,3368689078,1648299456,2307288136,1751538470,1161462933,1734760854,3543340382,3647850701,3576895616,3681405943,2256955280,1768316090,3419021932,1631521838,1257748418,2229081722,1619258661,3681405943,1338156279,2548695961,4083966100,589491990,3543340382,3427764042,0,0,0,0,0,0,145805971,1665077076,1258711737,1507021574,0,0,783502587,1027380460,3820868508,2993932807,145805968,1665077079,3368689076,1648299458,3368689077,1648299459,400462113,2119371906,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3440843972,1821392518,4083966100,589491990,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4024177552,2790623763,2256955281,1768316091,1257748418,2245859341,1257748416,2245859343,0,0,2714214842,1060935696,3368689078,1648299456,0,0};
    5. uint32_t iValuePrev;
    6. uint32_t iValueCurr;
    7. int i = 0;
    8.  
    9. void setup() {
    10.   Serial.begin(9600);
    11.   delay(500);
    12.   Serial.println("working");
    13. }
    14.  
    15. void loop() {
    16.  
    17.   iValuePrev = pgm_read_byte((values[i]));
    18.   iValueCurr = pgm_read_byte(&(values[i]));
    19.   Serial.println(iValuePrev);
    20.   Serial.println(iValueCurr);
    21.   delay(500);
    22.   i++;
    23. }[/i][/i]


    but it resutlts in
    Code ( (Unknown Language)):
    1. working
    2. 12
    3. 0
    4. 12
    5. 0
    6. 12
    7. 0
    8. 176
    9. 0
    10. more seemingly random values between 0 and 255
    11.  
    and trying the same code with "pgm_read_byte_long" results in
    Code ( (Unknown Language)):
    1. sketch_oct07b.ino: In function ‘void loop()’:
    2. sketch_oct07b:18: error: ‘pgm_read_byte_long’ was not declared in this scope
    can anyone help me?

    If you're curious, here's the project code it came from-
    Code ( (Unknown Language)):
    1. #include <IRremote.h>
    2. #include <avr/pgmspace.h>
    3.  
    4. //#define pgm_read_byte_far(address_long)
    5.  
    6. int RECV_PIN = 11;
    7. IRrecv irrecv(RECV_PIN);
    8. decode_results results;
    9.  
    10. PROGMEM prog_uint32_t values[464] = {0,0,0,0,0,0,0,0,1257748416,2229081720,1240970799,2245859341,2764547699,1044158077,145805968,1665077079,3543340382,3647850701,783502585,1027380462,1161462934,1734760853,3576895619,3681405940,3560117998,3631073085,1257748418,2212304103,112250734,1631521837,766724968,1044158079,3419021935,1631521837,1257748418,2229081722,1161462934,1734760853,3543340381,3427764041,3170838271,2900333579,1161462934,1734760853,1257748416,2245859343,2307288137,1751538471,3720504383,4146893830,2093295842,2923692692,3170838271,2900333579,3368689078,1648299456,2256955281,1768316091,3419021935,1631521837,1619258661,3681405943,1619258661,3681405943,2102920994,2977155184,223386377,3648407043,3368689077,1648299459,1257748418,2229081722,1619258662,3681405940,2153253851,2960377565,240163998,3598074184,4100743723,606269605,3419021935,1631521837,625947228,414840686,2256955281,1768316091,2256955282,1768316088,1257748418,2245859341,162583588,1648299459,3419021932,1631521838,609169610,465173540,2256955280,1768316090,1257748416,2212304101,0,0,145805968,1665077079,4007399933,2740290906,1240970797,2245859343,2714214840,1060935698,2076518223,2974025549,3419021935,1631521837,2307288139,1751538469,1257748416,2245859343,3368689078,1648299456,2307288136,1751538470,1161462933,1734760854,3543340382,3647850701,3576895616,3681405943,2256955280,1768316090,3419021932,1631521838,1257748418,2229081722,1619258661,3681405943,1338156279,2548695961,4083966100,589491990,3543340382,3427764042,0,0,0,0,0,0,145805971,1665077076,1258711737,1507021574,0,0,783502587,1027380460,3820868508,2993932807,145805968,1665077079,3368689076,1648299458,3368689077,1648299459,400462113,2119371906,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3440843972,1821392518,4083966100,589491990,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4024177552,2790623763,2256955281,1768316091,1257748418,2245859341,1257748416,2245859343,0,0,2714214842,1060935696,3368689078,1648299456,0,0};
    11. uint32_t previous = 1;
    12. uint32_t end_all = 4146893829;
    13. int code = 0;
    14.  
    15. uint32_t output = 0;
    16. uint8_t buf[8] = {0};   /* Keyboard report buffer */
    17.  
    18. void setup() {
    19.   Serial.begin(9600);
    20.   irrecv.enableIRIn(); // Start the receiver
    21.   delay(200);
    22.   Serial.println("working");
    23. }
    24.  
    25. void loop() {
    26.   if (irrecv.decode(&results)) {
    27.     if (results.value == end_all) {
    28.       releaseAllKeys();
    29.       previous = 1;
    30. //    }else if(results.value == 656){
    31. //      buf[2] = 127;
    32. //      Serial.write(buf, 8);   // Send keypress
    33. //    }else if(results.value == 1168){
    34. //      buf[2] = 128;
    35. //      Serial.write(buf, 8);   // Send keypress
    36. //    }else if(results.value == 3216){
    37. //      buf[2] = 129;
    38. //      Serial.write(buf, 8);   // Send keypress
    39.     }else{
    40.       Serial.print("results.value = ");
    41.       Serial.println(results.value);
    42.       Serial.print("previous = ");
    43.       Serial.println(previous);
    44.       for (int i=0; i < 464; i=i+2) {
    45.         //Serial.println(i);
    46.         uint32_t iValuePrev = pgm_read_byte(&(values[i]));
    47.         uint32_t iValueCurr = pgm_read_byte(&(values[i+1]));
    48.         Serial.print("iValuePrev = ");
    49.         Serial.println(iValuePrev);
    50.         Serial.print("iValueCurr = ");
    51.         Serial.println(iValueCurr);
    52.        
    53.         if (previous == iValuePrev){
    54.           Serial.println("Previous Match");
    55.           if(results.value == iValueCurr) {
    56.             buf[2] = i/2;
    57.             Serial.println("value detected");
    58.             Serial.println(buf[2]);
    59.             //Serial.println(i/2);
    60.             //Serial.write(buf, 8); // Send keypress
    61.             i = 464;
    62.           }
    63.         }
    64.       }
    65.       //releaseKey();
    66.       previous = results.value;
    67.       Serial.print("new_previous = ");
    68.       Serial.println(previous);
    69.      
    70.     }
    71.     irrecv.resume(); // Receive the next value
    72.   }
    73. }
    74.  
    75. void releaseKey() {
    76.   buf[0] = 0;
    77.   buf[2] = 0;
    78.   Serial.println("releaseKey");
    79.   //Serial.write(buf, 8);   // Release key  
    80. }
    81.  
    82. void releaseAllKeys() {
    83.   buf[0] = 0;
    84.   buf[1] = 0;
    85.   buf[2] = 0;
    86.   buf[3] = 0;
    87.   buf[4] = 0;
    88.   buf[5] = 0;
    89.   buf[6] = 0;
    90.   buf[7] = 0;
    91.   Serial.println("releaseAllKeys");
    92.   //Serial.write(buf, 8);   // Release key  
    93. }[/i]



    edit, the error was in using the byte command, I should have used pgm_read_dword
     
    Last edited: Oct 7, 2013
Loading...