目的是先用MASTER模式配置RF芯片,然后切换为SLAVE模式中断接收RF输出的数据..
查询模式下配置RF芯片可以(通过读出RF的寄存器验证了).单用中断就是不工作..GCC AVR....大家瞅瞅我那里出问题....3天了...
void SPI_Init_Slave(void)
{
//SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 :SPCR,spr1,spr0=0,fosc/4
DDR_SPI |=(1<<DD_MISO); //OUTPUT
DDR_SPI &=~(1<<DD_MOSI); //INPUT
DDR_SPI &=~(1<<DD_SCK); //INPUT
DDR_SPI &=~(1<<DD_SS); //INPUT
SPCR &=~(1<<MSTR);
SEB_ENABLE;
}
void SPI_Init_Master(void)
{
//SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 :SPCR,spr1,spr0=0,fosc/4
DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
DDR_SPI &=~(1<<DD_MISO);
PORTB |= (1<<DD_MISO);
PORTB |= (1<<DD_MOSI);
PORTB |= (1<<DD_SCK);
//PORTB |= (1<<DD_SS);
SPCR &=~(1<<CPOL);
SPCR |=(1<<SPIE)|(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0)|(1<<CPHA);//MSB first
SPSR = (1<<SPI2X);//double speed,10Meg frequency SCK,
}
void SPI_MasterTransmit(unsigned char cData)
{
while(SPI_Busy);
SPI_Read=False;
SPDR = cData;
SPI_Busy=True;
//while(!(SPSR & (1<<SPIF)));
}
uchar SPI_MasterRead(void)
{
while(SPI_Busy);
SPI_Read=True;
SPDR=0x00;
SPI_Busy=True;
// while(!(SPSR & (1<<SPIF)));
// return SPDR;
}
ISR(SPI_STC_vect)
{
if(SPI_Read==True) //Read SPI
{
SPI_Data=SPDR;
}
else//send
{
}
SPI_Busy=False;
} |