Other Parts Discussed in Thread: HALCOGEN
I want to create a generic interrupt driven I2C read function and have done the following so far:
I call i2cInit() which adopts the following HALCoGen settings for I2C_2:
- Enable I2C2 driver
- I2C2:
- Enable Master Mode
- Tx/Rx: TRANSMITTER
- Add Mode: 7_BIT_AMODE
- Bit Count: 8_BIT
- ICRRDY enabled
- ICXRDY enabled
- I2C Pin Mode: I2C Functional
- Pin Muxing:
- I2C2 checked (SDA @ G17 and SCL @ G16)
My read function does the following calls:
uint8 ch;
i2cSetSlaveAdd( i2cREG2, SLAVE_ADDR );
i2cSetDirection( i2cREG2, I2C_TRANSMITTER );
i2cSetCount( i2cREG2, 2 );
i2cSetMode( i2cREG2, I2C_MASTER );
i2cSetStop( i2cREG2 );
i2cSetStart( i2cREG2 );
i2cSend( i2cREG2, 1u, REGISTER_ADDR );
while ( i2cIsBusBusy( i2cREG2 ) == TRUE );
while ( i2cIsStopDetected( i2cREG2 ) == TRUE );
i2cClearSCD( i2cREG2 );
i2cSetSlaveAdd( i2cREG2, SLAVE_ADDR );
i2cSetDirection( i2cREG2, I2C_RECEIVER );
i2cSetCount( i2cREG2, 2u );
i2cSetMode( i2cREG2, I2C_MASTER );
i2cSetStart( i2cREG2 );
i2cReceive( i2cREG2, 1u, &ch );
i2cClearSCD( i2cREG2 );
My i2cNotification function is as follows:
void i2cNotification( i2cBASE_t *i2c, uint32 flags )
{
uint8 ch;
if ( flags & I2C_RX_INT )
{
i2cReceive( i2cREG2, 1, &ch );
}
}
Running the above code on the HDK, the interrupt service routine (ic2Notification) receives 4 bytes (All wrongly zero) from a BME280 sensor that I request its ID which is one byte!
Can someone please comment on errors in my function call sequence above?
What should the i2cSetCount value be? Does it need to take into consideration the Slave Address?
Thank you.