最近在调试F2812的SPI从模式; 两块F2812对连,SPICLK-SPICLK;SPISIMO-SPISIMO;SPISTE-SPISTE; 一块做主,一块做从,做主的发送,采用中断或查询都正常,用示波器看过;但是接收部分用中断或查询都不对;rdata=SpiaRegs.SPIRXBUF;用单步执行两边的变量也总不相同;不知道为什么 数据总是乱的 代码如下: //**************slaver model and interrupt RX************* void InitSpi() {
// Initialize SPI FIFO registers SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
SpiaRegs.SPICCR.all=0x4F; //16-bit character, SpiaRegs.SPICTL.all=0x03; //Interrupt enabled, Slave XMIT enabled SpiaRegs.SPISTS.all=0x0000; SpiaRegs.SPIBRR=0x05; // Baud rate //SpiaRegs.SPIFFTX.all=0xC028; // Enable FIFO's, set TX FIFO level to 8 SpiaRegs.SPIFFRX.all=0x28; // Set RX FIFO level to 16 SpiaRegs.SPIFFCT.all=0x00; SpiaRegs.SPIPRI.all=0x30; SpiaRegs.SPICCR.bit.SPISWRESET=1; // Enable SPI
//SpiaRegs.SPIFFTX.bit.TXFIFO=0; SpiaRegs.SPIFFRX.bit.RXFIFORESET=1; } interrupt void spiRxFifoIsr(void) { Uint16 i; rdata_point=(unsigned int *)(DP_start_UP_ADDR); for(i=0;i<8;i++) { rdata=SpiaRegs.SPIRXBUF;// Read data } for(i=0;i<8;i++) { *rdata_point=rdata&0xFFFF; rdata_point++; } SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1; // Clear Overflow flag SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag PieCtrlRegs.PIEACK.all|=0x20; // Issue PIE ack }
void spi_initial(void) { SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI SpiaRegs.SPICCR.all=0x4F;//使SPI处于复位模式,下降沿,16位数据 SpiaRegs.SPICTL.all=0x06;//主控模式,一般时钟,使能talk,关闭SPI中断 SpiaRegs.SPIBRR=0x05;//配置波特率 baud rate=LSPCLK/(3+1) SpiaRegs.SPIPRI.all=0x0030; SpiaRegs.SPICCR.bit.SPISWRESET=1;//退出复位
} void SPITX() {unsigned int i; sdata_point=(unsigned int *)(SD_START_ADDR); for(i=0;i<8;i++) { sdata1=*sdata_point; SpiaRegs.SPITXBUF=sdata1; while(SpiaRegs.SPISTS.bit.INT_FLAG!=1){} SpiaRegs.SPIRXBUF=SpiaRegs.SPIRXBUF; sdata_point++; } }
|