ANS HAFEEZ
Advanced Member level 4
- Joined
- Jul 25, 2013
- Messages
- 101
- Helped
- 5
- Reputation
- 10
- Reaction score
- 5
- Trophy points
- 1,298
- Location
- LAHORE,PAKISTAN
- Activity points
- 1,911
SALAM to all
Atmega32 as a Slave
Atmega8 as a Master
Code is Done according to datasheets But Proteus Simulation Not Working
CODE for Master:
CODE FOR SLAVE:
ANy HElp???:bang:
Atmega32 as a Slave
Atmega8 as a Master
Code is Done according to datasheets But Proteus Simulation Not Working
CODE for Master:
Code:
/*
* SPI_8_MASTER.c
*
* Created: 1/8/2015 3:36:36 PM
* Author: ANCC
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#define MOSI PINB3
#define SCK PINB5
#define MISO PINB4
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDRB = (1<<MOSI)|(1<<SCK);
DDRB &= ~(1<<MISO);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);
SPSR=0x00;
}
void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}
int main(void)
{
SPI_MasterInit();
while(1)
{
SPI_MasterTransmit('C');
}
}
CODE FOR SLAVE:
Code:
/*
* SPI_32.c
*
* Created: 1/8/2015 3:26:11 PM
* Author: ANCC
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#define MISO PINB6
#define MOSI PINB5
#define SCK PINB7
void SPI_SlaveInit(void)
{
/* Set MISO output, all others input */
DDRB |= (1<<MISO);
DDRB &=~(1<<MOSI)|(1<<SCK);
/* Enable SPI */
SPCR = (1<<SPE)|(1<<SPR1);
SPSR=0x00;
}
char SPI_SlaveReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)))
;
/* Return data register */
return SPDR;
}
int main(void)
{
SPI_SlaveInit();
int data=0;
DDRD=0xFF;
while(1)
{
data=SPI_SlaveReceive();
PORTD=data;
}
}
ANy HElp???:bang: