SPI SST25VF512A

Questions on control of serial busses
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

SPI SST25VF512A

Post by YahooArchive »

I had to check out the connections to a serial Flash on a new board, and
think it makes a good example of how to debug this.

Looking at the spec sheet for this part, there is a device ID register.
Its a good way to make sure you've got it connected up correctly.
Here's the first program

#include
dim xi(10) as string
dim xo(10) as string
xo(0)=&H90
xo(1)=0
xo(2)=0
xo(3)=0
spiin(31,26,29,30,0,4,xo,2,xi)
print hex(xi(0)),hex(xi(1))

The values that came back were &H91 and &7E and it was repeatable, so
something was hooked up, but still not expected values of &HBF and &H48

A check of the spec sheet showed the data was available as soon as CS is
lowered, so this statement is needed

#define SPIpreSample

Then try to write some data

xo(0)=3
spiin(31,26,29,30,0,4,xo,1,xi) ' read at addr 0
print hex(xi(0))

xo(0)=6
spiout(31,29,30,0,1,xo) ' write enable

xo(0)=2
xo(4)=0xbe
spiout(31,29,30,0,5,xo) ' write 0xbe

wait 10 ' don't know how long it would take, but its less than this

xo(0)=3
spiin(31,26,29,30,0,4,xo,1,xi) ' read at addr 0
print hex(xi(0))

But it still didn't write, back to the spec sheet, and might try reading
the status

xo(0)=5
spiin(31,26,29,30,0,4,xo,1,xi) ' read status
print hex(xi(0))

This was showing &HC which according to the spec means all the memory is
write protected (seems like this is how its shipped from the factory).
So to enable writes this needs to be done

xo(0)=&H50
spiout(31,29,30,0,1,xo) ' status write enable
xo(0)=1
spiout(31,29,30,0,2,xo) ' disable block protect

Not pretty, but a quick test of the interface is done with the following
program it total (notice the xo(1) -(3) values were kept at 0

#define SPIpreSample

#include
dim xi(10) as string
dim xo(10) as string
xo(0)=&H90
xo(1)=0
xo(2)=0
xo(3)=0
spiin(31,26,29,30,0,4,xo,2,xi)
print hex(xi(0)),hex(xi(1))

xo(0)=5
spiin(31,26,29,30,0,4,xo,1,xi) ' read status
print hex(xi(0))

xo(0)=&H50
spiout(31,29,30,0,1,xo) ' status write enable
xo(0)=1
spiout(31,29,30,0,2,xo) ' disable block protect

xo(0)=3
spiin(31,26,29,30,0,4,xo,1,xi) ' read at addr 0
print hex(xi(0))

xo(0)=6
spiout(31,29,30,0,1,xo) ' write enable

xo(0)=2
xo(4)=0xbe
spiout(31,29,30,0,5,xo) ' write 0xbe


xo(0)=5
spiin(31,26,29,30,0,4,xo,1,xi) ' read status
print hex(xi(0))

wait 10

xo(0)=3
spiin(31,26,29,30,0,4,xo,1,xi) ' read at addr 0
print hex(xi(0))

and the resultant output

Programming Flash 2103...*+
... 3.52K code 0.16K data programmed

Executing...

bf 48
c
ff
0
be


... Finished in 19 ms



Post Reply