This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL2-570LC43: Help needed in understanding how the I2C module works & additional question regarding Hercules development

Part Number: LAUNCHXL2-570LC43
Other Parts Discussed in Thread: HALCOGEN, TMS570LC4357

Hi all,

This is my first post here in the community so I'd like to thank in advance and welcome everyone is wishing to help me!

I'm a beginner in both MCU programming (I did a bit of Arduino and some Micropython in the past) and in TI ARM related stuff. 

At the moment, I'm trying to interface my Hercules LauchPad with some I2C sensors I have lying around in order to get some data out of it. My more ample target is to create a FreeRTOS platform on top of the Launchpad for data acquisition, processing and vehicle control inside a distributed control system of a Formula car which communicates using the FlexRay protocol (hence the choice of a LaunchPad TMS570LC43 board for this project). 

I think I read almost every bit of documentation I found online, but I'm struggling to understand how the I2C module works on this board. 

I've already setup everything in Halcogen and my project builds and compiles the way it should, the problem is that I'm not able to understand how to use the module in order to communicate with my sensor. 

The sensor is a LSM9DSO from ST which expects a communication cycle to be like that:

Master    ST        SAD + W           SUB         DATA SP
Slave           SAK                 SAK          SAK

Being:

ST -> Start, SAD -> Slave Address, SAK -> Slave Ack, SUB -> Register Subaddress, SP -> Stop Bit

At the moment this is the code I use for sending 3 bytes of data (Slave Address in Write mode, Slave Register, Data):

// Set i2cREG1 as Master
i2cSetMode(i2cREG1, I2C_MASTER);

// Set i2cREG1 as Transmitting device
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
// Set slaveAddress in i2c1Reg
//i2cSetSlaveAdd(i2cREG1, slaveAddress);
i2cSetCount(i2cREG1, 3);
* Master to Slave data send:
*
* 1. Send Start
* 2. Send Slave address in Write Mode (last bit low)
* 3. Send Slave Register to write
* 4. Send Slave Register content to write
* 5. Send Stop Bit
*/
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, slaveAddress);
i2cSendByte(i2cREG1, deviceRegister);
i2cSendByte(i2cREG1, dataByte);

/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);

/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);

The code compiles and when I start the debugging session nothing happens because the program is stuck in this infinite loop inside the i2cSendByte function which can be found of the Halcogen generated file HL_i2c.c

 while ((i2c->STR & (uint32)I2C_TX_INT) == 0U) 

This probably means that the module is not able to send those data on the bus, but I don't know why, since the sensor is properly attached and tested to be working in another board. 

I don't know how to properly inspect this problem, since I don't have any I2Cbus analyzer or tools like those. 

But the main problem I spot is the lack of proper programming documentation in order to get those modules up and running. Since drivers need to be made and there's not a simple and enough high level API for accessing such devices, I don't know why there isn't any programming guide, reference or document highlighting how to use MCU modules, like I2C, SPI, FlexRay and others. 

And by that I'm NOT saying that I need an example covering my particular need, instead it would be more more than useful to have these procedures documented such that you are able to understand how to properly communicate with every device provided its protocol. 

This is to say that would be enough to explain what does the i2cSetCount, i2cSendBytes, i2c Interrupt register do, or how to send a byte and wait an ACK from the device, or how does the i2cRepeat mode works.

So, if you could be gentle and kind enough to shed some light on how to do those kind of things, or at least provide an explanation on the working principle and how to develop sensor communication using I2C on the TMS570, that would be really appreciated.

Thank you for the help and disposal,

Best,

Giacomo

  • Hello Giacomo,

    The programmers guide is the TRM (SPNU563)  for the device, which is available on the product page for the TMS570LC4357 device and which I assume you have read based on your comments. The chapter on I2C covers the detailed operation of the module although it is not intended as an instruction manual for I2C as a protocol. I2C is a standard protocol originally developed by Philips corporation and for which there are public white papers, text books, and other such materials to learn the in and out of the principles behind it.

    With that said, as you are a beginner, the best practice would be to attempt to setup a simple loopback application that simply will send and receive data from the same device where one instantiation of the I2C is the master and the other the slave. This approach removes the added complication of the sensor communication that is often a "black box" and requires more detailed analysis using a scope or protocol analyzer.

    Also to facilitate learning and becoming familiar with the I2C module and writing programs on the Hercules device, there are several I2C examples included with the Halcogen tool.The picture below is showing the help content included in the Halcogen tool where each of these examples can be selected and then step by step instructions are included to generate the examples in Halcogen. Also note that source for each example is also included in an examples directory located at C:\ti\Hercules\HALCoGen\v04.07.00\examples\TMS570LC43x provided you installed to the default directory path.

    Hopefully these examples and information within HalCoGen can help get you started. For sure, we are here to help as much as we can along the way. You may also be interested in having a look at some general information on the I2C protocol located at these links:

    http://www.ti.com/lit/an/slva704/slva704.pdf

    https://www.i2c-bus.org/

    http://www.esacademy.com/en/library/technical-articles-and-documents/miscellaneous/i2c-bus/general-introduction/i2c-bus-protocol.html:%C2%A0