Concept check for chapter 8 of the Discovery Book

Hi, I'm new to embedded development and I'm currently following the Discovery book using a microbit v2 board. I've gone through chapter 8, which is on I2C and, in particular, I have followed the examples that describe how to use I2C to communicate with the accelerometer in the LSM303AGR component of the board.

I think I have understood what's happening, but since there's a lot going on (from my perspective) I wanted to check whether I'm getting things right. What I believe I'm doing in this chapter is the following:

  • The microbit board has a component that can "speak" I2C called TWI. This component can be used through the twi module from the microbit BSP/BSP. This module provides an abstraction layer over I2C so I don't have to tell the TWI when and how to change the voltage of the wires, but I can instead give it the address of a node and simply tell it to write a message. I use this module to send messages to the LSM303AGR through I2C.

  • On the section 8.4, I instead use a driver for the LSM303AGR component. This driver already knows the addresses of the sensors and how they will send the information, all it needs is a I2C communication "object" to be able to communicate with the LSM303AGR. So what I do is pass the I2C struct that I got from the twi module to the driver and I can get the data from the sensor directly, without having to worry about the addresses, or establishing the I2C communication, since this is all done by the driver.

  • The reason that the I2C stuct that I got from the twi module is compatible with the driver for the LSM303AGR is because they both follow embedded hal, which provides a specification of how drivers and components should look like and what traits they should implement, including how to implement a I2C struct.

Can you tell me if I'm getting the fundamentals right? I haven't work with embedded software before and at some points is hard to have a clear idea of how everything fits together.

Hi Videbar,

I think you understood that correctly. One minor detail:
both I2C and TWI are communication protocols. In many practical cases, both protocols are compatible. So a device that "speaks" TWI (e.g. the micro:bit, Arduino) can exchange information with another device (e.g. a sensor, another microcontroller) that speaks I2C. The TWI module you mention is a lower level hardware abstraction than the driver. Have fun!

Cheers,

Awesome, thanks a lot for the feedback!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.