2018-04-05 12:12 PM
Hi,
I'm new to the STM32 architecture so I need some help. I am using the STM32L431 mcu and I want to interface the LIS3MDLTR magnetic field sensor through I2C. According to the datasheet, in order to read from the LIS3MDLTR, a repeated start condition needs to be used.
In my application, I am using the Low -Layer (LL) APIs. I used the STM32CubeMX to setup the project and peripherals. I found an example on how to use the I2C LL library to send and receive (by polling) but I couldn't find any help regarding on how to generate a repeated start condition. Does any one now how I can use the LL library functions to set the Master I2C to generate a repeated start condition for read operation?
Note: I can't use the HAL library since I need my code to be more efficient.
2018-04-06 11:49 AM
I'm not 100% sure, because I haven't done it, but I do use LL to transmit with I2C and have looked for examples for write/read using a restart condition to use in the future.
For the normal basic write to a slave you use LL_I2C_HandleTransfer() with LL_I2C_MODE_AUTOEND and LL_I2C_GENERATE_START_WRITE. After sending that you loop waiting for the stop bit, sending your data based on TXIS.
I believe that to do a write/read with a restart that you would first use LL_I2C_HandleTransfer() using LL_I2C_MODE_SOFTEND and LL_I2C_GENERATE_START_WRITE. Then loop until the TC flag is set (transmitting your data based on TXIS). Once you get TC then you would use another LL_I2C_HandleTransfer() using LL_I2C_MODE_AUTOEND and LL_I2C_GENERATE_RESTART_7BIT_READ, looping until a stop, reading the incoming data as it arrives.
I'm just guessing though. But that might be a place for you to start.