说明:传感器工作在SPI的模式0,传输速度最高10MHZ,MSB,8bit数据;
程序概括:使用芯片的SPIB引脚,根据官方例程进行代码修改,完成寄存器配置
目前程序现象:已关闭自循环标志位,但是发送数据以后,还是会在接收寄存器观察到相同的数据,就是发什么接收什么。
代码:
1、主程序
#include "F28x_Project.h" void spi_xmit(Uint16 a); void spi_fifo_init(void); void spib_fifo_init(void); unsigned char spib_xmit(unsigned char a); unsigned char RecData; unsigned char SendData; void main(void) {InitSysCtrl();InitSpibGpio();DINT;InitPieCtrl();IER = 0x0000;IFR = 0x0000;InitPieVectTable();spib_fifo_init();// Initialize the SPI FIFOSendData = 0x00;for(;;){RecData = spib_xmit(SendData);SendData++;if(SendData == 0xFF){SendData = 0x00;}} } // // spi_fifo_init - Initialize SPIB FIFO // void spib_fifo_init(void) {//// Initialize SPI FIFO registers//SpibRegs.SPIFFTX.all = 0xE040;SpibRegs.SPIFFRX.all = 0x2044;SpibRegs.SPIFFCT.all = 0x0;//// Initialize core SPI registers//InitSpib(); } // // spi_xmit - Transmit value via SPI // unsigned char spib_xmit(unsigned char a) {unsigned char Receive;SpibRegs.SPITXBUF = a;while(SpibRegs.SPIFFRX.bit.RXFFST !=1) { }Receive = SpibRegs.SPIRXBUF;Receive = Receive >> 8;return Receive; } // // End of file //
2、SPIB的引脚和寄存器配置
void
InitSpib(void
)
{
// Initialize SPI-B
// Set reset low before configuration changes
// Clock polarity (0 == rising, 1 == falling)
// 8-bit character
// Disable loop-back
SpibRegs.***.bit.SPISWRESET = 0;
SpibRegs.***.bit.CLKPOLARITY = 0;
SpibRegs.***.bit.*** = (8-1);
SpibRegs.***.bit.SPILBK = 0;
// Enable master (0 == slave, 1 == master)
// Enable transmission (Talk)
// Clock phase (0 == normal, 1 == delayed)
// SPI interrupts are disabled
SpibRegs.***.bit.MASTER_SLAVE = 1;
SpibRegs.***.bit.TALK = 1;
SpibRegs.***.bit.CLK_PHASE = 0;
SpibRegs.***.bit.SPIINTENA = 0;
// Set the baud rate
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = SPI_BRR;
// Set FREE bit
// Halting on a breakpoint will not halt the SPI
SpibRegs.SPIPRI.bit.FREE = 1;
// Release the SPI from reset
SpibRegs.***.bit.SPISWRESET = 1;
}
void
InitSpibGpio(void
)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO16 (SPISIMOB)
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO17 (SPISOMIB)
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO18 (***)
GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0; // Enable pull-up on GPIO19 (SPISTEB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3;// Asynch input GPIO16 (SPISIMOB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3;// Asynch input GPIO17 (SPISOMIB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3;// Asynch input GPIO18 (***)
GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3;// Asynch input GPIO19 (SPISTEB)
GpioCtrlRegs.GPAGMUX2.bit.GPIO24 = 1;// Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAGMUX2.bit.GPIO25 = 1;// Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAGMUX2.bit.GPIO26 = 1;// Configure GPIO18 as ***
GpioCtrlRegs.GPAGMUX2.bit.GPIO27 = 1;// Configure GPIO19 as SPISTEA
GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 2;// Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 2;// Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 2;// Configure GPIO18 as ***
GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 2;// Configure GPIO19 as SPISTEA
EDIS;
}
Green Deng:
你好,你具体是用的哪个例程?都做了哪些修改?
在接收寄存器观察到相同的数据,与传感器的通信有问题吗?