I have an Arduino Mega and a wifly shield. The wifly shield has a SPI->UART IC which is supposed to be the interface to the wifly. Right now I'm just trying to get the SPI IC configured correctly. I've copied the transparent terminal sketch from the "Talking wireless server tutorial". When I run it the code hangs.
I striped everything down to a bare sketch so you can clearly see the problem:
char clr = 0;
#define SS 10
#define MOSI 11
#define MISO 12
#define SCLK 13
char spi_transfer( volatile char data )
{
SPDR = data;
while( !( SPSR & (1<<SPIF) ) );
Serial.println( "Completed" );
return SPDR;
}
void setup()
{
pinMode( MISO, INPUT );
pinMode( MOSI, OUTPUT );
pinMode( SS, OUTPUT );
pinMode( SCLK, OUTPUT );
digitalWrite( SS, HIGH );
SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0);
clr = SPSR;
clr = SPDR;
delay( 10 );
Serial.begin( 9600 );
Serial.println( "Initializing SPI..." );
digitalWrite( SS, LOW );
spi_transfer( 0x00 ); // Dummy data
spi_transfer( 0x00 ); // Dummy data
digitalWrite( SS, HIGH );
}
void loop()
{
}
When I run this I only see one "Completed" and the code hangs when trying to send the second byte. The second "Completed" never comes.
Here's a copy from the terminal:
Initializing SPI...
Completed
Is there a problem with my code? Do I have a bad Arduino or peripheral?
Can someone else run this simple code and see if they get the same results?