Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
Black
Level 1
Level 1
Welcome!
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)



5064.attach
0 Likes
6 Replies
MoD
Employee
Employee
10 likes given 50 likes received 500 replies posted
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).
0 Likes
Markus4711
Level 3
Level 3
First like received 10 questions asked 10 sign-ins
Hi,

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
Markus
0 Likes
Black
Level 1
Level 1
Welcome!
This issued is solved. Thanks.
Anyone can mail me private message if you need the modified snippet code.
0 Likes
ramzi
Level 1
Level 1
10 sign-ins 5 sign-ins First reply posted

i need this modifications

 

0 Likes
Shafi96
Level 3
Level 3
50 sign-ins First solution authored 25 replies posted

Hi,

Can I have the modified snippet code please?

Thanks in advance.

Regards,

Shafi.

0 Likes

Hi Black,

Can I have the modified snippet code please?

Thanks in advance.

0 Likes