Skip to content

Latest commit

 

History

History
40 lines (23 loc) · 1.29 KB

File metadata and controls

40 lines (23 loc) · 1.29 KB

Inter-Integrated Circuit (I2C) HAL

The usage of hal_i2c driver is self documented in hal_i2c.h header file. Please refer to it for details.

Typically, you need to work with the following functions:

int8_t i2cTransmit(uint8_t id, const uint8_t tx[], uint8_t len);
int8_t i2cReceive(uint8_t id, uint8_t* rx, uint8_t len);

stm32 usage

If you want to use stm32 platform, you should specify LIBPERIPH_PLATFORM=stm32.

It is expected to configure the periphery in STM32CubeMX.

You should enable i2c as shown below:

drawing

Ubuntu usage

If you want to use Ubuntu platform, you should specify LIBPERIPH_PLATFORM=ubuntu.

Ubuntu platform might used either for unit tests or for SITL mode.

For unit tests example based on Ubuntu implementation please check tests/periphery/test_i2c.cpp.

In SITL mode you should implement your own version of ubuntu_i2c_id and ubuntu_i2c_buffer array:

uint8_t ubuntu_i2c_id = 42;
uint8_t ubuntu_i2c_buffer[256] = {};

By default, these variables have a weak attributes.

So, you can change the values of I2C in real time to emulate the real I2C in a way you want.