I try to communicate with an Arduino Pro Atmega 328, actually part of the Mongoose IMU. http://www.gammon.com.au/forum/?id=10892
. First I knew nothing about SPI and asked a question here http://arduino.cc/forum/index.php/topic,96326.0.html
and Nick Gammon provided me with extremely usefull information (http://www.gammon.com.au/forum/?id=10892
) but I'm ashamed to say I still can't get it to work.
I want mij microprocessor (NetMF framework) to be the master and communicate with the Arduino. If the microprosessor sends out one byte "start updating me" the Arduino should send back the actual values.
I've created this on the Arduino:
// have to send on master in, *slave out*
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
// SPI interrupt routine
byte c = SPDR;
if(c == 8)
SPDR = 16;
SPDR = 255;
} // end of interrupt service routine (ISR) SPI_STC_vect
And this on the NetMF:
SpiCom = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE,
false, 0,0, true, false, 4000, SPI.SPI_module.SPI1));
byte ReadBuffer = new byte;
// Create and fill write buffer
byte WriteBuffer = new byte;
WriteBuffer = 4;
while (1 == 1)
I would have expected 16 on the readbuffer if I would send 8 and 255 otherwise. But somehow It sends back 6 if I write 4 and 12 if I write 8. I can't figure out why. I don't use a slave select pin, there is only one slave. This is why I pass Cpu.Pin.GPIO_NONE as slave select pin on NetMf. ChipSelect active state = false, setuptime and hold time = 0, clock idle state = true, clock edge = false, ClockRate = 4000 Khz (I read somewhere that Arduino would be at 4Mhz?). SPI module = SPI1, whatever that might be. I also used about every possible other combination of the parameters on NetMF.
On Arduino I tried SPI.setDataMode(SPI_MODE1); and SPI.setBitOrder(MSBFIRST); as well, but no better results. I could also remove SPI.Begin(); and get the same results.
I did blink the status led within the ISR (SPI_STC_vect) routine and that seems to work. But the bytes don't match to what I would have expect. I thought SPDR would have been the byte incomming from the master and could be altered to represent the result from the slave.
I can't find anything on google about connecting NetMf to Arduino over SPI.
Thanks for taking the time to read this. Any information about what I'm doing wrong is very much appreciated. I don't have any Arduino skills.