I'm using an Atmega644a that communicates with an Arduino Uno (Atmega328p) over SPI for logging purposes. The Arduino is the SPI slave. It works fine unless I reset or flash the Atmega644a; after this I always have to reset the Arduino for the SPI logging to keep working. I don't have this problem when I reset the Atmega with a watchdog timer, after this the SPI logging still works. Any thoughts on how to fix this?
My SPI code on the master is as follows:
#define SCK PINB7 #define MOSI PINB5 #define SS PINB4 void spi_master_init() { DDRB |= (1 << SS) | (1 << MOSI) | (1 << SCK); SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0); } uint8_t spi_print_char(char data) { /*transmit the byte to be sent */ SPDR = data; /* wait for the transfer to complete */ while (!(SPSR & (1<<SPIF))); /* return byte read from buffer */ return SPDR; } void spi_print_string(char *s) { while(*s) spi_print_char(*s++); spi_print_char('\r'); spi_print_char('\n'); }
The code for the Arduino Slave is taken from here: https://gist.github.com/chrismey.... It uses SPI interrupts to fill a buffer, and when it receives the "\n" character it prints it to the serial output.