I am assigning the array DriveTech[0][0] value to PORTB but in stead of PORTB taking its value, 0xf1, it is turned to 0x00 when I run the simulation. What gives? compiler optimization error?
Assignment turns PORTB to 0x00! Help please?
No one here is psychic. Only you know what "DriveTech[][]" is and what it is supposed to contain.
Can we assume it is "const __flash uint8_t DriveTech[N][M] = { ..." or something?
If, for example it is PROGMEM then you forgot the pgm_read_byte() dereference to access it!
Yeah, sorry for not including that. And yep.. you're right :| It is progmem and I forgot I needed to include that. Thanks you tons!
Which is a strong reason NOT to use PROGMEM. Unless using C++ (where it is not available) then __flash is better in almost every respect. Instead of:
const PROGMEM uint8_t DriveTech[5][3] = { {7, 8, 9}, {5, 18, 23} etc. }; PORTB = pgm_read_byte(&DriveTech[2][1]);
you really could just use:
const __flash uint8_t DriveTech[5][3] = { {7, 8, 9}, {5, 18, 23} etc. }; PORTB = DriveTech[2][1];
Because "__flash" is a modifier that is inherent in the data type, when the compiler comes to read the data it already knows this has to be an LPM not an LDS read. No more need for any pgm_read_XXX(&...) nonsense any more.
I had no idea O_O this is great!! Thanks again =]
I am using Atmel Studio and arduino IDE so C++. What other options are there for programming AVRs? __flash is not recognised in my code right now.
If you know of a book or a good source to learn about AVR programming please tell me.
I am using Atmel Studio and arduino IDE so C++.