I have a real simple SPI function that reads by sending a dummy byte. I also have the uart up and running for debug work. This function comes from the Fatfs demo for anyone who wonders.
Anyway, the init function calls rcvr_spi 10 times to wake up the card or something, but it always hangs. I added the uart output to see what was happening and the best case so far is 5 transmissions with an average of 2-3 before freezing.
Why would the SPIF bit fail to set? I have no SPI interrupts enabled (I'm in master mode).
#define DD_MOSI 2 #define DD_SCK 1 #define DDR_SPI DDRB #define DD_SS 4 .....SPI init code DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)| (1<<DD_SS); SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); /* Initialize SPI port (Mode 0) */ ..... //SPI receive via dummy send static BYTE rcvr_spi (void) { SPDR = 0xFF; xputs(PSTR("SPI get\n")); loop_until_bit_is_set(SPSR, SPIF); return SPDR; }
EDIT: also tried to go with a while loop in place of the loop_until_bit_is_set() macro thingy, no dice.