-
-
Save ft232r/465a5cfe157b7a2556868e852bb83aa2 to your computer and use it in GitHub Desktop.
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
#include <avr/io.h> | |
#include <util/delay.h> | |
int main() { | |
uint8_t index; | |
DDRB=(1<<PB5)|(1<<PB3); | |
/* Enable SPI, Master, set clock rate fck/128 */ | |
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); | |
_delay_ms(2000); | |
index = 0; | |
while (1) { | |
SPDR = index; | |
while(!(SPSR & (1<<SPIF))); | |
index = (index + 1) % 10; | |
_delay_ms(5000); | |
} | |
} |
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
#include <avr/io.h> | |
#include <util/delay.h> | |
#include "uart.h" | |
#include "printk.h" | |
int main() { | |
uart_init(); | |
DDRB = (1<<PD6); //MISO as OUTPUT | |
SPCR = (1<<SPE); //Enable SPI | |
printk("Start slave program\r\n"); | |
uint8_t data = 0; | |
while (1) { | |
SPDR = 0xff; | |
while(!(SPSR & (1<<SPIF))); | |
data = SPDR; | |
printk("data %d\r\n", data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment