SPI自测是通的,但是当读取W25Q64的ID时失败。具体配置如下:
// SPI 配置
void HW_Spi_Init(void)
{
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO54 = 0; // Enable pull-up on GPIO54 (SPISIMO)
GpioCtrlRegs.GPBQSEL2.bit.GPIO54 = 3; // Asynch input GPIO54 (SPISIMO)
GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMO
GpioCtrlRegs.GPBDIR.bit.GPIO54 = 1; // Configure GPIO54 as output pin
GpioCtrlRegs.GPBPUD.bit.GPIO55 = 0; // Enable pull-up on GPIO55 (SPISOMI)
GpioCtrlRegs.GPBQSEL2.bit.GPIO55 = 3; // Asynch input GPIO55 (SPISOMI)
GpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMI
GpioCtrlRegs.GPBDIR.bit.GPIO55 = 0; // configure GPIO55 as input pin
GpioCtrlRegs.GPBPUD.bit.GPIO56 = 0; // Enable pull-up on GPIO56 (***)
GpioCtrlRegs.GPBQSEL2.bit.GPIO56 = 3; // Asynch input GPIO56 (***)
GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as ***
GpioCtrlRegs.GPBDIR.bit.GPIO56 = 1;
GpioCtrlRegs.GPBPUD.bit.GPIO57 = 0; // Disable pull-up on GPIO57 (SPISET)
GpioCtrlRegs.GPBQSEL2.bit.GPIO57 = 3; // Asynch input GPIO57 (SPISET)
GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 0; // Configure GPIO57 as I/O
GpioCtrlRegs.GPBDIR.bit.GPIO57 = 1;
// GpioDataRegs.GPBSET.bit.GPIO57 = 1;
EDIS;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; // SPIACLK
EDIS;
// InitSpiaGpio();
SpiaRegs.***.bit.SPISWRESET=0; // Reset SPI
SpiaRegs.***.all=0x0007; // 8-bit character, no Loopback mode
SpiaRegs.***.all=0x0017; // Interrupt enabled, Master/Slave XMIT enabled
SpiaRegs.SPISTS.all=0x0000;
SpiaRegs.SPIBRR=0x007F; // Baud rate
SpiaRegs.SPIFFTX.all=0xC028; // Enable FIFO's, set TX FIFO level to 8
SpiaRegs.SPIFFRX.all=0x0028; // Set RX FIFO level to 8
SpiaRegs.SPIFFCT.all=0x00;
SpiaRegs.SPIPRI.all=0x0010;
SpiaRegs.***.bit.SPILBK = 0;
SpiaRegs.***.bit.SPISWRESET=1; // Enable SPI
SpiaRegs.SPIFFTX.bit.TXFIFO=1;
SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;
}
// SPI 发送指令函数
uint8_t SPIA_SendRecData(uint8_t data)
{
SpiaRegs.SPITXBUF = data ;
while (1 != SpiaRegs.SPIFFRX.bit.RXFFST);
return SpiaRegs.SPIRXBUF ;
}
uint8_t W25Q64_RWData(uint8_t val){
return SPIA_SendRecData(val);
}
// 读写W25Q64 ID
Uint32 W25Q64_GetDeviceID(void){
Uint32 ID = 0;
Uint32 id0 = 0, id1 = 0, id2 = 0;
SPISTE_SETL;
SPIA_SendRecData(0x9F); // 0x9F: 读取ID指令
id0 = W25Q64_RWData(FLAG);
id1 = W25Q64_RWData(FLAG);
id2 = W25Q64_RWData(FLAG);
ID = (id0 << 16) | (id1 << 8) | id2;
SPISTE_SETH;
return ID;
}
我在SPI中断中调用了读取W25Q64设备ID的功能:idd = W25Q64_GetDeviceID();
调试结果如下
Expressions Type Value Address
SpiaRegs.SPITXBUF unsigned int 0x00FF (Hex) 0x00007048@Data
SpiaRegs.SPIRXBUF unsigned int 0x9FFF (Hex) 0x00007047@Data
idd unsigned long 0xFFFFFFFF (Hex) 0x0000C004@Data
SPI总是发什么收什么,似乎不能从W25Q64设备中接收数据,所以idd返回值一直是0xFFFFFF。求指教!!!
Green Deng:
你好,你在8月有发布过一个相同的帖子,之后就没有回复,请问这两个帖子目前的状态有不同吗?
e2echina.ti.com/…/191980
DLAM:
回复 Green Deng:
您好,十分感谢您的回复!!八月的那个帖子我上午修改了,和之前不太一样了。我担心修改过的帖子不会有回复(也没找到删帖的地方),所以我又重新发了一篇帖子。八月的时候确实是我们公司的芯片问题,现在换了新的芯片,SPI可完成环路自测,但是不能与W25Q64进行正常通信,比如我上面提到的读取W25Q64的ID不能正常进行,返回值依然是我发送的指令。期待您的回复,谢谢!
Green Deng:
回复 DLAM:
祝贺!我还在看W25Q64的资料了。。。
方便的话可以分享一下解决方案。
DLAM:
回复 Green Deng:
问题出在数据类型,上面的指令我定义的unsigned char ,而SPI的收发缓冲寄存器的Uint16类型的,指令要通过强转和移位才能准确被接收返回得到。Uint16 data1 = (Uint16)data << 8;SpiaRegs.SPITXBUF = data1 ;