您好,
我參考StartWare02_02_01_01撰寫了一個spi的測試程式..
情況1. 在WAIT_EOT=0的情況下,運行讀寫測試...,讀寫數百次後,會有機會讀回一筆0x00(但應該是0x86)
情況2. 在WAIT_EOT=1的情況下,運行讀寫測試...,每次讀回的資料是0x00(但應該是0x86)
PS:沒有啟用中斷服務..
請問,是否有需要注意的地方呢?
Kerry
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);
#if WAIT_EOT
//Wait until 'end of transmission' flag is set
while (0 == (McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH0STAT_EOT))
{
//Wait and do nothing
}
#endif
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;
}