-
Apr 7th, 2021 09:10 PM
#1
New Member
I2C read issue for TC377
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)
-
Apr 8th, 2021 01:14 AM
#2
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).
The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.
-
Apr 8th, 2021 10:42 PM
#3
Beginner
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
Disclaimer
All content and materials on this site are provided “as is“. Infineon makes no warranties or
representations with regard to this content and these materials of any kind, whether express or
implied, including without limitation, warranties or representations of merchantability, fitness for
a particular purpose, title and non-infringement of any third party intellectual property right. No
license, whether express or implied, is granted by Infineon. Use of the information on this site may
require a license from a third party, or a license from Infineon.
Infineon accepts no liability for the content and materials on this site being accurate, complete or up-
to-date or for the contents of external links. Infineon distances itself expressly from the contents of
the linked pages, over the structure of which Infineon has no control.
Content on this site may contain or be subject to specific guidelines or limitations on use. All postings
and use of the content on this site are subject to the Usage Terms of the site; third parties using
this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of
this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements,
improvements and other changes to the content and materials, its products, programs and services
at any time or to move or discontinue any content, products, programs, or services without notice.
Bookmarks