How can I send the string from Slave SPI to Master SPI?
I want to write code in Bare Metal.
The problem which I am facing is I can't make out what will be my blocking function in Master SPI code when receiving data from slave SPI.
As my SPIF bit is cleared in MAster code as soon as I shift out SPDR register from master to receive byte which is coming from the slave.
#define spi_data_reg SPDR
//Naster read byte function
uint8_t MA_SPI0_read_byte()
{
spi_port &= ~(1<<SS);
spi_data_reg = 0;
while(!(SPSR & (1<<SPIF))); //Wait until transmission complete
return(spi_data_reg); //Return received data
spi_port |= (1<<SS);
}
//Slave send byte function
void SL_SPI0_send_byte(uint8_t data)
{
spi_data_direc=(1<<MISO); //MISO as OUTPUT
spi_data_reg = data;
while(!(SPSR &(1<<SPIF)));
}
spi_port |= (1<<SS);
after the return wil not work. You'll never reach the line. Why do you initializespi_data_reg = 0;
? Have you set the master to input likespi_data_direc=(1<<MISO);
elsewhere? I did not yet programmed SPI communications with the low level api, so I do not know if one of these could be the problem. But as no one else repsonded ... Just some ideas; better than nothing. – Peter Paul Kiefer Dec 2 '20 at 13:42