Hi,
Customer write a simple spi transmitter/receive project which referring to AM335X_StarterWare_02_00_01_01-master/examples/evmAM335x/mcspi/mcspiFlash.c.
He just polling RXS bit in MCSPI_CH0STAT and read MCSPI_RX and he don't use interrupt.
After reading and writing hundreds of times, there will be an inconsistent data reading(read 0x86 as 0x00) and sometimes MCSPI_CH0STAT_RXS is always "1", how to debug?
chNum = 1;
/* Enable the clocks for McSPI0 module.*/
McSPI0ModuleClkConfig();
/* Perform Pin-Muxing for SPI0 Instance */
McSPIPinMuxSetup();
/* Perform Pin-Muxing for CS0/CS1 of SPI0 Instance */
McSPI0CSPinMuxSetup(chNum);
/* Reset the McSPI instance.*/
McSPIReset(SOC_SPI_0_REGS);
/* Enable chip select pin.*/
McSPICSEnable(SOC_SPI_0_REGS);
/* Enable master mode of operation.*/
McSPIMasterModeEnable(SOC_SPI_0_REGS);
/* Perform the necessary configuration for master mode.*/
McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_MULTI_CH,
MCSPI_TX_RX_MODE, MCSPI_DATA_LINE_COMM_MODE_0,
chNum);
/* Configure the McSPI bus clock depending on clock mode. */
McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, chNum,
MCSPI_CLK_MODE_1);
/* Configure the word length.*/
McSPIWordLengthSet(SOC_SPI_0_REGS, MCSPI_WORD_LENGTH(16), chNum);
/* Set polarity of SPIEN to low.*/
McSPICSPolarityConfig(SOC_SPI_0_REGS, MCSPI_CS_POL_LOW, chNum);
WriteEnable();
static void WriteEnable(void)
{
unsigned char tmp;
unsigned char cnt = 0x86;
while(1) {
McSPITransfer(0x4800, cnt);
tmp = McSPITransfer(0x4A00, 0x00);
if(cnt != tmp)
{
DEBUG("loopCnt = %d, wr = %x, rd = %x", loopCnt, cnt, tmp);
}
}
return ;
}
unsigned char McSPITransfer(unsigned short cmd, unsigned short data)
{
unsigned char rcv_data = 0;
unsigned short cmd_data ;
cmd_data = cmd + data;
/* SPIEN line is forced to low state.*/
McSPICSAssert(SOC_SPI_0_REGS, chNum);
/* Enable the McSPI channel for communication.*/
McSPIChannelEnable(SOC_SPI_0_REGS, chNum);
McSPITransmitData(SOC_SPI_0_REGS,(unsigned int)cmd_data, chNum);
while (1 == (McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH0STAT_RXS))
{
//Wait and do nothing
}
rcv_data = McSPIReceiveData(SOC_SPI_0_REGS, chNum);
/* Force SPIEN line to the inactive state.*/
McSPICSDeAssert(SOC_SPI_0_REGS, chNum);
McSPIChannelDisable(SOC_SPI_0_REGS, chNum);
return rcv_data;
}