下面是我目前的程式碼,在case1的地方FFST永遠為0導致卡在無窮回圈內,讀不出值。請教一下我這邊應該是出了甚麼問題?
void drv_I2C_read(Uint16 uiPar_Addr,Uint16 recieve_bytes)
{
Uint16 uiaddr;
Uint16 NUM;
NUM = recieve_bytes;
switch(stDrv_I2C.uiread_state)
{
case 0:
uiaddr = uiPar_Addr;
DELAY_US(1000L); // Delay 1ms
I2caRegs.I2CCNT = 1; // Set 1 byte to be transmitted
I2caRegs.I2CDXR = uiaddr;
I2caRegs.I2CMDR.all = FRE + STT + MST + TRX + IRS; // Configure mode register as transmitter mode
DELAY_US(1000L); // Delay 1ms
I2caRegs.I2CCNT = NUM; // Set 1 byte to be transmitted
I2caRegs.I2CMDR.all = FRE + STT + STP_CMD + MST + IRS; // Configure mode register as receive mode
stDrv_I2C.uiread_state = 1;
break;
case 1:
if(I2caRegs.I2CFFRX.bit.RXFFST >= 1) // Confirm 1 byte had been received------------------------------------I'm stuck here.RXFFST always 0
stDrv_I2C.uiread_state = 2;
break;
case 2:
stDrv_I2C.uiread_data.byte.hi = I2caRegs.I2CDRR; // Acquire high byte data bytes
stDrv_I2C.uiread_data.byte.lo = I2caRegs.I2CDRR; // Acquire low byte data bytes
stDrv_I2C.uiread_state = 3;
break;
case 3:
stDrv_I2C.uiread_state = 0; // Reset I2C flow-status flag
stDrv_I2C.uiread_end = 1; // Set I2C END status
break;
default:
break;
}
}
Any answer will be appreciate.
Thanks.
Andy