Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:58 02 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 : SPI help

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:11pm 29 Dec 2018
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10315
Posted: 12:36pm 29 Dec 2018
Copy link to clipboard 
Print this post

  Quote  Do I need to define the addresses of the device?


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.

  Quote  What would I use as the nbr in this case?


LEN(TIME$)
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 03:55pm 29 Dec 2018
Copy link to clipboard 
Print this post

does it help that this is a i2c device not SPI?

Am I missing something?Edited by CaptainBoing 2018-12-31
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 04:06pm 29 Dec 2018
Copy link to clipboard 
Print this post

  CaptainBoing said   Am I missing something?


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 Kingdom
Posts: 2170
Posted: 10:08pm 29 Dec 2018
Copy link to clipboard 
Print this post

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 ) on the 4Mbyte and 8MByte ones... they are dead useful where you need logging and can't squeeze it into the 2K of a '170Edited by CaptainBoing 2018-12-31
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:36pm 29 Dec 2018
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1702
Posted: 11:36pm 29 Dec 2018
Copy link to clipboard 
Print this post

  TassyJim said   Datasheet has "More than one million store cycles to EEPROM"
At one per second, that's 2 weeks.

Jim

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 Edited by lew247 2018-12-31
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 11:14am 30 Dec 2018
Copy link to clipboard 
Print this post

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
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

Print

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
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
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
Edited by Quazee137 2018-12-31
 
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