Other Parts Discussed in Thread: PCF8575, HALCOGEN
Hello,
I need some help on my code for the MCU as Master Receiver to read port status of PCF8575.
My code was based on HalCoGen generated template.
I remember I can went through it before. But I ran into problem now.
(1) to read 16bit port of PCF8575, MCU need to write "FF" and "FF" to the port first - The write portion works.
(2) then set the I2C to be receive mode, and start to read using "i2cReceiveByte()", it can read the 1st byte data, but stuck at the 2nd byte read - waiting for RX status bit.
Now, I am confusing how the MCU generate the clocks for reading out the 2nd byte data?
Please provide advice and comments. Thanks!
Yanzhong
unsigned int i2cReceiveByte(i2cBASE_t *i2c)
{
while ((i2cREG1->STR & I2C_RX_INT) == 0) { /* wait */ };
return i2cREG1->DRR;
}
========= code to read I2C port (PCF8575 16bit, in main() ============
// ---- Write U11 with "FF"
I2CMDR_bit.MST = 1; //set MSTER Mode again
i2cSetSlaveAdd(i2cREG1, 0x20);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, 0xFF); // write first byte
i2cSendByte(i2cREG1, 0xFF); // write 2nd byte
//stop i2cSetStop(i2cREG1);
// ---- Read U11 Value
i2cSetSlaveAdd(i2cREG1, 0x20);
I2CMDR_bit.MST = 1; //Set as Master
I2CMDR_bit.TRX = 0; //READ - Receive data
i2cClearSCD(i2cREG1);
i2cSetStart(i2cREG1);
I2CRD1 = i2cReceiveByte(i2cREG1); // Read 1st byte - executed successfully
I2CRD2 = i2cReceiveByte(i2cREG1); // Read 2nd byte - stuck here, waiting for RX ready status ?
I2CRD1 = i2cReceiveByte(i2cREG1); // Read 1st byte - repeat
I2CRD2 = i2cReceiveByte(i2cREG1); // Read 2nd byte - repeat
i2cSetStop(i2cREG1);