Created
May 16, 2019 11:18
-
-
Save avr-programmierung/63c9c6f1f26a746b2d50c2236aabdd56 to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz SPI-Slave - Daten am MOSI empfangen und am PORTD ausgeben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* * spi_receive_01.c | |
* SPI-Slave - Daten am MOSI empfangen und am PORTD ausgeben | |
* Controller: ATmega88 @ 8MHz | |
*/ | |
#include <avr/io.h> | |
#include <util/delay.h> | |
void SPI_Slave_Init(void) | |
{ | |
SPCR &= ~(1<<MSTR); // Controller = Slave | |
SPCR &= ~(1<<CPOL); // CLK positiv phase | |
SPCR |= (1<<CPHA); // Sampling data @ rising edge | |
DDRB |= (1<<PB4); // Set MISO output | |
DDRB &= ~(1<<PB3); // Set MOSI input | |
DDRB &= ~(1<<PB5); // Set SCK input | |
DDRB &= ~(1<<PB2); // Set SS input | |
SPCR |= (1<<SPE); // SPI enable | |
} | |
uint8_t SPI_Slave_Receive(void) | |
{ | |
while (!(SPSR & (1<<SPIF))); // Wait for transmission complete | |
return SPDR; // return spi data register | |
} | |
int main(void) | |
{ | |
DDRD = 0xFF; | |
SPI_Slave_Init(); // Init SPI Interface as Slave | |
while(1) | |
{ | |
PORTD = SPI_Slave_Receive(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment