Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:29 12 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Communicating with an SPI EEPROM

Author Message
Dedericus
Newbie

Joined: 19/01/2018
Location: United Kingdom
Posts: 4
Posted: 02:38pm 13 Mar 2019
Copy link to clipboard 
Print this post

Hi
I am using a Maximite to communicate with a SPI EEPROM 25LC512. To write a byte of data requires 4 bytes:- the cmd byte, address high, low and then the data byte.
To read data requires three bytes: the cmd byte, address high, low. The data at the address is then clocked back but I don’t know how to get a hold of this data.
My code is:

PIN(17)=1 'preset pin17 before it is setup
Setpin 17, DOUT
SPI OPEN 4000000,0,8 '4MHz, Mode 0,8 bits
PIN(17)=0 'chip select low
SPI WRITE 4,2,0,5,8 'write 4 bytes, '2'is write instruction,
' 0005' is the memory location, 8 is data
PIN(17)=1 'CS high
'try to read back
Pause(100)
PIN(17)=0 'CS low
SPI Write 3,3,0,5 'Send the read command to the EEPROM
' Read 3 bytes,the next'3' is read cmd, 0005 is memory location
byte1=SPI(0) 'Trying to get byte from memory
PIN(17)=1
SPI CLOSE

?byte1


Any suggestions to sort the code would be welcomed.
Thanks
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2959
Posted: 06:18pm 13 Mar 2019
Copy link to clipboard 
Print this post

Replace:

byte1=SPI(0)

with:

SPI READ 1,byte1 'read one byte into variable: byte1

Let us know if this works for you!!


EDIT 1:

If the above works, then move on to:

SPI READ n,ww() 'read n bytes into array ww (rename as appropriate!!)


EDIT 2:

Refer to Page 93 (bottom) and Page 94 in User Manual - explained in a little more detail there.

Hope this helps.Edited by WhiteWizzard 2019-03-15
 
Dedericus
Newbie

Joined: 19/01/2018
Location: United Kingdom
Posts: 4
Posted: 08:21pm 13 Mar 2019
Copy link to clipboard 
Print this post

Hi

Thanks for the reply.
I tried your suggestion of SPI READ 1,byte1 but the response when run was 'cannot find byte1'.
I am reasonably confident that my hardware is ok butI'll keep looking.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2959
Posted: 08:27pm 13 Mar 2019
Copy link to clipboard 
Print this post

Dim ww() ‘’add to start of code

Then change your spi write to:
ww()= SPI WRITE 3,3,.......

Then add:
Print ww(0)
Print ww(1)
Print ww(2)

Etc
 
Dedericus
Newbie

Joined: 19/01/2018
Location: United Kingdom
Posts: 4
Posted: 04:54pm 14 Mar 2019
Copy link to clipboard 
Print this post

Thanks for the suggestions.
I tried what you suggested but no success. I then modified my code to be similar to that on page 95 of the manual - still no success.:
OPTION Base 1

DIM ww%(4)
PIN(17)=1 'preset pin17 before it is setup
Setpin 17, DOUT
SPI OPEN 500000,0,8 '500 kHz, Mode 0,8 bits
PIN(17)=0 'chip select low
SPI WRITE 7,2,0,5,8,7,6,5 'write 4 bytes, '2'is write instruction,
' 0005' is the memory location, 8,7,6,5 is data
PIN(17)=1 'CS high
'try to read back
Pause(100)
PIN(17)=0 'CS low
SPI Write 3,3,0,5 'Send the read command to the EEPROM
' Read 3 bytes,the next'3' is read cmd, 0005 is memory location
SPI READ 4,ww%() 'read 4 bytes starting at 0005.
PIN(17)=1
SPI CLOSE

Print ww%(1)
Print ww%(2)
Print ww%(3)
Print ww%(4)


The program when run gives 255 for each location. This suggests the EEPROM is not being written to.
I checked with my scope that there were clk pulses from the uP - that was ok but I did not see any pulses on the SPI data in pin.
I am stepping back from this for a couple of days and come back to it with a clear head.
Thanks for your suggestions.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2959
Posted: 05:05pm 14 Mar 2019
Copy link to clipboard 
Print this post

Hi Derek,

If I get time later tonight I will run your code and drop on a Logic Analyser to monitor the SPI out.

Will also check the data sheet for the 25LC512.

I have gotten this family of SPI memory to work before so hopefully not too much effort . . .

Should have something for you in a couple of days if nobody else chimes in.

WW
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025