Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- volatile data;
- int main (void)
- {
- DDRD |= (1<<PD0);
- PORTD |= 0x00;
- DDRB &= ~((1<<2)|(1<<3)|(1<<5)); // SCK, MOSI and SS as inputs
- DDRB |= (1<<4); // MISO as output
- SPCR &= ~(1<<MSTR); // Set as slave
- SPCR |= (1<<SPR0)|(1<<SPR1); // divide clock by 128
- SPCR |= (1<<SPIE); // Enable SPI Interrupt
- SPCR |= (1<<SPE); // Enable SPI
- sei();
- while(1)
- {
- }
- }
- ISR (SPI_STC_vect)
- {
- data = SPDR;
- PORTD ^= (1<<PD0);
- }
- #include <avr/io.h>
- #include <avr/interrupt.h>
- volatile data;
- int main (void)
- {
- char blah;
- DDRB |= (1<<2)|(1<<3)|(1<<5); // SCK, MOSI and SS as outputs
- DDRB &= ~(1<<4); // MISO as input
- SPCR |= (1<<MSTR); // Set as Master
- SPCR |= (1<<SPR0)|(1<<SPR1); // divided clock by 128
- SPCR |= (1<<SPIE); // Enable SPI Interrupt
- SPCR |= (1<<SPE); // Enable SPI
- sei();
- while(1)
- {
- if ((SPSR & (1<<SPIF)) > 0) // checks to see if the SPI bit is clear
- data=blah; // send the data
- }
- }
- ISR (SPI_STC_vect)
- {
- SPDR = data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement