Skip to content

Instantly share code, notes, and snippets.

@ft232r
Created July 22, 2016 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ft232r/465a5cfe157b7a2556868e852bb83aa2 to your computer and use it in GitHub Desktop.
Save ft232r/465a5cfe157b7a2556868e852bb83aa2 to your computer and use it in GitHub Desktop.
#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);
}
}
#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