How to get started building I2C-based drivers #22
Replies: 1 comment 4 replies
-
Writing drivers for various devices will need a read and write that doesn't send the register address with every transaction. Some devices require more register-pointer management. You can see one example of this in Sparkfun's AS7341X driver. There are others that will require this method. The SHT30 series of temperature/humidity sensors is one, they don't make use of registers, as can be seen here. It accepts 16 bit commands then a request will send the measurements The AS7341X device requires a If I'm following the code correctly, it appears that passing a -1 for the register address skips sending it, however at another point in the code, it will throw an exception when it sees -1. |
Beta Was this translation helpful? Give feedback.
-
Get started building an I2C-based driver
To show how to get started building drivers for I2C-connected peripherals, let's build a driver for the SparkFun Qwiic Joystick. We connect the joystick to the ESP32 with a Qwiic cable and a simple I2C setup — here using pin 21 for SDA (blue) and pin 22 for SCL (yellow).
The datasheet for the joystick shows the important registers like the default address and the button position:
The code required to start interacting with the SparkFun Joystick is less than 30 lines of Toit code:
You can read more about the driver and how to expand it do deal with more of the joystick functionality in here.
Beta Was this translation helpful? Give feedback.
All reactions