SPI using AVR:
Program for SPI (MOSI):
Master:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0xAC;
SPCR=0x70;
while(1)
{
SPDR=0xf0;
while((SPSR&0x80)==0);
}
}
Slave:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRD=0xFF;
//DDRB=0X40;
SPCR=0x70;
while(1)
{
while((SPSR&0x80)==0);
PORTD=SPDR;
}
}
Simulation for MOSI:
Program for SPI (MISO):
Master:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
while(1)
{
DDRB=0x2C;
SPCR=0x70;
SPDR=0x55;
while((SPSR&0x80)==0);
DDRB=0x34;
DDRD=0xFF;
SPCR=0x50;
while((SPSR&0x80)==0);
PORTD=SPDR;
while(1);
}
}
Slave:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
while(1)
{
DDRD=0xFF;
SPCR=0x40;
while((SPSR&0x80)==0);
PORTD=SPDR;
DDRB=0x10;
SPCR=0x60;
SPDR=0x55;
while((SPSR&0x80)==0);
while(1);
}
}
Program for SPI (MOSI):
Master:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0xAC;
SPCR=0x70;
while(1)
{
SPDR=0xf0;
while((SPSR&0x80)==0);
}
}
Slave:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRD=0xFF;
//DDRB=0X40;
SPCR=0x70;
while(1)
{
while((SPSR&0x80)==0);
PORTD=SPDR;
}
}
Simulation for MOSI:
Program for SPI (MISO):
Master:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
while(1)
{
DDRB=0x2C;
SPCR=0x70;
SPDR=0x55;
while((SPSR&0x80)==0);
DDRB=0x34;
DDRD=0xFF;
SPCR=0x50;
while((SPSR&0x80)==0);
PORTD=SPDR;
while(1);
}
}
Slave:
#include<avr/io.h>
#include<util/delay.h>
void main()
{
while(1)
{
DDRD=0xFF;
SPCR=0x40;
while((SPSR&0x80)==0);
PORTD=SPDR;
DDRB=0x10;
SPCR=0x60;
SPDR=0x55;
while((SPSR&0x80)==0);
while(1);
}
}
0 comments:
Post a Comment
if you have any doubt please let me know