我的C32 SPI接收不到数据!MOSI脚一直出现杂波。
主模式对从机初始化正常,波形和数据都正确,设置为从模式时,不能进入中断!请各位高手指教。SPI初始化程序如下:
void SPIInitial(void) { uchar temp; //MODRR=0x10; //define SPI0 pins are PM2-PM5,CAN0 pins are PM0-PM1. //ss=1; //ss pin is high, master mode //DDRM|=0x30; //master mode, MOSI,SCK are output;MISO,SS are input SPICR1=0x54; SPICR2=0x00; SPIBR=0x17; //SPI baud rate set:SPI0BR=0x17 is 7.8125 kHz,SPI0BR=0x07 is 15.625 kHz // SPIDR=0x73; //initialize the slave //while(!SPI0SR_SPIF); while(!SPISR_SPTEF); delay(1); SPIDR=0xFF; //while(!SPI0SR_SPIF); while(!SPISR_SPTEF); delay(1); SPIDR=0x88; //while(!SPI0SR_SPIF); while(!SPISR_SPTEF);//等待发送完毕 delay(1);
SPIDR=0x80; //while(!SPI0SR_SPIF); while(!SPISR_SPTEF); delay(1); SPIDR=0x00; //while(!SPI0SR_SPIF); while(!SPISR_SPTEF); delay(1); SPIDR=0x00; //while(!SPI0SR_SPIF); while(!SPISR_SPTEF); delay(1); temp=SPISR; //Clear SPIF bit temp=SPIDR; SPICR1&=0xEF; //MSTR=0,slave mode //DDRM&=0xC3; //DDRM|=0x04; //slave mode,MISO is output,MOSI,SCK,SS are input.
// asm NOP;asm NOP;asm NOP; ss=0; rstb=1; SPICR1|=0x80; //enable SPI interrupt } |