Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:32 11 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 : auxiliary SD card drive

Author Message
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 08:36am 15 May 2018
Copy link to clipboard 
Print this post

As part of incorporating file I/O and more datatypes into my interpreter program I have been able to set up a SD card as an auxiliary drive.
It uses a small uno for the drivers/housekeeping, and is driven with single 16-bit spi words to open, read, write, and close bytes and csv file as necessary. This means any four micro pins that can bit-bang some spi can be used to connect it.

eg to write a line of some test variables into a csv file:

PROGRAM testwrite
C
CHARACTER*20 s
INTEGER*1 a
INTEGER*4 b, n
REAL c
DOUBLE d
UNSIGNED*1 e
a = 123
b = 1222333444
c = 1.123456
d = 1.12345678
e = 234
s = 'squarkoid'
OPEN WRITE
CALL longd()
WRITE (1,*) a, b, c, d, e, s
CLOSE
END
...


and then read it



PROGRAM testread
C
CHARACTER*20 s
INTEGER*1 a
INTEGER*4 b, n
REAL c
DOUBLE d
UNSIGNED*1 e
OPEN
CALL longd()
READ (1,*) a, b, c, d, e, s
PRINT a," ",b," ",c," ",d," ",e," ",s
CLOSE
END
...



displays the line


123 1222333444 1.123456 1.12345678 234 squarkoid



A main advantage is that using a uno means the SD drivers are separately maintainable .
Any errors are reported back via the word exchange. On power-up a check is done for directory access etc. I found a small delay was needed between opening a file and accessing it.
So far I have run files of 185k without problems, it should be good for 4Gb. It might be useful for other systems, if there is further interest.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 10:05am 15 May 2018
Copy link to clipboard 
Print this post



Thanks.
As I understand it this is an SPI based SD raw drive?
And will/is there file handling?

Using this will use less of the 170's flash to store
setup or log files on SD. I have been looking into I2C/SPI
fram / flash for this but your way allows so much more storage
and is removable. Looking forward for more.

Quazee

any thoughts on I2C as thats what I playing with now.
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 01:10pm 15 May 2018
Copy link to clipboard 
Print this post

The data is saved as strings of bytes, the files are csv files and can be seen/used as text or excel etc. [I did have an early version that could save values as native binary eg 4 bytes for a 32bit value but it is not developed.]
So far it uses two preset filenames, one for reading, another for writing; writing will create a new file if it is not already present, or append data to a file already present.
It is fairly slow - there is a preset delay in the uno which I have not changed - but it chugs away logging gps values well enough.

ed - re I2C - I have tried to stay clear of it, there seemed to be problems in the early versions but it looks popular now. I have stuck with spi as it offers higher speed maximums, it too has had its gotchas though.Edited by chronic 2018-05-17
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 03:41am 27 May 2018
Copy link to clipboard 
Print this post

This is the semi-prototype, using a "pro mini" (approx 4$), and
a sd micro socket.








The four connections at at the left are used like miso, mosi, clk, ss.
(I am using pic port B0, B1, B2, B3 just as ordinary port B i/o,
it is arbitrary)
There are 5v-3.3v dropping resistor dividers, and the leads are
3.3v and ground. (ed - also two more for 5v/0 for the mini)

To use it with other systems, some routines are needed eg
OPEN, READ, WRITE, CLOSE
which just send constructed 16 bit words exchanged as per spi.

It will be more useful with filename selection, which is in
final progress, hopefully something like

OPEN 'filename.csv'
OPEN 'filename.csv' WRITE

etc.


ed - PS I used one of Mik's protoboards - excellent thanks Mik
Edited by chronic 2018-05-28
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 01:17pm 15 Jun 2018
Copy link to clipboard 
Print this post

OK the arbitrary filename version is working.

eg to write a file called "cruddtxt.csv"


...
a = 122
b = 1222333444
c = 1.123456
d = 1.12345678
e = 234
OPEN 'cruddtxt.csv'
WRITE (1,*) a, b, c, d, e
CLOSE
...


and read it and print

...
OPEN 'cruddtxt.csv' READONLY
READ (1,*) a, b, c, d, e
CLOSE
PRINT a," ",b," ",c," ",d," ",e
...


122 1222333444 1.123456 1.12345678 234


It is working so far (small files), I will test it further and write it up a bit.
 
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