Hi all,
I am somewhat confused at the moment. Despite the fact that I have a good knowledge about RTOS and Arduino platform I can't figure out how to use I2C wire library with RTOS/ESP-IDF.
If for example I have bought a sensor which has arduino wire based API and does not have ESP-IDF based I2C API then do I have to write a IDF API using I2C API of ESP-IDF? or I can port a wire based library? If I can use Wire based library what is the need of ESP-IDF I2C API??
https://docs.espressif.com/projects/esp ... s/i2c.html
I2C wire library porting on ESP-IDF
Re: I2C wire library porting on ESP-IDF
I would check datasheet for the sensor. Basically you are interested in sensor's I2C address. Some devices have only one pre-defined address. Some have multiple, which are configurable by the user (switch on the device or different wiring of the sensor itself).
Next, check this example of I2C library usage: https://github.com/espressif/esp-idf/tr ... _self_test
Communication with the sensor is always the same:
Next, check this example of I2C library usage: https://github.com/espressif/esp-idf/tr ... _self_test
Communication with the sensor is always the same:
- Check which ESP's I2C bus is the sensor connected to. As far as I know, there are two of them. You need to know which bus is used later on when setting up the driver.
- Create I2C master on the ESP. This is set via .mode = I2C_MODE_MASTER in i2c_config_t. Configuration structure is then passed to i2c_param_config function.
- Install I2C driver with: i2c_driver_install
- Start communicating with the sensor. Documentation provides nice order of function calls, you have to use either for writing or reading.
-
- Posts: 25
- Joined: Mon Jun 28, 2021 4:55 am
Re: I2C wire library porting on ESP-IDF
If you use Arduino IDE for ESP32, you can use the wire library for I2C devices like you would with any other Arduino project.
If you use ESP-IDF, you will need to write your own code to work according to whatever communication format the I2C device requires you to use (i.e. send addr byte, then read a byte, etc).
The ESP-IDF I2C drivers let you do things like generate an I2C start, send/read a byte, generate ACK/NACK, stop condition, etc.
You have to program the sequence of steps according to your needs.
Check the I2C example sources in IDF examples directory, it is a good place to start.
Also, a good "example" that you can simply build and run on your hardware to talk to the I2C sensor to begin with:
https://github.com/espressif/esp-idf/tr ... /i2c_tools
What sensor is it BTW? Can probably suggest a good place to start if I knew.
If you use ESP-IDF, you will need to write your own code to work according to whatever communication format the I2C device requires you to use (i.e. send addr byte, then read a byte, etc).
The ESP-IDF I2C drivers let you do things like generate an I2C start, send/read a byte, generate ACK/NACK, stop condition, etc.
You have to program the sequence of steps according to your needs.
Check the I2C example sources in IDF examples directory, it is a good place to start.
Also, a good "example" that you can simply build and run on your hardware to talk to the I2C sensor to begin with:
https://github.com/espressif/esp-idf/tr ... /i2c_tools
What sensor is it BTW? Can probably suggest a good place to start if I knew.
Hobbyist and electronic design consultant! (https://PCBArtists.com/)
Re: I2C wire library porting on ESP-IDF
As was asked already, are you using the Arduino framework for ESP32? Then Wire is available. If you are using ESP-IDF there is an option for linking in Arduino libraries.
Re: I2C wire library porting on ESP-IDF
Hi,
Thanks again for your replies.
From the three replies I have got it is clear that my doubt was an obvious one.
Well, I dont want to use Arduino IDE as of now. I am using ESP-IDf. From the first answer it got clear how to use I2C API of ESP-IDF.
From the second and third answers, there is still a confusion. The following sentences do not match exactly. Specially @mbratch told that you can use the wire based library with ESP-IDF by porting it.
Thanks again for your replies.
From the three replies I have got it is clear that my doubt was an obvious one.
Well, I dont want to use Arduino IDE as of now. I am using ESP-IDf. From the first answer it got clear how to use I2C API of ESP-IDF.
From the second and third answers, there is still a confusion. The following sentences do not match exactly. Specially @mbratch told that you can use the wire based library with ESP-IDF by porting it.
mbratch wrote: If you are using ESP-IDF there is an option for linking in Arduino libraries.
By the way I am using current sensor I2C bases INA219.If you use Arduino IDE for ESP32, you can use the wire library for I2C devices like you would with any other Arduino project.
If you use ESP-IDF, you will need to write your own code to work according to whatever communication format the I2C device requires you to use
Re: I2C wire library porting on ESP-IDF
There is existing "library" written for ESP-IDF: https://github.com/UncleRus/esp-idf-lib ... nts/ina219
Re: I2C wire library porting on ESP-IDF
As you can see from what I had said, I did not mention porting at all.
-
- Posts: 25
- Joined: Mon Jun 28, 2021 4:55 am
Re: I2C wire library porting on ESP-IDF
Check this out for ESP-IDF, INA219 and I2C:
https://github.com/pcbreflux/espressif/ ... INA219.cpp
This is a good place to start.
https://github.com/pcbreflux/espressif/ ... INA219.cpp
This is a good place to start.
Hobbyist and electronic design consultant! (https://PCBArtists.com/)
Who is online
Users browsing this forum: No registered users and 164 guests