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

From Flowcode Help
Jump to navigationJump to search
(XML import)
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==
 +
Generic Two Wire I2C Communications Interface
  
==[[File:Component Icon eac43fda_0bc5_4b08_881c_6d3e364f2eff.png|Image]] I2C Slave component==
+
==Detailed description==
Generic Two Wire I2C Communications Interface
+
 
 +
''No detailed description exists yet for this component''
  
 
==Examples==
 
==Examples==
 +
 +
 
===PIC16F1937 Examples===
 
===PIC16F1937 Examples===
  
Line 42: Line 45:
 
==Downloadable macro reference==
 
==Downloadable macro reference==
  
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
Receives a byte from the I²C bus.
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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''
 +
|}
  
Returns the data received, and sends either Ack or Nak
 
  
Set parameter Last as: 1=Last=Nak, 0=Ack=More
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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''
 +
|}
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Last''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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''
 +
|}
  
  
'''Return value'''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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''
 +
|}
  
:[[Variable Types|BYTE]]
 
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 +
|-
 +
| colspan="2" | Startup the I2C bus ready for communications.&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><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.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Read'''
 +
|-
 +
| colspan="2" | Attempt to read Length number of bytes from the I2C slave to the given Buffer. Ensure that the Buffer is large enough.  Returns number of bytes read, caller should check that this matches requested Length&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Buffer
 +
|-
 +
| colspan="2" | Buffer to store the incoming byte data&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | Length
 +
|-
 +
| colspan="2" | Number of bytes to read&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Data''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::Data byte to send on the I²C bus.
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Start'''
 +
|-
 +
| colspan="2" | Outputs a start condition onto the I²C bus.&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''
 +
|}
  
  
'''Return value'''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Initialise'''
 +
|-
 +
| colspan="2" | Initialise the I2C interface to communicate with a Slave device at Address Returns 0 on fail, 1 on success&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Address
 +
|-
 +
| colspan="2" | 7-bit I2C Address without the shift for the R/W bit&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''
 +
|}
  
:[[Variable Types|BYTE]]
 
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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><tt>Check_Status</tt></u></span>===
 
Returns the Slave Status.
 
  
Bit 0 = 1 Indicates address/data byte available in the buffer to read
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 +
|-
 +
| colspan="2" | Initialise the sensor configuration as set by the component properties. Sets the default intigration time and gain as well as enable the sensor.&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''
 +
|}
  
Bit 5 = 1 Indicates that the last byte received or transmitted was data (else address)
 
  
'''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''
 
 
 
'''Return value'''
 
 
:''This call does not return a value''
 
 
 
 
==Simulation macro reference==
 
 
''This component does not contain any simulation macros''
 
  
  
 
==Property reference==
 
==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 ''cal_i2c::CHANNEL''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
Channel selection
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
<span style="font-weight: normal;"><u>Baud Select</u></span>
+
|-
 
+
|-
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" | [[File:Fc9-type-16-icon.png]]
 
+
| width="90%" | Channel
Baud rate option selector
+
|-
 
+
| colspan="2" | Channel selection&nbsp;
<span style="font-weight: normal;"><u>Baud Rate</u></span>
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
This property is of type ''Signed integer'' and can be referenced with the variable name ''cal_i2c::BAUD''.
+
| width="90%" | Baud Select
 
+
|-
Baud rate to be used
+
| colspan="2" | Baud rate option selector&nbsp;
 
+
|-
<span style="font-weight: normal;"><u>Stop Delay</u></span>
+
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]]
 
+
| width="90%" | Baud Rate
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::StopDel''.
+
|-
 
+
| colspan="2" | Baud rate to be used&nbsp;
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not  
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
a 10ms delay between an I2C stop event and the next I2C start event.
+
| width="90%" | Stop Delay
 
+
|-
 
+
| 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;
 
+
|-
Most modern microcontrollers will not have a problem so this property can be disabled to speed up the  
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
+
| width="90%" | Slave Address
I2C communications.
+
|-
 
+
| colspan="2" | &nbsp;
<span style="font-weight: normal;"><u>Slave Address</u></span>
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Slave_Address''.
+
| width="90%" | Mask
 
+
|-
''<span style="color:red;">No additional information</span>''
+
| 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;
 
+
|-
 
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections'''  
<span style="font-weight: normal;"><u>Mask</u></span>
+
|-
 
+
|-
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Mask''.
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 
+
| width="90%" | SDA
0 - don't care;
+
|-
 
+
| colspan="2" | Pin used for SDA (data signal)&nbsp;
1 - perform match;
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F
+
| width="90%" | SCL
 
+
|-
<span style="font-weight: normal;"><u>SDA</u></span>
+
| colspan="2" | Pin used for SCL (clock signal)&nbsp;
 
+
|-
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SDA''.
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations'''  
Pin used for SDA (data signal)
+
|-
 
+
|-
<span style="font-weight: normal;"><u>SCL</u></span>
+
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]]
 
+
| width="90%" | Label
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SCL''.
+
|-
 
+
| colspan="2" | Label shown on the comms flasher on the simulation panel.&nbsp;
Pin used for SCL (clock signal)
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
<span style="font-weight: normal;"><u>Label</u></span>
+
| width="90%" | Scope Traces
 
+
|-
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
+
| colspan="2" | Selects if the scope traces are automatically generated or not&nbsp;
 
+
|-
Label shown on the comms flasher on the simulation panel.
+
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
 
+
| width="90%" | Console Data
<span style="font-weight: normal;"><u>Scope Traces</u></span>
+
|-
 
+
| colspan="2" | Selects if the console data is automatically generated or not&nbsp;
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ScopeTraces''.
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
Selects if the scope traces are automatically generated or not
+
| width="90%" | API
 
+
|-
<span style="font-weight: normal;"><u>Console Data</u></span>
+
| colspan="2" | &nbsp;
 
+
|}
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ConsoleData''.
 
 
 
Selects if the console data is automatically generated or not
 
 
 
<span style="font-weight: normal;"><u>Injector</u></span>
 
 
 
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_i2c::Injector''.
 
 
 
''<span style="color:red;">No additional information</span>''
 

Revision as of 19:47, 16 November 2021

Author Matrix Ltd.
Version 1.3
Category Comms: Interface


I2C Slave component

Generic Two Wire I2C Communications Interface

Detailed description

No detailed description exists yet for this component

Examples

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. FC6 Icon.png Master Read Example

FC6 Icon.png Slave Switches Example 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. FC6 Icon.png Master Send Example

FC6 Icon.png Slave LEDs Example

Arduino Uno Examples

Example program showing how to use the I2C Slave on an AVR Arduino device. FC6 Icon.png I2C Slave Arduino Uno Example

ECIO40P Examples

Example program showing how to use the I2C Slave on an ECIO40P device. FC6 Icon.png Master Example

FC6 Icon.png Slave Example

Downloadable macro reference

Fc9-comp-macro.png 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 
Fc9-u8-icon.png - BYTE Last
Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png 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. 
Fc9-u8-icon.png - BYTE Data
Data byte to send on the I²C bus. 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png 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) 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png 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. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Initialise
Startup the I2C bus ready for communications. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Transaction_Read
Attempt to read Length number of bytes from the I2C slave to the given Buffer. Ensure that the Buffer is large enough. Returns number of bytes read, caller should check that this matches requested Length 
Fc9-u8-icon.png - BYTE Buffer
Buffer to store the incoming byte data 
Fc9-u16-icon.png - UINT Length
Number of bytes to read 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png Start
Outputs a start condition onto the I²C bus. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Transaction_Initialise
Initialise the I2C interface to communicate with a Slave device at Address Returns 0 on fail, 1 on success 
Fc9-u8-icon.png - BYTE Address
7-bit I2C Address without the shift for the R/W bit 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png 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. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png Initialise
Initialise the sensor configuration as set by the component properties. Sets the default intigration time and gain as well as enable the sensor. 
Fc9-void-icon.png - VOID Return



Property reference

Fc9-prop-icon.png Properties
Fc9-type-16-icon.png Channel
Channel selection 
Fc9-type-16-icon.png Baud Select
Baud rate option selector 
Fc9-type-14-icon.png Baud Rate
Baud rate to be used 
Fc9-type-7-icon.png 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.  
Fc9-type-21-icon.png Slave Address
 
Fc9-type-21-icon.png 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 
Fc9-conn-icon.png Connections
Fc9-type-5-icon.png SDA
Pin used for SDA (data signal) 
Fc9-type-5-icon.png SCL
Pin used for SCL (clock signal) 
Fc9-conn-icon.png Simulations
Fc9-type-10-icon.png Label
Label shown on the comms flasher on the simulation panel. 
Fc9-type-7-icon.png Scope Traces
Selects if the scope traces are automatically generated or not 
Fc9-type-7-icon.png Console Data
Selects if the console data is automatically generated or not 
Fc9-type-16-icon.png API