Part Number: RM46L852
Other Parts Discussed in Thread: HALCOGEN
I want to use the I2C Master peripheral in a non-blocking way (no infinite while loops).
To do so, I need to learn how to use the TI HalCoGen I2C API with Interrupts.
Sadly I didn't find any examples:
- The TI e2e search feature doesn't show me any results that discuss this topic
- The Official documentation does not contain examples using HalCoGen generated code
- The HalCoGen example folder has 0 mentions of i2cNotification

So I'm turning to this forum :^ )
---
I'm mainly looking for guidance regarding
- How to properly handle STOP in i2cNotification?
- How to properly handle errors in i2cNotification?
- How to properly wait for the bus to be ready before doing other things?
Here's my code right now:
static volatile bool g_rx_done = false;
static volatile bool g_tx_done = false;
int i2c_transmit(i2cBASE_t *base, //
uint8_t slave_address,
size_t data_size,
uint8_t const data[data_size])
{
if (i2cIsMasterReady(base) != true)
{
return -1; //< Busy
}
g_tx_done = false;
i2cSetSlaveAdd(base, slave_address);
i2cSetDirection(base, I2C_TRANSMITTER);
i2cSetMode(base, I2C_MASTER);
i2cSetCount(base, data_size);
i2cSetStop(base);
i2cSetStart(base);
i2cSend(base, data_size, data);
return 0;
}
bool i2c_is_transmit_done(i2cBASE_t *base)
{
return i2cIsMasterReady(base) && g_tx_done; //
}
int i2c_start_receiving(i2cBASE_t *base, //
uint8_t slave_address,
size_t data_size,
uint8_t data[data_size])
{
if (i2cIsMasterReady(base) != true)
{
return -1; //< Busy
}
g_rx_done = false;
i2cSetSlaveAdd(base, slave_address);
i2cSetDirection(base, I2C_RECEIVER);
i2cSetMode(base, I2C_MASTER);
i2cSetCount(base, data_size);
i2cSetStop(base);
i2cSetStart(base);
i2cReceive(base, data_size, data);
return 0;
}
bool i2c_is_receive_done(i2cBASE_t *base)
{
return i2cIsMasterReady(base) && g_rx_done; //
}
void i2cNotification(i2cBASE_t *base, uint32 flags)
{
if (flags & I2C_SCD_INT) //< Stop condition detect
{
i2cClearSCD(base);
}
if (flags & I2C_TX_INT) //< Transmit data ready
{
g_tx_done = true;
}
if (flags & I2C_RX_INT) //< Receive data ready
{
g_rx_done = true;
}
if (flags & I2C_AL_INT) //< Arbitration lost (AL)
{
}
if (flags & I2C_NACK_INT) //< No acknowledgement (NACK)
{
}
if (flags & I2C_ARDY_INT) //< Register access ready (ARDY)
{
}
if (flags & I2C_AAS_INT) //< Address as slave (AAS)
{
}
}
Any advice is appreciated.
Regards,
Gabriel
















