![]() |
Forum Index : Microcontroller and PC projects : SPI help
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I'm planning on using a 47L04 SRAM device I need to store TIME$ every second and then read TIME$ as well and nothing else I've been reading the manual about SPI use and I believe once I have opened the SPO port I can simply SPI WRITE nbr,array() which would be SPI WRITE ?, TIME$ What would I use as the nbr in this case? I have never used an SPI device before and I can't get my head round "nbr is the number of data items to be sent" Do I need to define the addresses of the device? I'm only using this one SPI device |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
No: the SPI bus can be shared but this is done by each device having a chip-select pin. To address a specific device you typically pull that device's CS pin low. LEN(TIME$) |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
does it help that this is a i2c device not SPI? Am I missing something? |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
I think not, but an interesting component anyway. Unfortunately, no big capacity. Kind regards Michael causality ≠ correlation ≠ coincidence |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Indeed, capacity on these devices and the UNIO beasties is low. I have been using the winbond W25Qxx chips a bit this year - since PeteM did his CFunctions to make using them a breeze. My latest controller board has the solderpads as an option even. They are a viable alternative to SDCards without the hardware considerations. You can get huge capacities but I have sort of standardized (because they are the ones I got and I need nothing else ![]() |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Datasheet has "More than one million store cycles to EEPROM" At one per second, that's 2 weeks. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's an SRAM device it only stores in Eeprom if the power to the device is lost, which is exactly what I want it for, only to store the current time once a second Then if the power is lost, I know exactly the time the power was lost at because the device stores it in Eeprom at that stage The SRAM can be used as often as needed It is however as pointed out an I2C device not SPI so i'll have to try and figure out what address to write the TIME$ to |
||||
Quazee137![]() Guru ![]() Joined: 07/08/2016 Location: United StatesPosts: 593 |
Here is a program I'm using to play with the I2C fram chips should work for sram. its still raw no real parsing for input errors Print "09-08-2018 fram menu" Do Print "Select operation" Print "1. I2CScanner must be done 1st" Print "2. Framsize" Print "3. Erase Fram" Print "4. Write to Fram" Print "5. Dump Fram" Print "6. Exit" Print:Print ">>"; k$="" Do While k$="" k$=Inkey$ Loop Select Case k$ Case "1" I2CScanner Case "2" FramSize Case "3" FramErase Case "4" FramWrite Case "5" FramDump Case "6" End End Select Loop '==================== Sub I2CScanner Local found, i,h$, temp found=0 Print "I2C-Scanner from Adr. 8-119":Print For i = &h08 To &h77 ' gueltige I2C-Adressen von 8-119 I2C open 100, 1000 ' i2c enable 100kHz, 1000ms timeout I2C read i, 0, 1, temp If MM.I2C = 0 Then Print "Found I2C-Address at "; i; " (&H";Hex$(i);")" found=1 EndIf I2C close ' i2c disable Next i If found = 0 Then Print "NO I2C-Address found!" If found = 1 Then Input "Fram I2C address &H",h$ fa=Val("&H"+h$) EndIf End Sub Sub FramDump Local a,b,c,d,da$ Print "Dumping Fram. ESC to exit " a=getadr() I2C open 100,100 DA$=Chr$(A\256) + Chr$(A Mod 256) I2C write fa,0,2,da$ 'opt 0, lenght 2, memadr as a string Do Print " [======+==================================================+==================]" For d=1 To 16 d1$="" Print " | ";Hex$(a,4);" | "; For c=1 To 16 I2C read fa,1,1,B 'opt 1, lenght 1, b gets data A=A+1 If a=framsz Then a=0 Print Hex$(b,2);" "; b=b And &H7F ' mask out upper bit If b=>&h21 And b<=&H7E Then d1$=d1$+Chr$(b) Else d1$=d1$+"." End If Next c Print " | ";d1$;" |" Next d If esckey() Then Exit Do Loop End Sub Function esckey() Local k$ k$="" Do While k$="" k$=Inkey$ esckey=0 If k$=Chr$(&H1B) Then esckey=1 Loop End Function Function getadr() Local i$,a Input "Fram address =&H", i$ a=Val("&H"+i$) If (a<0 Or a >framsz) Then a=0 a=a And &HFFF0 getadr=a End Function Sub FramErase 'erasing in 16 byte blocks Local x Print "Erasing ";framsz;" bytes, press ESC to abort" If esckey() Then Exit Sub Print "Erasing ."; I2C open 100,100 For X=0 To framsz-1 Step 16 I2C write fa,0,18,X\256, X Mod 256,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ' If Not (x Mod 256) Then Print "."; Next I2C Close End Sub Sub FramWrite Local d$,da$,db$ Print "Writing to Fram " a=getadr() Print Hex$(a,4);" "; Input "-> ",v$ DA$=Chr$(A\256) + Chr$(A Mod 256) D$=DA$ + v$ I2C open 100,100 I2C write fa,0,Len(D$),D$ I2C Close A=A+Len(D$)-2 If a=framsz Then a=0 End Sub Sub FramSize Local x,d$,r$,s$ Print: Print "FramSize": Print "Sizing" I2C open 100,100 D$=Chr$(0) + Chr$(0) I2C write fa,0,Len(D$),D$ I2C read fa,0,4,s$ D$=Chr$(0) + Chr$(0) + "Here" I2C write fa,0,Len(D$),D$ D$=Chr$(0) + Chr$(4) I2C write fa,0,2,D$ Do I2C read fa,1,4,r$ 'opt 1, lenght 4 If x Mod 512=0 Then Print "."; x=x+4 If r$="Here" Then Exit Do Loop Print: Print "Fram Size ";x;", &H";Hex$(x,4);" bytes" framsz=x D$=Chr$(0) + Chr$(0) + s$ I2C open 100,100 I2C write fa,0,Len(D$),D$ I2C Close End Sub |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |