0

I'm simulating my code on Proteus and trying to send data between two ATmega32 devices via SPI as master and slave. However I keep getting the warning "SPDR Write Collision. Written data is ignored" for the slave device for each character of the string I'm trying to send.

#define F_CPU 8000000UL

#include <avr/io.h>

void PORT_INIT(void);
void SPI_SLAVE_INIT(void);
void SPI_SEND_STRING(void);

char *transmit = "Hello there!";        ///< Data to be sent.

int main(void){
    DDRA = 0xFF;
    
    PORT_INIT();
    SPI_SLAVE_INIT();
    
    SPI_SEND_STRING();
}

/*!
 *  @brief Initialize ports.
 */

void PORT_INIT(void){
    DDRB &= ~((1<<PB4)|(1<<PB5)|(1<<PB7));          ///< Set MOSI, SCK and SS pins to input.
    DDRB |= (1<<PB6);                               ///< Set MISO pin to output.
}

/*!
 *  @brief Initialize SPI in slave mode.
 */

void SPI_SLAVE_INIT(void){
    SPCR = (1<<SPE);            ///< Enable SPI in Slave SPI mode.
}

/*!
 *  @brief Transmit a message over SPI.
 */

void SPI_SEND_STRING(void){
    for(uint8_t i=0;transmit[i]!=0;i++){
        SPDR = transmit[i];         ///< Load the data byte to the SPDR shift register to transmit.
        while(!(SPSR & (1<<SPIF)));     ///< Wait until the full data byte is received.
        PORTA = SPDR;
    }
}

Am I missing something here? The master device clock frequency is Fosc/16.

4

0 回答 0