I have two of the following boards:
http://www.olimex.com/dev/index.html
I am trying to see if I can get the SPI’s to communicate with each other by setting one board as a master and the other as a slave.
Here is the code I am using for the functions to initialize and control the SPI:
Master:
/********************** SPI Initialization*********************/
//Sets the SPI on the microcontroller to be the master
void SPI_MasterInit(void)
{
// set PB1(/SS), PB3(MOSI), PB2(SCK) as output
DDRB = DDRB | 0b00000111;
// enable SPI Interrupt and SPI in Master Mode with SCK = CK/16
SPCR = SPCR | 0b11010001;
}
void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}
Slave:
void SPI_SlaveInit(void)
{
/* Set MISO output, all others input */
DDRB = DDRB | 0b00001000;
/* Enable SPI */
SPCR = SPCR | 0b01000000;
}
char SPI_SlaveReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)))
;
/* Return data register */
return SPDR;
}
I call the initialization functions on each board respectively and on the transmitter I send a defined single char through the SPI_MasterTransmit();. On the slave side I set the SPI_SlaveRecieve(); to a deined char as well and send that recieved char to the LCD.
The LCD is working fine since I have tested it using other display code. Can anyone tell me if my code looks sound?
Also note, on my boards I connected the MISO’s, MOSI, SCK and SS to each other on the boards (this could also be an issue). Any help would be greatly appreciated. If you need more information let me know.
Thanks in advance.