Jump to content

Component: I2C Slave (Comms: Interface): Difference between revisions

From Flowcode Help
XML import BR
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(23 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{| style="width:50%"
 
{| width="50%"
|-
|-
| width="20%" style="color: gray;" | Author
| width="20%" style="color:gray;" | Author
| Matrix Ltd.
| Matrix Ltd.
|-
|-
| width="20%" style="color: gray;" | Version
| width="20%" style="color:gray;" | Version
| 1.2 (Release)
| 1.3
|-
|-
| width="20%" style="color: gray;" | Category
| width="20%" style="color:gray;" | Category
| Comms: Interface
| Comms: Interface
|}
|}




 
==I2C Slave component==
==[[File:Component Icon eac43fda_0bc5_4b08_881c_6d3e364f2eff.png|Image]] I2C Slave component==
Generic Two Wire I2C Communications Interface
Generic Two Wire I2C Communications Interface


==Examples==
==Component Source Code==
===PIC16F1937 Examples===


The slave device is connected to a bank of switches, the master device to a bank of LEDs. The value of the switches is passed to the master LEDs.
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_I2C_Slave.fcfx FC_Comp_Source_I2C_Slave.fcfx]
{{Fcfile|1. I2C Master Read.fcfx|Master Read Example}}


{{Fcfile|1. I2C Slave switches.fcfx|Slave Switches Example}}
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_I2C_Slave.fcfx FC_Comp_Source_I2C_Slave.fcfx]
The slave device is connected to a bank of LEDs, the master device to a bank of switches. The value of the switches is passed to the slave LEDs.
{{Fcfile|2. I2C Master Switches.fcfx|Master Send Example}}


{{Fcfile|2. I2C Slave LEDs.fcfx|Slave LEDs Example}}
==Detailed description==
===Arduino Uno Examples===


Example program showing how to use the I2C Slave on an AVR Arduino device.
{{Fcfile|I2C Uno slave.fcfx|I2C Slave Arduino Uno Example}}
===ECIO40P Examples===


Example program showing how to use the I2C Slave on an ECIO40P device.
{{Fcfile|ECIO40P_I2C_Master.fcfx|Master Example}}


{{Fcfile|ECIO40P_I2C_Slave.fcfx|Slave Example}}


==Downloadable macro reference==


===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
Receives a byte from the I²C bus.


'''Parameters'''


:[[Variable Types|BYTE]] ''Last''
::Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte




'''Return value'''


:[[Variable Types|BYTE]]




===<span style="font-weight: normal;"><u><tt>TransmitByte</tt></u></span>===
Sends a byte on the I²C bus. Returns the acknowledge if any.


0 represents that data was acknowledged and 1 represents no acknowledge was detected.


'''Parameters'''


:[[Variable Types|BYTE]] ''Data''
::Data byte to send on the I²C bus.




'''Return value'''


:[[Variable Types|BYTE]]




===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
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.


'''Parameters'''


:''This macro has no parameters''
''No detailed description exists yet for this component''


==Examples==


'''Return value'''


:''This call does not return a value''






==Simulation macro reference==


''This component does not contain any simulation macros''




==Property reference==
<span style="font-weight: normal;"><u>Channel</u></span>


This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''CHANNEL''.


Specifies the I2C peripheral used by the component.


Hardware channels are defined by the number of I2C peripherals available onboard your target microcontroller.
''<span style="color:red;">No additional examples</span>''


Software channels use standard I/O pins allowing you to connect the I2C bus to pretty much any pin.
==Macro reference==


<span style="font-weight: normal;"><u>Baud Select</u></span>
===Check_Status===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''Check_Status'''
|-
| colspan="2" | Returns the Slave Status. Bit 0 = 1 Indicates address/data byte available in the buffer to read Bit 5 = 1 Indicates that the last byte received or transmitted was data (else address)&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}


This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''BAUD_LIST''.


Sets the rate of the I2C clock which sets the maximum number of bits per second that can be sent or received.
===Initialise===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''Initialise'''
|-
| colspan="2" | 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.&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}


<span style="font-weight: normal;"><u>Slew Rate Control</u></span>


This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''SRC''.
===ReceiveByte===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''ReceiveByte'''
|-
| colspan="2" | Receives a byte from the I²C bus. Returns the data received, and sends either Ack or Nak Set parameter Last as: 1=Last=Nak, 0=Ack=More&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Last
|-
| colspan="2" | Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}


The slew rate control only works with hardware I2C channels but acts to modify the overall baud to ensure


that signals are being transferred correctly based on how fast the control signals are able to rise and fall.
===TransmitByte===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''TransmitByte'''
|-
| colspan="2" | Sends a byte on the I²C bus. Returns the acknowledge if any.  0 represents that data was acknowledged and 1 represents no acknowledge was detected.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
| colspan="2" | Data byte to send on the I²C bus.&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}


<span style="font-weight: normal;"><u>SMBus Inputs</u></span>


This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''SMB''.
==Property reference==


The SMBus Inputs only works with hardware I2C channels but acts to modify the I2C driver to be compatible with SM Bus.
{| class="mtx-class-macrotable wikitable"
 
|-
<span style="font-weight: normal;"><u>Data (SDA)</u></span>
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
 
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''SDA''.
|-
 
|-
I2C data pin commonly referred to as SDA which represents serial data
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Bus Settings
<span style="font-weight: normal;"><u>Clock (SCL)</u></span>
|-
 
|-
This property is of type ''Single digital pin'' and can be referenced with the variable name ''SCL''.
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
| width="90%" | Channel
I2C clock pin commonly referred to as SCL which represents serial clock
|-
 
| colspan="2" | Channel selection&nbsp;
<span style="font-weight: normal;"><u>Label</u></span>
|-
 
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
| width="90%" | Baud Select
 
|-
Label shown on the comms flasher on the simulation panel.
| colspan="2" | Baud rate option selector&nbsp;
 
|-
<span style="font-weight: normal;"><u>Injector</u></span>
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]]
 
| width="90%" | Baud Rate
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''Injector''.
|-
 
| colspan="2" | Baud rate to be used&nbsp;
Lists all the available injector components on the panel to allow the I2C data to have meaning.
|-
 
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
Injectors are available to let you directly type in values, simulate devices and communicate between multiple instances of Flowcode.
| width="90%" | Stop Delay
 
|-
<span style="font-weight: normal;"><u>Slave Address</u></span>
| colspan="2" | On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not  a 10ms delay between an I2C stop event and the next I2C start event.  Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications. &nbsp;
 
|-
This property is of type ''Signed integer'' and can be referenced with the variable name ''Slave_Address''.
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Slave Setttings
''<span style="color:red;">No additional information</span>''
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
| width="90%" | Slave Address
<span style="font-weight: normal;"><u>Mask</u></span>
|-
 
| colspan="2" | &nbsp;
This property is of type ''Signed integer'' and can be referenced with the variable name ''Mask''.
|-
 
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
0 - don't care;
| width="90%" | Mask
 
|-
1 - perform match;
| colspan="2" | 0 - don't care; 1 - perform match; So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F&nbsp;
 
|-
So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" class="mtx-class-propfolder" | Connections
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | SDA
|-
| colspan="2" | Pin used for SDA (data signal)&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | SCL
|-
| colspan="2" | Pin used for SCL (clock signal)&nbsp;
|-
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" class="mtx-class-propfolder" | Simulation
|-
|-
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]]
| width="90%" | Label
|-
| colspan="2" | Label shown on the comms flasher on the simulation panel.&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" | Scope Traces
|-
| colspan="2" | Selects if the scope traces are automatically generated or not&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" | Console Data
|-
| colspan="2" | Selects if the console data is automatically generated or not&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | API
|-
| colspan="2" | &nbsp;
|}

Latest revision as of 14:37, 13 July 2026

Author Matrix Ltd.
Version 1.3
Category Comms: Interface


I2C Slave component

Generic Two Wire I2C Communications Interface

Component Source Code

Please click here to download the component source project: FC_Comp_Source_I2C_Slave.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_I2C_Slave.fcfx

Detailed description

No detailed description exists yet for this component

Examples

No additional examples

Macro reference

Check_Status

Check_Status
Returns the Slave Status. Bit 0 = 1 Indicates address/data byte available in the buffer to read Bit 5 = 1 Indicates that the last byte received or transmitted was data (else address) 
- BYTE Return


Initialise

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. 
- VOID Return


ReceiveByte

ReceiveByte
Receives a byte from the I²C bus. Returns the data received, and sends either Ack or Nak Set parameter Last as: 1=Last=Nak, 0=Ack=More 
- BYTE Last
Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte 
- BYTE Return


TransmitByte

TransmitByte
Sends a byte on the I²C bus. Returns the acknowledge if any. 0 represents that data was acknowledged and 1 represents no acknowledge was detected. 
- BYTE Data
Data byte to send on the I²C bus. 
- BYTE Return


Property reference

Properties
Bus Settings
Channel
Channel selection 
Baud Select
Baud rate option selector 
Baud Rate
Baud rate to be used 
Stop Delay
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not a 10ms delay between an I2C stop event and the next I2C start event. Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications.  
Slave Setttings
Slave Address
 
Mask
0 - don't care; 1 - perform match; So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F 
Connections
SDA
Pin used for SDA (data signal) 
SCL
Pin used for SCL (clock signal) 
Simulation
Label
Label shown on the comms flasher on the simulation panel. 
Scope Traces
Selects if the scope traces are automatically generated or not 
Console Data
Selects if the console data is automatically generated or not 
API