playing with external sram
Posted: Sun Feb 24, 2013 9:08 am
picked up some new chips for communication projects, the one of current discussion is this one http://www.digikey.com/scripts/DkSearch ... 16&cur=USD
this chip is easy to use, since im using a 16f1939 with 32k of memory i thought it would be funny if i also have external spi of about the same memory sram and eeprom, seems like overkill but you never know
note: i only use this chip in byte mode
since its a 512kb chip, thats 65536 extra bytes of ram, thats addressed 0-65535 but broken down into two bytes
- first thing is initialize spi with settings in simi box
- command C0=1 which is slave select high
- write to the mode register for byte mode( C0=0, spi_write(1), spi_write(0), C0=1)
- can read the mode register back with (C0=0, spi_write(5), spi_read(), C0=1)
- then to write suppose we want to write a 1028 to address 500-501 we could do this with 6 variables to keep it simple to see,
- now a write can be done,(in sudo code):
- to read data back the inverse is done
here is chip operation
wanted to add: fcf writes 0-32766 which is 16 bit numbers taking up two ram locations per number, so total ram locations used is 32767*2 bytes
this chip is easy to use, since im using a 16f1939 with 32k of memory i thought it would be funny if i also have external spi of about the same memory sram and eeprom, seems like overkill but you never know

since its a 512kb chip, thats 65536 extra bytes of ram, thats addressed 0-65535 but broken down into two bytes
- first thing is initialize spi with settings in simi box
- command C0=1 which is slave select high
- write to the mode register for byte mode( C0=0, spi_write(1), spi_write(0), C0=1)
- can read the mode register back with (C0=0, spi_write(5), spi_read(), C0=1)
- then to write suppose we want to write a 1028 to address 500-501 we could do this with 6 variables to keep it simple to see,
Code: Select all
to break the 16 bit (unsigned int) data and address variables down into two 8 bit variables, we need two extra variables for each
{
address=500
data=1028
address_low = address & 0xff
address_high = (address >> 8) & 0xff
data_low = data & 0xff
data_high = (data >> 8) & 0xff
}
Code: Select all
loop_counter=0//byte variable
looped two times
{
C0=0
spi_write(2)//write to ram command
spi_write(address_high)
spi_write(address_low)
if(loop_counter=1){
spi_write(data_low)
}
else
{
spi_write(data_high)
address=address+1
address_low = address & 0xff
address_high = (address >> 8) & 0xff
}
C0=1
loop_counter=loop_counter+1
}
Code: Select all
loop_counter=0//byte variable
address=500
address_low = address & 0xff
address_high = (address >> 8) & 0xff
looped two times
{
C0=0
spi_write(3)//read from ram command
spi_write(address_high)
spi_write(address_low)
if(loop_counter=1){
spi_read(data_low)
}
else
{
spi_read(data_high)
address=address+1
address_low = address & 0xff
address_high = (address >> 8) & 0xff
}
C0=1
loop_counter=loop_counter+1
}
data=data_low+(data_high<<8)