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