Difference between revisions of "Component: I2C Master (Comms: Interface)"
Line 162: | Line 162: | ||
[[File:Sniffer_I2C_backpack_address.png]] | [[File:Sniffer_I2C_backpack_address.png]] | ||
− | The other two Addresses i.e. 0x56 [86] and 0x68 [104] is for | + | The other two Addresses i.e. 0x56 [86] and 0x68 [104] is for other connected devices, 24C32 EEPROM and DS3231 RTC respectively. |
Note The I2c addresses scan will repeat every 5seconds. | Note The I2c addresses scan will repeat every 5seconds. | ||
− | The sniffer will send data to your PC via UART to USB | + | The sniffer will send data to your PC via UART to USB which the Arduino range and clones have built-in. |
==Downloadable macro reference== | ==Downloadable macro reference== |
Revision as of 15:21, 18 January 2023
Author | Matrix Ltd. |
Version | 1.4 |
Category | Comms: Interface |
Contents
I2C Master component
Generic Two Wire I2C Communications Interface
Component Source Code
Please click here for the component source code: FC_Comp_Source_I2C_Master.fcfx
Detailed description
Overview
The I2C bus is a medium speed communications bus which is usually best suited for talking between devices situated on the same circuit board. Due to the high frequency digital nature of the bus care should be taken to keep tracks as short as possible and as far away as possible from other sources of noise. A typical I2C bus consists of two signals, data and clock. The I2C bus usually consists of a single master device and then one or more slave devices. The master device initiates all the communications and can only communicate with a single device on the bus at a time by sending a unique device address as the first byte.
Each I2C transaction consists of a start and a stop as well as one or more data bytes made up of 8 clock cycles allowing the 8-bits of each byte to be transferred. Each byte send is followed by an Ack (acknowledged) or a Nak (not acknowledged) from the receiving device.
Pull up resistors
The I2C bus usually requires pull up resistors in the range of 4.7K to 10K between the two I2C signals and VCC. Some I2C devices have the pull up resistors built in so as to avoid external components.
The pull up resistors can be useful when interfacing a 5V microcontroller to a 3V3 sensor as the pull up resistor can be connected to 3V3 to eliminate the need for voltage level shifting.
Start / Restart / Stop
The Start, Restart and Stop operations are each states which the bus can be put into using the I2C specification.
Generic Write Transaction
A generic write transaction to a memory device might look something like this:
Start
Send External Device Address Byte (Write mode)
Send Internal Address Byte
Send Data Byte
Stop
Generic Read Transaction
A generic read transaction to a memory device might look something like this:
Start
Send External Device Address Byte (Write mode)
Send Internal Address Byte
Restart
Send External Device Address Byte (Read mode)
Read Data Byte
Stop
Examples
More information on I2C can be found here,
Matrix Flowcode Blog: Simplified communications I2C and SPI
Generic I2C EEPROM
Example file demonstrating how to read and write bytes from a generic I2C EEPROM device.
I2CEEPROM
Simulated I2C devices
This example uses the I2C master component combined with the DS1307 injector to simulate an I2C communications bus between the target Microcontroller and the virtual DS1307 device.
I2C DS1307 Example
The panel displays the current time from the DS1307 RAM which is populated to match the system time.
The I2C console shows the communications between the target microcontroller and simulated I2C device.
The DS1307 console shows the contents of RAM memory on the simulated I2C device.
I2C Transaction Mode
Transction mode can be used on all target devices.
If not using transaction mode then your code won't work on ARM or ESP.
With transaction mode there are fewer component macros required than Non-transaction read/write mode.
Example file demonstrating how I2C transaction component macros can be used to write and read to the minutes register of DS1307/DS3231 RTC.
If simulation Mode within properties is set to Yes, then the minutes are read from your PC time via a dll.
You can expand using the dll to retrieve the whole date and time.
I2C Address Scanner
Using an Arduino Uno I2C addresses can be determined by using an
IC2 Address Sniffer
The I2C address to use is the one within the first set of square brackets.
For example, with my backpack display, the correct address to use is 0x3F [63]:
The other two Addresses i.e. 0x56 [86] and 0x68 [104] is for other connected devices, 24C32 EEPROM and DS3231 RTC respectively.
Note The I2c addresses scan will repeat every 5seconds.
The sniffer will send data to your PC via UART to USB which the Arduino range and clones have built-in.
Downloadable macro reference
![]() |
ReceiveByte |
Receives a byte from the I²C bus. | |
![]() |
Last |
Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte | |
![]() |
Return |
![]() |
Restart |
Outputs a restart condition onto the I²C bus. | |
![]() |
Return |
![]() |
Stop |
Outputs a stop condition onto the I²C bus. | |
![]() |
Return |
![]() |
Transaction_Uninit |
Uninitialise the I2C interface | |
![]() |
Return |
![]() |
Start |
Outputs a start condition onto the I²C bus. | |
![]() |
Return |
![]() |
Initialise |
Enables the I²C hardware and performs some initialization. Should be called at the start of the program or at least before any of the other I²C functions are called. | |
![]() |
Return |