Jump to content

marek.svancar

Member
  • Posts

    1
  • Joined

  • Last visited

Awards

This user doesn't have any awards

marek.svancar's Achievements

  1. I need to create peer to peer communication between two terminals using SPI. I managed to get data from terminal connected to master into slave's terminal but I have no idea how to send data from slave to master. I am complete noob so the code is really f**ked up especially after trying to get communication from slave to master working an there are probably some stupid mistakes. Master void main() { char send; char receive; DDRB |= 1<<0; PORTB &= ~(1<<0); SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV4, _SPI_CLK_LO_LEADING); UART1_Init(9600); SPCR |=(1<<SPE) | (1<<SPR1) ; SPCR &=~(1<< DORD)& ~(1<<SPIE); SPCR &= ~(1<<CPOL) & ~(1<<CPHA); while(1) { if (UART1_Data_Ready() == 1) { receive = UART1_Read(); } SPDR = receive; while(!(SPSR & (1<<SPIF) )); UART1_Write(SPDR); delay_ms(1000); } } Slave char receive; void main() { char q; SPI1_Init_Advanced(_SPI_SLAVE, _SPI_FCY_DIV4, _SPI_CLK_LO_LEADING); UART1_Init(9600); SPCR |=(1<<SPE); SPCR &=~(1<< DORD)& ~(1<<SPIE); SPCR &= ~(1<<CPOL) & ~(1<<CPHA); while(1) { if (UART1_Data_Ready() == 1) { receive = UART1_Read(); } UART1_Write(SPDR); SPDR = receive; while(!(SPSR & (1<<SPIF) )); } }
×