NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Array creation and access
November 06, 2011 by rob_k |
I am attempting to store a series of "off", "on" states in an array. However it seems that using the array is not working. I have tested my code (modified a bit to print to stdout) on a normal gcc compiler, and everything works as expected. Can anyone see what would be wrong with the following code? The led never turns on or off. But I can turn the led on and off when i do not use an array.
|
---|---|
November 06, 2011 by bl00513 |
Please let me know if you figure out what is actually going on with this. I too have been having some array problems. I am just using some simple UART / printf commands, but when I use them to display variable (from an array) I get nothing. I know this isn't any help to you, but at least you know you aren't the only person running into some array problems. |
November 06, 2011 by rob_k |
if you look at this post it seems that the data section was not being flashed to the chip. I was able to add "-j .data" (leave -j .text there too) and it seems to work just fine. Can someone give me a quick and dirty definition of what the PROGMEM macro does? And perhaps why -j .data is not enabled by default? |
November 07, 2011 by JimFrederickson |
I am pretty sure there are 2 reasons why this occurring for you, and why the Nerdkit Project Makefiles are setup the way they are. (Just to know, I am NOT talking for Nerdkits, only I believe this is accurate...) The AVR CPU's are based a the 'Harvard Architecture'. This means that the Program space and the Data Space are separate areas. (Most desktop computers are based on the 'Von Newmann Arhitecture' where these spaces are combined.) In fact in the AVR CPU's they are actually in a different 'format' as well. Additionally, the AVR CPU's are mostly for 'Control Applications' where memory is often at a 'premium' so creating code that has a minimal space footprint is often important as well. So any 'constants/literals' that are declared in the c program are normally stored in the program space so that 'writeable data space' use is mitigated. There are functions, and initialization routines, that the Nerdkits implementation of c for the AVR CPU's has that will copy these 'constants/literals' to the 'data space'. For me... I just always initialize arrays or structures that I want in code. See these links, which I think will further explain this... NOTE: For the first one it may not seem 'immediately clear' that it is referencing what you are looking for, but keep reading. http://www.nerdkits.com/forum/thread/100/ |
Please log in to post a reply.
Did you know that interrupts can be used to trigger pieces of code when events happen? Learn more...
|