Go Down

Topic: SD Card SPI with two masters (Read 1 time) previous topic - next topic

torgil

Hi!

I've been trying to eavesdrop a SD card write from an AVR based heater controller. This was unfortunately a dead end since the SPI clock speed is at 4 MHz which seems to be to high for the Arduino when acting as a SPI slave. Now I'd like feedback on another aproach:

The boiler controller writes one line of text to a file on the SD card every five seconds(about 150 chars). In between the writes the CS is high and the SD card is not used. My idea is to hijack the lines from the SD card holder and read the last line written to the SD card using the Arduino as master, since the SPI bus is uni-directional I'm thinking this could be done like this:

SD_MOSI = CONTROLLER_MOSI & ~CONTROLLER_SS + ARDUINO_MOSI & CONTROLLER_SS

SD_CLK = CONTROLLER_CLK & ~CONTROLLER_SS + ARDUINO_CLK & CONTROLLER_SS

SD_SS = CONTROLLER_SS & ARDUINO_SS

ARDUINO_MISO = SD_MISO & CONTROLLER_SS

CONTROLLER_MISO = SD_MISO & ~CONTROLLER_SS

Which requires 2OR gates, 8AND gates and one inverter. The software for this could be:

1. Detect low to high transition on CONTROLLER_SS (which means that the controller has finished writting the card).
2. Init SD, look for most recently changed file, read last line of file, release SD.

Is this a good aproach or could this be done in a more simple way? Will I be able to finish reading the SD card in 5 secs? Are there any timing issues/delays on SD card init or relase? Does it take long time to find the most recently changed file in the root folder of a SD Card with about 50 files?

Could this be constructed with less components than one 74HC04, two 74HC08 and one 74HC32?

Regards,
Torgil

robtillaart

No advice but it sounds like an interesting experiment.

Did you have a chance to have a logic analyzer connected to the SPI bus allready?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

torgil

Some more info.

Image of the controller card:



The wires are soldered onto the SD Card holder:



Oscilloscope screen of the CS line, different time scale:







The whole write cycle is about 120 ms and is repeated every 5 seconds. CS line is dropped high/low several times during one write. A better way not to interfere with the write operation would be to look for low to high transition on CS line and then wait for say 250 ms before reading the card.

Oscilloscope screen of the SCK line, different time scale:







Clock frequency is 4 MHz and, one byte takes 2 us and the delay between bytes is 4 us. 

Ideas are welcome!

DirtyBits


Hi!
This was unfortunately a dead end since the SPI clock speed is at 4 MHz which seems to be to high for the Arduino when acting as a SPI slave.


If you can make your own software serial than you can get clock speed of up to 8MHz with Arduino (ATmega328)!
Use port manipulation and you can toggle output at higher speed!!
Code: [Select]

void setup()
{   
   DDRB = DDRB | B00111111; // sets Arduino pins 8 to 13 as outputs, pins GND & AREF are unchanged
   DDRD = DDRD | B11111100; // sets Arduino pins 2 to 7 as outputs, pins 0 & 1 are unchanged
}


Good luck  :smiley-mr-green:

graynomad

Quote
This was unfortunately a dead end since the SPI clock speed is at 4 MHz which seems to be to high for the Arduino when acting as a SPI slave.

Did you see the last few entries in the other thread. We got 4MHz slave working.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

MarkT

The datasheet says that in SPI slave mode the SCK high and low pulses must each be "more than 2 cpu clocks".  This implies less than 4MHz for a 16MHz crystal (and a 50% duty cycle).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up