Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:02 01 Aug 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 : Cash Gift for sample EEPROM SPI / I2C Micromite code

Author Message
pdeivendran

Newbie

Joined: 18/09/2020
Location: Malaysia
Posts: 9
Posted: 09:09am 02 Jun 2021
Copy link to clipboard 
Print this post

Dear Guys,

I am at my wits-end, trying to solve the above EEPROM communication using the Micromite.

I have tried almost everything I could to solve it but only ending in frustration. Maybe there is something I am NOT doing right.

The chips in question are the 25AA02UID (SPI) and the AT24CS01 (I2C) from Microchip.

What I am attempting is to:

1. Read the chip UID Serial Number

2. Write data to the unprotected memory array

3. Read data from memory array

Having said the above, as my last attempt before dumping this entire effort,  if I am not being too rude or insulting,  I would like to offer you a USD 150 cash gift for your troubles, for a set of proven sample codes for both the above chipsets.

If you are agreeable to this and have a PayPal account, I will transfer this amount to you before your posting.

My email id. is pdeivendran@me.com

Thanking you in advance

Dave
 
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 159
Posted: 02:35pm 02 Jun 2021
Copy link to clipboard 
Print this post

Don't have any of those chips but if you are having problems with both SPI and I2C chips then it is likely not an interface related issue.
Which micromite you are using/firmware version?
What are you trying and what is not working?
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 04:33pm 02 Jun 2021
Copy link to clipboard 
Print this post

this might give you some pointers

http://www.thebackshed.com/Forum/ViewTopic.php?TID=6917
Edited 2021-06-03 02:36 by CaptainBoing
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 08:17pm 02 Jun 2021
Copy link to clipboard 
Print this post

My stuff pile includes a 25AA512 I/P SPI EEPROM.
(I also have a single FT24C256A, although I haven't tried anything with it.)

The following quick test program seems to work with my SPI EEPROM.

Note that addressing and instruction set are a little bit different between the SPI EEPROM I have and the one you indicated. Mine has 16 bit addresses, and some flash erase instructions. However, the demo program should kind of still work if you change 2 places to only write the (low) address byte. I say 'kind of' because you have to obey page rules when writing - max 16 bytes at a time, within a single page.

From the data sheet:
  Quote   The only restriction is that all of the bytes must reside in the same page. Additionally, a page address begins with XXXX 0000 and ends with XXXX 1111.


Also, my chip has a 'Read Electronic Signature' command whereas yours has a unique serial number stored at address &hFC to &hFF.

Hopefully this helps a bit.

Print "EEPROM Test"
Print

Const SPI_CS = 2

Pin(SPI_CS) = 1   'deselect SPI EEPROM
SetPin SPI_CS, dout

SPI open 100000,0,8

Print "Read electronic signature:";
Pin(SPI_CS) = 0
dummy = SPI(&b10101011)
dummy = SPI(0)
dummy = SPI(0)
result = SPI(0)
Pin(SPI_CS) = 1
Print result
Print

Print "EEPROM Satus:";SPI_EE_Read_Status()

Print "old EEPROM contents:"
Print SPI_EE_Read_String(0,45)  ' read 45 bytes starting from address 0

' write some stuff to EEPROM
SPI_EE_Write_String 10, "This is a test!"
SPI_EE_Write_String 30, Time$ + "     "   ' spaces to blank out previous data
SPI_EE_Write_String 40, Date$

Print "new EEPROM contents:"
Print SPI_EE_Read_String(0,45)  ' read 45 bytes starting from address 0

SPI close

End

Sub SPI_EE_Enable_Write
 Pin(SPI_CS) = 0
 dummy = SPI(&b00000110)   ' enable writes
 Pin(SPI_CS) = 1
End Sub

Sub SPI_EE_Disable_Write
 Pin(SPI_CS) = 0
 dummy = SPI(&b00000100)   ' disable writes
 Pin(SPI_CS) = 1
End Sub

' Write a string to EEPROM
' WARNING - dumb code doesn't know about page boundaries!
Sub SPI_EE_Write_String addr,d$
 Local integer dummy

 If Len(d$) > 0 Then
   SPI_EE_Enable_Write

   Pin(SPI_CS) = 0
   dummy = SPI(&b00000010)     ' write instruction
   dummy = SPI(addr \ 256)     ' high byte of address
   dummy = SPI(addr Mod 256)   ' low byte of address
   SPI write Len(d$), d$
   Pause 1
   Pin(SPI_CS) = 1
   Pause 500   ' wait for write to finish - should check STATUS instead
   SPI_EE_Disable_Write
 EndIf

End Sub

' Read n bytes from EEPROM, return as a string
Function SPI_EE_Read_String(addr,n) As string
 Local integer i,dummy,v
 Local d$ = ""

 Pin(SPI_CS) = 0
 dummy = SPI(&b00000011)     ' read instruction
 dummy = SPI(addr \ 256)     ' high byte of address
 dummy = SPI(addr Mod 256)   ' low byte of address

 For i = 1 To n              ' loop through and read each byte
   v = SPI(0)                ' dummy output to get input
   If v <  32 Then v = 32     ' WARNING - turn unprintable into space
   If v > 127 Then v = 32     ' WARNING - turn unprintable into space
   d$ = d$ + Chr$(v)
 Next i

 SPI_EE_Read_String = d$
 Pin(SPI_CS) = 1

End Function

' read the status register
Function SPI_EE_Read_Status()
 Pin(SPI_CS) = 0
 dummy = SPI(&b00000101)
 Read_SPI_EE_Status = SPI(0)
 Pin(SPI_CS) = 1
End Function

Visit Vegipete's *Mite Library for cool programs.
 
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