Pages: [1]   Go Down
Author Topic: a newbie Q: can I use sd card pins for something else between writes?  (Read 1669 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?).

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: