Jump to content

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

From Flowcode Help
XML import
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(22 intermediate revisions by 3 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.3 (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.


Returns the data received, and sends either Ack or Nak


Set parameter Last as: 1=Last=Nak, 0=Ack=More


'''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>Check_Status</tt></u></span>===
Returns the Slave Status.


Bit 0 = 1 Indicates address/data byte available in the buffer to read
''No detailed description exists yet for this component''


Bit 5 = 1 Indicates that the last byte received or transmitted was data (else address)
==Examples==


'''Parameters'''


:''This macro has no parameters''




'''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''


''<span style="color:red;">No additional examples</span>''


'''Return value'''
==Macro reference==


:''This call does not return a value''
===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''
|}




===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''
|}


==Simulation macro reference==


''This component does not contain any simulation macros''
===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''
|}




==Property reference==
===TransmitByte===
<span style="font-weight: normal;"><u>Channel</u></span>
{| 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''
|}


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


Channel selection
==Property reference==


<span style="font-weight: normal;"><u>Baud Select</u></span>
{| class="mtx-class-macrotable wikitable"
 
|-
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_i2c::BAUD_LIST''.
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
 
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
Baud rate option selector
|-
 
|-
<span style="font-weight: normal;"><u>Baud Rate</u></span>
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Bus Settings
This property is of type ''Signed integer'' and can be referenced with the variable name ''cal_i2c::BAUD''.
|-
 
|-
Baud rate to be used
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
| width="90%" | Channel
<span style="font-weight: normal;"><u>Stop Delay</u></span>
|-
 
| colspan="2" | Channel selection&nbsp;
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::StopDel''.
|-
 
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not  
| width="90%" | Baud Select
 
|-
a 10ms delay between an I2C stop event and the next I2C start event.
| colspan="2" | Baud rate option selector&nbsp;
 
|-
 
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]]
 
| width="90%" | Baud Rate
Most modern microcontrollers will not have a problem so this property can be disabled to speed up the  
|-
 
| colspan="2" | Baud rate to be used&nbsp;
I2C communications.
|-
 
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
<span style="font-weight: normal;"><u>Slave Address</u></span>
| width="90%" | Stop Delay
 
|-
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Slave_Address''.
| 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;
 
|-
''<span style="color:red;">No additional information</span>''
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Slave Setttings
 
|-
 
|-
<span style="font-weight: normal;"><u>Mask</u></span>
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
| width="90%" | Slave Address
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Mask''.
|-
 
| colspan="2" | &nbsp;
0 - don't care;
|-
 
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
1 - perform match;
| width="90%" | Mask
 
|-
So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F
| 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;
 
|-
<span style="font-weight: normal;"><u>SDA</u></span>
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Connections
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SDA''.
|-
 
|-
Pin used for SDA (data signal)
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 
| width="90%" | SDA
<span style="font-weight: normal;"><u>SCL</u></span>
|-
 
| colspan="2" | Pin used for SDA (data signal)&nbsp;
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SCL''.
|-
 
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
Pin used for SCL (clock signal)
| width="90%" | SCL
 
|-
<span style="font-weight: normal;"><u>Label</u></span>
| colspan="2" | Pin used for SCL (clock signal)&nbsp;
 
|-
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
 
| width="90%" class="mtx-class-propfolder" | Simulation
Label shown on the comms flasher on the simulation panel.
|-
 
|-
<span style="font-weight: normal;"><u>Scope Traces</u></span>
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]]
 
| width="90%" | Label
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ScopeTraces''.
|-
 
| colspan="2" | Label shown on the comms flasher on the simulation panel.&nbsp;
Selects if the scope traces are automatically generated or not
|-
 
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
<span style="font-weight: normal;"><u>Console Data</u></span>
| width="90%" | Scope Traces
 
|-
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ConsoleData''.
| colspan="2" | Selects if the scope traces are automatically generated or not&nbsp;
 
|-
Selects if the console data is automatically generated or not
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
 
| width="90%" | Console Data
<span style="font-weight: normal;"><u>Injector</u></span>
|-
 
| colspan="2" | Selects if the console data is automatically generated or not&nbsp;
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_i2c::Injector''.
|-
 
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
''<span style="color:red;">No additional information</span>''
| 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