I'm trying to use an Arduino to eavesdrop SD card writes from a heater system controller (AVR based). I've soldered wires on the SD card holder and converted the signal from 3v3 to 5v0.
The clock (red) and data (blue) looks like this:
The problem is that I get more or less only garbage on the Arduino. When this line is written to the SD Card:
2011-08-27,16:17:01,0x2,0x0,0,0,0x0,1,0,1023,-74,26.0,21.5,26.1,0,0.0,0.0,0.0,0x5,7,0,0,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
The Arduino outputs this:
Q
ÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
ÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ0,1ÿÿÿÿÿÿÿ
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
I've tried to change clock phase, clock polarity and bit order without any progress. Arduino source code:
// Sample SPI slave that echos to Serial on EOL
#include "pins_arduino.h"
char buf [150];
volatile byte pos;
volatile boolean process_it;
void setup (void)
{
Serial.begin (9600); // debugging
// setup pins
pinMode(MISO, OUTPUT);
pinMode(MOSI, INPUT);
pinMode(SS, INPUT);
pinMode(SCK, INPUT);
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// get ready for an interrupt
pos = 0; // buffer empty
process_it = false;
// now turn on interrupts
SPCR |= _BV(SPIE);
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR; // grab byte from SPI Data Register
// add to buffer if room
if (pos < sizeof(buf))
{
buf [pos++] = c;
// example: newline means time to process buffer
if (c == 0x0a || pos >= 149)
process_it = true;
} else {
// reset buffer
pos = 0;
} // end of room available
} // end of interrupt routine SPI_STC_vect
// main loop - wait for flag set in interrupt routine
unsigned long oldmillis = millis();
void loop (void)
{
if (process_it)
{
// terminate string
buf [pos] = 0;
Serial.println (buf);
pos = 0;
process_it = false;
} // end of flag set
// print status every 5 secs
if(millis() > (oldmillis + 5000))
{
Serial.print("SPCR=" );
Serial.println(SPCR, BIN);
Serial.print("SPDR=" );
Serial.print(SPDR, BIN);
Serial.print(SPDR, HEX);
Serial.println(byte(SPDR));
Serial.print("SPSR=" );
Serial.println(SPSR, BIN);
oldmillis = millis();
}
} // end of loop
Any ideas on why the SPI / SD Card traffic isn't captured properly?
Regards,
Torgil