I am in the process of writing a simple read/write .c file to use to read and write data to the SRAM in lpc2138
I have successfully been able to write and then read from the SRAM with the value that i wrote there earlier
however if i then remove the write command from the code and then compile and load it onto the lpc2138 again i dont get the same number that i wrote there previously, i somehow suspect the IDE and programmer that i am using please help
I am using CrossStudio 1.7 with an OLIMEX ARM-USB-TINY
mwoo769:
however if i then remove the write command from the code and then compile and load it onto the lpc2138 again i dont get the same number that i wrote there previously
Maybe I misunderstood what you said but I would have been more surprised if you did get the same number.
If you want to preserve a value between separate executions of a program with any degree of confidence you will need to write it to Flash ROM using IAP, or to external EEPROM memory e.g. using I2C, or to some other persistent storage system.
i have since tested some more things with the SRAM on the lpc2138 and found that the act of reprogramming the chip via the JTAG programmer seems to wipe the SRAM memory however if i create a write command that writes a value from an incrementing counter into an address in SRAM using a pin state to initiate the write. Once the ARM7 has been turned off and then back on it will remember the last write instruction always.
I dont think there is a work around for this problem. So instead i have decided that in normal operations that if i am to reprogram the lpc2138 then after this i should reprogram the SRAM by a serial connection like USB transmitting a package containing all desired SRAM content. It will be messy at the start but when i get to a stage where i dont have to reprogram the lpc2138 i can alter its baudrate and other constants by sending a serial command.
But if anyone does know the exact reason why this is happening it would be good to know. I will also be doing an experiment to determine once i have written to SRAM for how long and to what extent the data will begin to degrade if at all. Just to check your assumption that values cant be stored in SRAM. I think they will be stored properly and for a long period of time.
Oh the data will degrade alright. If it didn’t when you turned off the power, then you didn’t wait long enough for the supply voltage to drop far enough. RAM will hold in pretty good even at low voltages, but once the voltage drops far enough, you will lose everything in RAM. It is volatile storage. If you want to keep data with the power off, you must use some form of non-volatile storage, like EEPROM, FLASH, NVRAM (battery backed up RAM), or FRAM.
As cfb and manton mentioned, it is not surprising that a value written in SRAM goes awaywhen the power goes off.
The “Static” of “Static RAM” does not mean that it is maintained without power but merely that you don’t need to send RAS/CAS to refresh the values as you would with an SDRAM.
Static RAM is usually constructed with gates that form a bistable entity for each bit stored (RS flif-flop or flavors thereof) while SDRAM is typically composed of tiny capacitors that are charged or discharged depending on the bit stored, and need to be refreshed regularly lest the value decays (the actual technologies vary wildly). Wth SRAM you can just write a value which remains maintained as long as the power stays on, while with SDRAM (DRAM, DDR RAM ETC.) you need a dedicated RAm controller that refreshes it.
Please do not mix up static RAM with non-volatile RAM.
Although it exists, it is pretty expensive and for the kind of processor you are interested in, persistent storage is done typically with flash or EEPROM (LPC2138 has flash). This is exactly what you are doing when you program the unit through the JTAG: you write the program to flash, and it remains after power off.
Check out the application notes for ISP and IAR and store your data in flash if you want them to persist.