How to use I2C

Discussion to talk about software related topics only.
Post Reply
fredy-gutierrez
Posts: 12
Joined: Fri Dec 11, 2020 8:27 am

How to use I2C

Post by fredy-gutierrez »

Hi everyone,

I'm working on my MODM7AE70 I want to use I2C to implement a temperature and humidity sensor(Adafruit_AM2320), But I am very new to using I2C, I looked at the Netburner examples to better understand the use of I2C, but I only got confused, has someone implemented this or has experience with the use of I2C? or have you implemented the sensor? I would greatly appreciate your help or any example you can provide.

kind regards
Fredy

Sensor Image
adafruit_products_3721_iso_ORIG_2018_03.jpg
adafruit_products_3721_iso_ORIG_2018_03.jpg (268.55 KiB) Viewed 4388 times
User avatar
Jon
Posts: 79
Joined: Mon Feb 05, 2018 10:54 am

Re: How to use I2C

Post by Jon »

Hi Fredy,

If you're looking to get more information on the basics of I2C, I'd suggest taking a look at an article that we have on the site. It should give you a pretty good rundown on how the protocol behaves in general. There's also additional resources listed there that can get you started if you want to dig in a bit deeper. If you start trying to use the examples and run into any issues, please don't hesitate to let us know. =)

https://www.netburner.com/learn/get-on-the-i2c-bus/

Kind Regards,
Jon
fredy-gutierrez
Posts: 12
Joined: Fri Dec 11, 2020 8:27 am

Re: How to use I2C

Post by fredy-gutierrez »

Hi Jon,
Thanks a lot for your help, I'll look the article which you say because I don't really understand the use of I2C.
Thanks again.
Fredy
jpelletier
Posts: 18
Joined: Wed Dec 23, 2020 3:32 am

Re: How to use I2C

Post by jpelletier »

Jon wrote: Mon Feb 01, 2021 12:05 pm Hi Fredy,

If you're looking to get more information on the basics of I2C, I'd suggest taking a look at an article that we have on the site. It should give you a pretty good rundown on how the protocol behaves in general. There's also additional resources listed there that can get you started if you want to dig in a bit deeper. If you start trying to use the examples and run into any issues, please don't hesitate to let us know. =)

https://www.netburner.com/learn/get-on-the-i2c-bus/

Kind Regards,
Jon
I've read the 'Get on the i2c bus' article, but this doesn't cover the MODM7AE70 API.
I figured that the I2C class is for implementing a master interface, the I2CDevice is for implementing a peripheral device.

The documentation lacks many details about what it does exactly. It only explains what are the parameters.

As an example, for the I2C class, we have this function: writeReg8(uint8_t devAddr, uint32_t reg, uint8_t data)
What exactly is this reg? Does the interface sends these on the I2c bus in order? devAddr, reg, data?
User avatar
TomNB
Posts: 569
Joined: Tue May 10, 2016 8:22 am

Re: How to use I2C

Post by TomNB »

Hello,

The description in the docs is: Write an 8-bit value to an I2C slave device register. This is according to the I2C spec, so it would send a byte to the specified I2C device address. Most I2C device data sheets are controlled by writing to registers, which is a term they use. What the device register is/does is dependent on what it is. For example, the microchip gpio port expander has 11 registers, for things like reading and writing gpio pins.

The tools include examples for 5 I2C devices, so it might help to take a look at that also:

Microchip Pickit Serial I2C Demo Board Driver

Demonstrates the use of 5 Microchip I2C Peripherals:
- 24LC0B EEPROM, 2Kbit (256 x 8)
- MCP9800 Temperature sensor
- MCP23008 GPIO port expander, connected to LEDs
- TC1321 10-bit DAC
- MCP3221 12-bit ADC
jpelletier
Posts: 18
Joined: Wed Dec 23, 2020 3:32 am

Re: How to use I2C

Post by jpelletier »

Thanks! I'll look into that.
Post Reply