playing with external sram

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

playing with external sram

Post by brandonb »

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 :lol: 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,

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
}
- now a write can be done,(in sudo code):

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
}
- to read data back the inverse is done

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)
here is chip operation
1.jpg
1.jpg (48.38 KiB) Viewed 8430 times
2.gif
2.gif (76.96 KiB) Viewed 8430 times
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
Attachments
SPI SRAM BYTE.fcf
saves 0-32767 & recalls 0-32767
(22.77 KiB) Downloaded 449 times
Last edited by brandonb on Sun Feb 24, 2013 1:34 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: playing with external sram

Post by medelec35 »

Hi Brandon,
This is great, what an informative article!
Thanks for posting.
It has made me want to have a play with some exteral sram now :P

I have moved topic to Tips & tricks section so its easier for people to find.
If left in V5 section it will soon get buried amoungst all the other posts
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: playing with external sram

Post by brandonb »

previous example was byte read and write mode, in this example we can fill all the ram locations at once with out delays with one address, then read them all back with one address, key to this is in sequel mode it autoadvances from the start address!
to enable sequel operation (C0=0, spi_write(1), spi_write(64),C0=1)
im using same fcf example only modified for different mode
for this mode just give it a start address (C0=0, spi_write(2), spi_write(0), spi_write(0)
then you can send 0-65535 bytes one after the other without delays, after the last byte sent make C0=1
to read them all back its the same way but inverse
(C0=0, spi_Write(3), spi_write(0), spi_write(0),
then send as many spi_read() as you want, when done end with C0=1
if only eeprom were like this instead of having to use page write :lol:
SPI SRAM SEQUEL.fcf
(22.23 KiB) Downloaded 447 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: playing with external sram

Post by Enamul »

Thanks for sharing us this. I was in-need of using higher RAM for an application. I will give a try and come to you if stuck anywhere.
Enamul
University of Nottingham
enamul4mm@gmail.com

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: playing with external sram

Post by brandonb »

Thanks for sharing us this. I was in-need of using higher RAM for an application. I will give a try and come to you if stuck anywhere.
nahh man, i've never used spi or sram chips before tonight, just trying to inspire members to try them so we can all learn and make cool things, i really like the newer 16f chips and want to expand on them with extra ram and eeprom, if you follow the digikey parts link the datasheet is about midway down.... thanks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: playing with external sram

Post by Enamul »

Thanks for the link and being so generous.
Enamul
University of Nottingham
enamul4mm@gmail.com

DannyBerry
Posts: 29
Joined: Tue Aug 30, 2011 9:20 pm
Has thanked: 11 times
Been thanked: 1 time
Contact:

Re: playing with external sram

Post by DannyBerry »

Thanks Brandon, :D

Good Work ...as usual.

Post Reply