Assignment turns PORTB to 0x00! Help please?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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?

This topic has a solution.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

Last Edited: Thu. Dec 12, 2019 - 10:37 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

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!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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!

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

Last Edited: Thu. Dec 12, 2019 - 10:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tellSlater wrote:
I am using Atmel Studio and arduino IDE so C++.
I'm afraid you cannot use __flash then. It is only in C, not C++ (though you could create a mixed C/C++ project I guess?)