Default Atmega128 storage is SRAM?

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

On an Atmega128:

 

When I, for example, store incoming characters at the serial port into a char array, or store an A2D measurement into an int, is the default memory location the onboard SRAM? I am not cognizant of specifying which memory to save to in my code, so wherever I'm saving to is the default setting (using CodeVisionAVR).

 

I've read the datasheet and their terminology is a little confusing to me, but as near as I can tell the program memory is located in flash, and any data stored or manipulated by the program is SRAM. Is that correct?

 

I ask because I'd like to lock the flash bits, and I don't want to do that and find out that I'm actually storing data there and after I lock the bits the program won't work because it can't store data.

 

Oh, and if I lock the flash bits then I can't reprogram the processor again unless I erase it first, correct? When I program a chip using CAVR, I see a message at the bottom stating that the chip is being erased, so I guess there is nothing further I need to do to enable that feature?

Last Edited: Wed. May 5, 2021 - 10:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lavadisco wrote:
I can tell the program memory is located in flash, and any data stored or manipulated by the program is SRAM. Is that correct?

Yes it is.

All variables be it static, local or global are stored in SRAM by default. Unless you make them not to by using const __flash qualifier. In that case they will be stored in program memory. Corrected below.

 

Lock bits have more to do with - prevent reading the flash memory (i.e your written program) from an outside device. Or disabling the use of LPM (load program memory) and SPM(store program memory) instructions in either the application section or boot section or both.

lavadisco wrote:
if I lock the flash bits then I can't reprogram the processor again unless I erase it first, correct?

Yes. Erase is the only options left at the point. You can't read the flash memory either.

Last Edited: Thu. May 6, 2021 - 12:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. Can you help me understand something - is erasing the chip and then programming it not how it's usually done? Is there a way to overwrite without erasing, and is that more common than erasing first? Is there a downside to erasing (like, using up more cycles on the flash or something)?

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

From frequent programming perspective (flashing over and over) on the prototype, don't worry about the flash write cycles too much.

lavadisco wrote:
Is there a way to overwrite without erasing

Yes, but overwrite without erasing or erasing first and then flashing, doesn't really matter. You can do any, whatever makes you feel better. You won't run out of write cycles that easily anyway.

 

Keep programming !!! cheeky

Last Edited: Wed. May 5, 2021 - 11:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heisen wrote:
All variables be it static, local or global are stored in SRAM by default. Unless you make them not to by using const __flash qualifier. In that case they will be stored in program memory.

 

Um, are you saying that I can write my ADC readings to program memory simply by using 'const__flash' as opposed to storing them in SRAM?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Oops! Nooo, forgot to mention "const __flash" is only to store constant data in program memory, which do not change during runtime of the program.