Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

AURIX™ Forum Discussions

Level 1
Level 1
I develop the project program on the TC377 EVK platform and encounter a I2C issue---failed to read a register value.

I tried to read a register value of I2C device(pressure sensor based on the I2C bus transmission signals(refer to attachment) described by the sensor datasheet.

Could anyone show me how to generate the repeated start signal or provide the sample code. Thanks

//iLLD Libraries used by program
uint8 i2cTxBuffer[1] = {WHO_AM_I_REG};//WHO_AM_I_REG: register address
uint8 i2cRxBuffer[1]

/* Write data to device */
while(IfxI2c_I2c_write(&g_i2cDevPressure, &i2cTxBuffer[0], 1) == IfxI2c_I2c_Status_nak)
/* Read the data*/
while(IfxI2c_I2c_read(&g_i2cDevPressure, &i2cRxBuffer[0], 1) == IfxI2c_I2c_Status_nak)

3 Replies
250 sign-ins 25 likes received 50 solutions authored
Function IfxI2c_I2c_write will always release the bus if finished. Therefore a stop condition is always placed on the bus after write. You must write your own write function which don't release the bus and will stay in Master Restart State (see State Machine in UM).
Level 1
Level 1
5 questions asked Welcome! 5 replies posted

I had the same challenge just a few weeks ago. Because of the low-speed behaviour of the I²C compared to the µC (TC375 in my case) I had the need to include DMA transfer also to avoid the polling on interrupt/protocol flags.
I have to say it was beyond the complexity I usually face in using the I²C because of the 'one way' behaviour of the I²C FIFO and the versatile but also complex I²C state machine of the TC3xx (I guess TC2xx is the same). This
state machine is really very detailed but is not supporting too much 'automatic standard transfer modes'. Anyway I did it the following way:

1. Init the I²C module concerning speed, pins, ... . I took most of it from the standard example. Maybe you need to adjust the value for the pad-driver. I usually switch to one of the '1' speed grades
2. Init a DMA transfer from your FIFO to the TXD register of the I²C
3. Configure the I²C registers for device address and protocol interrupts.
4. Set the number of bytes to be transferred. At that point in time the DMA transfer will start
5. In the interrupt service routine (that will be executed after all the configured bytes have been transmitted) clear all protocol flags and set the restart condition (in the endctrl reg as far as I remember).
Also set the transmit of the device address (I did again by using DMA). You also have to remember that you have been in this state (I did with a static local variable). The reason for this is that there is only one I²C protocol interrupt. So with the next interrupt
you have to remember that you already has been there.
6. After the retransmit of the device address is finished you have to change the DMA channel to read from RXD and copy to your desired memory address. Also you have to set the number of bytes to be received. Again, set the I²C protocol
Interrupt to get the signal after the last data has been received
7. In this interrupt call you have to set the stop condition. I allowed one more time to raise an interrupt.
8. In the final interrupt call I reset the above mentioned static variable to the begin of the sequence (point 5.) and also reset the DMA configuration to 'transmit' direction.

Hope that helps for a start point.

Best Regards
Level 1
Level 1
This issued is solved. Thanks.
Anyone can mail me private message if you need the modified snippet code.