Author Topic: AVR 0 Series- Reading flash Memory  (Read 500 times)

0 Members and 1 Guest are viewing this topic.

Offline sanka1pTopic starter

  • Contributor
  • Posts: 23
  • Country: us
AVR 0 Series- Reading flash Memory
« on: December 06, 2023, 10:25:00 pm »
Hi All,

I am using Atmega1608 and Microchip studio. I am trying to read data at a certain location in flash, how can I do that? I tried using pgm_read_byte(0x3FFE), but it didnt return any value? I filled my flash with 0xFF so it should be returning 255 at-least. Anything wrong here?
Using Analog in a Digital world.
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 828
Re: AVR 0 Series- Reading flash Memory
« Reply #1 on: December 07, 2023, 02:26:26 am »
Quote
but it didnt return any value?
You cannot have a return of no value, whether your address is valid or not. That function always returns a byte value of 0-255 so you got one of those values, and whether you used that return value or not you will still get the lpm instruction when using that macro.

Flash access examples-
https://godbolt.org/z/35Pfxnoax

Any const var by default will be place in flash and given a virtual memory mapped address (for avr0/1/etc series), so accessing const vars requires nothing special (no need for the pgmspace macros). In your case, you simply want to read a flash address that is not a toolchain produced var so need to use any of the methods in the example above (which specify the memory mapped address, or if using the pgmspace macros the 0 based address).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf