您好, C6748 SPI1 外接了一片FRAM,本人参考了Processor SDK RTOS 06_03_00_106中SPI loopback的用例,FRAM_CS连接到SPI1_SCS[0], pin脚多路复用已配置成SPI模式,尝试利用FRAM的RDID命令读取device ID, 修改的代码如下:
#define SPI_INS_FRAM 1
#define SPI_PORT_FRAM 1
#define FRAM_ID_NUM_BYTES (9U)
#pragma DATA_ALIGN (txBuf, 128)
uint8_t txBuf;
#pragma DATA_ALIGN (rxBuf, 128)
uint8_t rxBuf[FRAM_ID_NUM_BYTES];
/*
* ======== SPI test function ========
*/
voidspi_test()
{
Board_initSPI();
bool testPassed =true;
uint32_t xferEnable, len, loop = 1;
uint32_t count = 0;
uint32_t terminateXfer = 0;
bool retVal;
uint32_t spi;
/* SPI params structure */
SPI_Params spiParamsFram;
/* SPI handle */
SPI_Handle framHandle;
/* SPI transaction structure */
SPI_Transaction transactionFram;
/* SPI Hardware attributes */
SPI_v0_HWAttrs spi_cfg_fram;
/* Get the default SPI init configurations */
SPI_socGetInitCfg(SPI_INS_FRAM, &spi_cfg_fram);
/* Set the DMA related init config */
spi_cfg_fram.pinMode = SPI_PINMODE_4_PIN;
spi_cfg_fram.edmaHandle = SPIApp_edmaInit();
spi_cfg_fram.dmaMode = TRUE;
spi_cfg_fram.enableIntr =false;
SPI_socSetInitCfg(SPI_INS_FRAM, &spi_cfg_fram);
/* Init SPI driver */
SPI_init();
/* Open the Board flash NOR device with the test SPI port
and use the default SPI configurations */
SPI_Params_init(&spiParamsFram);
/* Config SPI params*/
spiParamsFram.transferMode = SPI_MODE_BLOCKING;
spiParamsFram.frameFormat = SPI_POL0_PHA0;
spiParamsFram.dataSize = 8;
spiParamsFram.bitRate = FRAM_FREQ; //30MHz
framHandle = (SPI_Handle)SPI_open(SPI_PORT_FRAM, &spiParamsFram);
if (!framHandle)
{
testPassed =false;
System_printf("\n no spi framHandle.\n");
}
/* Enable transfer */
xferEnable = 1;
SPI_control(framHandle, SPI_V0_CMD_XFER_ACTIVATE, (void *)&xferEnable);
txBuf = FRAM_RDID; //read fram device ID cmd
len = FRAM_ID_NUM_BYTES; // 9 bytes
transactionFram.txBuf = (void *)&txBuf;
transactionFram.rxBuf = (void *)&rxBuf[0];
transactionFram.count = len;
transactionFram.arg = NULL;
retVal = SPI_transfer(framHandle, &transactionFram);
for (count = 0; count < FRAM_ID_NUM_BYTES; count++)
{
System_printf("Received Data : %x. \n",rxBuf[count]);
}
SPI_close(framHandle);
}
最终获取到的rxBuf全为0xFFh,并不是期望的 FRAM Device ID, 请问是哪里出了问题还是SDK提供的接口使用不当
同时参考nor_spi.c的代码 分别写入RDID 命令再进行读取操作,代码如下:
// write RDID cmd
txBuf = FRAM_RDID;
len = 1;
transactionFram.txBuf = (void *)&txBuf;
transactionFram.rxBuf = NULL;
transactionFram.count = len;
transactionFram.arg = NULL;
retVal = SPI_transfer(framHandle, &transactionFram);
// read device ID
len = FRAM_ID_NUM_BYTES;
transactionFram.txBuf = NULL;
transactionFram.rxBuf = (void *)&rxBuf[0];
transactionFram.count = len;
transactionFram.arg = NULL;
retVal = SPI_transfer(framHandle, &transactionFram);
然而在运行到第二次SPI_transfer中时(read device ID), 跑进了
if (overflow != FALSE) {
Error_raise(NULL, Hwi_E_stackOverflow, 0, 0);
}
请问这种对SPI接口的使用是有什么问题?
感谢各位的指点和解答
kaijie zhang:
回复 Shine:
FRAM支持SPI mode 0 (0, 0) and mode 3 (1, 1), 我配置了spiParamsFram.frameFormat = SPI_POL0_PHA0;
kaijie zhang:
调试发现将SPI_v0_HWAttrs中的dmaMode置False,nor_spi的示例可以运行,但是device ID依然读取错误
kaijie zhang:
回复 Shine:
十分感谢回答 我重新对照了C6748 和FRAM 的 SPI时序模式, 修改之后读取正常了
Shine:
回复 kaijie zhang:
非常高兴您的问题解决了,感谢分享!