2022-04-04 02:09 AM
Hi,
I found a tutorial for using a BME280 sensor with I2C in HAL (https://controllerstech.com/bme280-with-stm32/).
However, I need to use LL for it to fit into the rest of the program.
The main part I'm having an issue with is below as I can't find a command within LL that would easily replace it.
HAL_I2C_Mem_Read(BME280_I2C, BME280_ADDRESS, 0x88, 1, trimdata, 25, HAL_MAX_DELAY);
Any help or links to good I2C LL tutorials would be greatly apprecaited.
2022-04-04 04:32 AM
One reason is that it doesn't map to a single LL call.
Take a look at the source-code for HAL_I2C_Mem_Read.
An I2C "memory-read" translates into an I2C write of the memory-location-to-read, followed by an I2C read of the data. And between them, in order to ensure that no other I2C controllers get a look-in and potentially change that memory-location-to-read, the I2C controller issues a "repeated-start" (i.e. i2c start without being preceded by an I2C stop).
Philips (now NXP) were the originators of the I2C protocol - see e.g. the Wikipedia entry for more information.
As to the LL commands, I've had a quick look and they seem to provide function-calls to access the stm32 peripheral registers for I2C. The registers are described in the Reference Manual, including sample code.
If you wish to go deeper than HAL I suggest you start with the section on I2C/SPI in the Reference Manual for your STM32.
Hope this helps,
Danish
2022-04-04 05:01 AM
Hello @Loch and welcome to the STM32 Community :)
You may start from the LL template project in the STM32CubeXX package and check the ready-to-use I2C example related to your device.
I advise you to look at the User Manual "Description of STM32XX HAL and low-layer drivers", it may help you to have more idea about the use of LL functions.
Check this FAQ, which describes few tips related to I2C peripheral on STM32 devices: STM32 I2C does not work, this may help you on your project.
When your question is answered, please close this topic by choosing Select as Best.
Imen
2022-04-04 05:50 AM
Ohh of course the example package. I knew I had seen something somewhere.
Thanks for the other advice too, I'll check it out
2022-04-04 05:51 AM
Thanks for the other advice. I'll have to take a deeper look into how that function actually works.
If only there was a google translate for code.