TI中文支持网
TI专业的中文技术问题搜集分享网站

am437x的spi接收问题

我的spi作为主机,我设置的是全双工的模式,但是今天折腾一下午了,数据发送没有问题,但是接收老是全0,后来我直接把发送和接收短接了,保证接收引脚上肯定有波形,接收还是全0.我把接收引脚直接接高电平,也是全零。

我觉得是配置的问题,但我检查了好几遍了是rx-tx的全双工模式并且d0设为了输出d1设为了输入。好郁闷啊。。

static int32_t MCSPIAppInit(CommonCfg_t *pCfgMcspi,MyData_t *pObj)
{
int32_t status = S_PASS;

/* Clock Configuration. */
status = PRCMModuleEnable(CHIPDB_MOD_ID_MCSPI, pObj->instNum, 0U);

if (S_PASS != status)
{
CONSOLEUtilsPrintf("\n Clock Configuration failed !\n");
}
else
{
/* Perform the MCSPI pinmux. */
status = PINMUXModuleConfig(CHIPDB_MOD_ID_MCSPI, pObj->instNum, NULL);

if (S_PASS != status)
{
CONSOLEUtilsPrintf("\n Pin Muxing failed !\n");
}
else
{
if((MCSPI_INTERRUPT_MODE == pCfgMcspi->pAppFlag.comFlag) |
(MCSPI_NO_MODE == pCfgMcspi->pAppFlag.comFlag))
{
if(MCSPI_INTERRUPT_MODE == pCfgMcspi->pAppFlag.comFlag)
{
/* Register the MCSPI interrupts. */
//McspiAppIntrConfig(pCfgMcspi);
}
/* Reset the MCSPI instance.*/
McSPIReset(pObj->instAddr);

if (TRUE == pCfgMcspi->pAppFlag.csFlag)
{
/* Enable CS. */
MCSPICsEnable(pObj->instAddr, TRUE);

/* Set the CS polarity. */
MCSPISetCsPol(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppCfg.csPolarity);
}
else if (FALSE == pCfgMcspi->pAppFlag.csFlag)
{
/**
* Disable CS. In this scenario the CS will be handled
* externally. E.g. would be using an external GPIO pin
* or the CS pin of slave device is pulled to the required
* polarity as default.
*/
MCSPICsEnable(pObj->instAddr, FALSE);
}

if (MCSPI_MODE_MASTER == pCfgMcspi->pAppFlag.modeFlag)
{
/* Perform the necessary configuration for master mode.*/
MCSPIModeConfig(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppFlag.modeFlag,
pCfgMcspi->pAppCfg.channel,
pCfgMcspi->pAppCfg.txRxMode,
pCfgMcspi->pAppCfg.pinMode);

/* Configure the clock speed on the bus. */
MCSPIClkConfig(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->inClk,
pCfgMcspi->outClk,
pCfgMcspi->pAppCfg.clkMode);
}
else if (MCSPI_MODE_SLAVE == pCfgMcspi->pAppFlag.modeFlag)
{
/* Perform the necessary configuration for slave mode.*/
MCSPIModeConfig(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppFlag.modeFlag,
pCfgMcspi->pAppCfg.channel,
pCfgMcspi->pAppCfg.txRxMode,
pCfgMcspi->pAppCfg.pinMode);
}

/* Configure the word length. */
McSPIWordLengthSet(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppCfg.wordLength);

/* Enable/disable the Tx FIFO. */
McSPITxFIFOConfig(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppCfg.txFifoCfg);

/* Enable/disable the Rx FIFO. */
McSPIRxFIFOConfig(pObj->instAddr,
pObj->channelNum,
pCfgMcspi->pAppCfg.rxFifoCfg);
}
else if(MCSPI_DMA_MODE == pCfgMcspi->pAppFlag.comFlag)
{
CONSOLEUtilsPrintf("\n DMA mode is not supported !\n");
}
}
}
return(status);
}

这个是初始化,是starterware的源码。

uint16_t MCSPI_TxRxOneByte(uint32_t baseAddr,uint32_t chNum,uint16_t txdata)
{
uint32_t chstatus;
uint32_t data;
uint32_t tcount=0;
/* SPIEN line is forced to low state.*/
McSPICSAssert(baseAddr, chNum);
/* Enable the MCSPI channel for communication.*/
MCSPIChEnable(baseAddr, chNum, TRUE);
chstatus = MCSPIChStatus(baseAddr, chNum);//获取当前通道状态寄存器的值
while(((chstatus>>1)&1)!=1&&(tcount<1000))//等待发送寄存器为空
{
tcount++;
if(tcount>=1000)
{
return 0;//发送失败
}
chstatus = MCSPIChStatus(baseAddr, chNum);
}
/*填充发送数据到发送寄存器*/
McSPITransmitData(baseAddr,chNum,(uint32_t)txdata);
tcount=0;//超时计数清0
chstatus = MCSPIChStatus(baseAddr, chNum);//获取当前通道状态寄存器的值
while((chstatus & 1)!=1&&(tcount<1000))//等待接收寄存器full
{
tcount++;
if(tcount>=1000)
{
return 1;//接收失败失败
}
chstatus = MCSPIChStatus(baseAddr, chNum);//获取当前通道状态寄存器的值
}
data = McSPIReceiveData(baseAddr,chNum);
/* Force SPIEN line to the inactive state.*/
McSPICSDeAssert(baseAddr, chNum);
/* Disable the MCSPI channel.*/
MCSPIChEnable(baseAddr, chNum, FALSE);
return (uint16_t)data;
//return 0;
}

这个是发送和接收一个数据的函数。

static const CommonCfg_t MCSPIAPP_DEFAULT =
{
48000000U, /* inClk.*/
12000000U, /* outClk.*/
{
MCSPI_CH_SINGLE, /* channel.*/
MCSPI_TRANSFER_MODE_TX_RX, /* txRxMode.*/
MCSPI_DATA_LINE_COMM_MODE_6, /* pinMode. D1接收,D0发送*/
MCSPI_CLK_MODE_3, /* clkMode.*/
16U, /* wordLength.*/
MCSPI_CS_POL_LOW, /* csPolarity.*/
TRUE, /* txFifoCfg.*/
FALSE, /* rxFifoCfg.*/
MCSPI_INTR_TX_EMPTY(0U) | \
MCSPI_INTR_RX_FULL(0U) /* interrupt.*/
},
{
INTC_TRIG_HIGH_LEVEL, /* trigType.*/
0U, /* intrLine.*/
10U, /* intrPriority.*/
FALSE, /* isIntrSecure.*/
NULL, /* pTxBuf.*/
NULL, /* pRxBuf.*/
NULL /* pFnIntrHandler.*/
},
{
TRUE, /* csFlag.*/
MCSPI_MODE_MASTER, /* modeFlag.*/
MCSPI_NO_MODE /* comFlag.*/
}
};这个是配置的结构体

我关掉了中断,用的轮询方式。

yakun song:

在全双工模式下,没发送一次数据,接收寄存器的状态为也会置位,表示满,但接收寄存器的值RX0一直是0,不管接啥都是零,这样就好郁闷啊。。。

Shine:

回复 yakun song:

请问有量过接收时序吗?试试在每次接收之前,先写一次dummy write(往发送寄存器里随便写个数)。

赞(0)
未经允许不得转载:TI中文支持网 » am437x的spi接收问题
分享到: 更多 (0)