Getting Started with I2C
Jump to navigation
Jump to search
Agenda
What we are going to talk about:
- I2C
- DS3231 Real Time Clock (RTC)
- AT24C32 32Kbit EEPROM (4096 bytes)
- TM1637 7-segment LED driver (decimal points or colon)
- Logic8 / Logic16 logic analyzer
Begin by watching the following "Understanding I2C" video: https://www.youtube.com/watch?v=CAvawEcxoPU 1) What is I2C - The bus hardware 2) START and STOP conditions (These are NOT bits) 3) I2C Address and the R /W bit - (7 or 8 bit I2C address ?) 4) Acknowledge bit (receiver of data provides acknowledge) 5) What isn't I2C? Examine the TM1637 5) Examine the DS3231, write and read it's registers 6) Examine the AT24C32, write and read data
Example I2C bus with a master and three slaves
Notes: 1) Bus signals are 'Open Collector / Open Drain' (Devices can only pull a signal low) 2) The Master always drives SCL. Exception: clock stretching 3) Both Master AND Slaves drive SDA. 4) For a 100KHz I2C bus speed, pull-ups (Rp), are usually around 4.7K ohms. The values chosen for pull-ups are a balance between trace capacitance and the current necessary for each device to pull a signal low.
Example - Detail of a 'write byte'
Notes: 1) Master sends START 2) Master sends device address (0x64) with Read/Write bit low (WRITE) 3) Device responds with ACK 4) Master sends data byte 5) Device responds with ACK 6) Master sends STOP
DS3231 Module
DS3231
The time (and temperature), are accessed via 19 byte-wide registers, see Address Map on page 11. https://www.analog.com/media/en/technical-documentation/data-sheets/ds3231.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ds3231m.pdf (The 'M' variant)
Reading DS3231 control register (0x0E)
AT24C32
This 32Kbit EEPROM (4096 x 8), will hold 4096 bytes of data. https://ww1.microchip.com/downloads/en/DeviceDoc/doc0336.pdf
Writing 16 bytes using page write
Following a write, polling the device, waiting for ACK to signal device is ready'
TM1637
Multiple 7-segment LED display driver / keypad scanner https://www.aliexpress.us/item/3256801873805909.html (decimal points) https://www.aliexpress.us/item/3256801704898010.html (decimal points) https://www.aliexpress.us/item/3256801873036951.html (colon)
Waveforms captured during a clock update
The Software
Arduino Example: https://github.com/JimMerkle/Arduino_Uno_Command_Line_I2C_DS3231_TM1637 NUCLEO-F103RB Example: https://github.com/JimMerkle/NUCLEO-F103RB_TM1637_DS3231_Clock
References
https://www.analog.com/en/resources/technical-articles/i2c-primer-what-is-i2c-part-1.html https://www.ti.com/lit/an/sbaa565/sbaa565.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ds3231.pdf https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf