Go Down

Topic: a newbie Q: can I use sd card pins for something else between writes? (Read 1 time) previous topic - next topic

Hi,

I'm working on a datalogging project using a Seeeduino Stalker (basically a clone with a microSD on-board, using the SPI interface over pins 10-13).  I've got this working fine with the fat16 library from http://code.google.com/p/fat16lib/.  My project involves reading various analog inputs via a couple of multiplexers, displaying the values on an lcd screen and logging to the SD card.

My question is this:  Is it possible to use pins 11-13 for something else (for example setting the mux pins) at the times when the SD card is not being written to?  I'd basically like to free up a few pins for something else.  At present it seems that pins 11 and 12 are active all the time, no matter whether or not the card is actually being written to at the time.  What I'd like to achieve is something like:

Quote
setup:
initialise card

loop:
set mux pins using pins 11-13, and store readings
write readings to card


pin 10 appears to be the card's CS pin, so something like this seems logical, but various permutations I've tried haven't worked so far:

Quote
setup:
initialise card

loop:
set CS pin to not access card
set mux pins, and store readings
set CS pin to access card
write to card


Does this seem reasonable, or am I completely misunderstanding how the sd card access works?
I've tried to search for an answer to this, but haven't had any luck so far - any help much appreciated!  I'm new to this and picking it up as I go along.

Thanks very much,
Jo

CrossRoads

Yes, with SPI you will share the clock, MOSI, and MISO pins between devices, with the seperate Chip Select lines determining which devices do something with the data going out (MOSI) or if the devices will send something back (MISO).
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Thanks CrossRoads.  After a little more digging around, I think my problem boils down to finding a "SD card interface - STOP TALKING!" command - so time for some perusal of the fat16 documentation.  Will report back if/when I find what I want.

Cheers,
Jo

GaryP

Yes, thanks indeed!

This information is probably found somewhere, but asking it might help someone else as well:
-How many SPI devices can be loading the line at the same time?

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

CrossRoads

Do  you mean how many things can you connect to the clock, MOSI, and MISO lines at the same time?
That will depend on how far apart they are, what kind of current load they present to the atmega's output driver, etc.,how fast you are trying to communicate (the SPI mode can be varied for different speeds), and how connected (one long daisy chain?).

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

In my case I want to do something with the pins that doesn't use SPI (i.e. just bog-standard digitalWrites to control my mux inputs), in between the times when I access the SD card.  At the moment I can't seem to do anything at all with those pins - any digitalWrites are just ignored.

So how do I disable the SPI interface from using pins 11-13 when it's not actually accessing the card?

I've been wading through the playground, the forum, and the fat16 documentation, but to no avail.  Any ideas?

Thanks,
Jo

Solved!  I think...

Quote
#include <SPI.h>

...

void setup() {
  // do setup stuff here
  SPI.end();
}


void loop() {
  // do non-SPI stuff here - in my case set my mux bits
  SPI.begin();
  // do SPI stuff here - open file, write to file, close file, etc
  SPI.end();
}


Hope that helps anyone else in the same situation.
Cheers,
Jo

CrossRoads

"In my case I want to do something with the pins that doesn't use SPI (i.e. just bog-standard digitalWrites to control my mux inputs), in between the times when I access the SD card."
When you turn SPI back on, will you use the SPI chip select to let the mux know the signals are not to be used?
Perhaps run CS thru an inverter - when CS goes Low for SPI, the inverted CS will keep the mux deseleced, and when CS is High for SPI the inverted CS will be Low, enabling the mux.
Or, AND the inverted CS with your MUX enable signal.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nice idea - and I would use it except that I'm severely limited in the components I have or can get hold of (I'm working at a hospital in northern Pakistan just now - the system is for monitoring a solar water heater system I'm working on).

For this set up it doesn't matter, as the mux settings are only important at the times I take the readings - I'm not so worried about what they do in between.

Thanks very much for your input.
Jo

Go Up