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

From Flowcode Help
Jump to navigationJump to search
(XML import)
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 1.2 (Release)
+
| 1.3 (Release)
 
|-
 
|-
 
| width="20%" style="color: gray;" | Category
 
| width="20%" style="color: gray;" | Category
Line 19: Line 19:
  
 
==Examples==
 
==Examples==
 
 
===PIC16F1937 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.
 
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.
 
 
{{Fcfile|1. I2C Master Read.fcfx|Master Read Example}}
 
{{Fcfile|1. I2C Master Read.fcfx|Master Read Example}}
  
 
{{Fcfile|1. I2C Slave switches.fcfx|Slave Switches Example}}
 
{{Fcfile|1. I2C Slave switches.fcfx|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.
 
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 Master Switches.fcfx|Master Send Example}}
  
 
{{Fcfile|2. I2C Slave LEDs.fcfx|Slave LEDs Example}}
 
{{Fcfile|2. I2C Slave LEDs.fcfx|Slave LEDs Example}}
 
 
 
===Arduino Uno Examples===
 
===Arduino Uno Examples===
  
 
Example program showing how to use the I2C Slave on an AVR Arduino device.
 
Example program showing how to use the I2C Slave on an AVR Arduino device.
 
 
{{Fcfile|I2C Uno slave.fcfx|I2C Slave Arduino Uno Example}}
 
{{Fcfile|I2C Uno slave.fcfx|I2C Slave Arduino Uno Example}}
 
 
 
===ECIO40P Examples===
 
===ECIO40P Examples===
  
 
Example program showing how to use the I2C Slave on an ECIO40P device.
 
Example program showing how to use the I2C Slave on an ECIO40P device.
 
 
{{Fcfile|ECIO40P_I2C_Master.fcfx|Master Example}}
 
{{Fcfile|ECIO40P_I2C_Master.fcfx|Master Example}}
  
 
{{Fcfile|ECIO40P_I2C_Slave.fcfx|Slave Example}}
 
{{Fcfile|ECIO40P_I2C_Slave.fcfx|Slave Example}}
 
 
  
 
==Downloadable macro reference==
 
==Downloadable macro reference==
Line 57: Line 44:
 
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
 
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
 
Receives a byte from the I²C bus.
 
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'''
 
'''Parameters'''
Line 78: Line 69:
 
:[[Variable Types|BYTE]] ''Data''
 
:[[Variable Types|BYTE]] ''Data''
 
::Data byte to send on the I²C bus.
 
::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
 +
 +
Bit 5 = 1 Indicates that the last byte received or transmitted was data (else address)
 +
 +
'''Parameters'''
 +
 +
:''This macro has no parameters''
  
  
Line 109: Line 117:
 
<span style="font-weight: normal;"><u>Channel</u></span>
 
<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''.
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_i2c::CHANNEL''.
 +
 
 +
Channel selection
 +
 
 +
<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''.
  
Specifies the I2C peripheral used by the component.
+
Baud rate option selector
  
Hardware channels are defined by the number of I2C peripherals available onboard your target microcontroller.
+
<span style="font-weight: normal;"><u>Baud Rate</u></span>
  
Software channels use standard I/O pins allowing you to connect the I2C bus to pretty much any pin.
+
This property is of type ''Signed integer'' and can be referenced with the variable name ''cal_i2c::BAUD''.
  
<span style="font-weight: normal;"><u>Baud Select</u></span>
+
Baud rate to be used
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''BAUD_LIST''.
+
<span style="font-weight: normal;"><u>Stop Delay</u></span>
  
Sets the rate of the I2C clock which sets the maximum number of bits per second that can be sent or received.
+
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::StopDel''.
  
<span style="font-weight: normal;"><u>Slew Rate Control</u></span>
+
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''SRC''.
+
a 10ms delay between an I2C stop event and the next I2C start event.
  
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.
 
  
<span style="font-weight: normal;"><u>SMBus Inputs</u></span>
+
Most modern microcontrollers will not have a problem so this property can be disabled to speed up the
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''SMB''.
+
I2C communications.
  
The SMBus Inputs only works with hardware I2C channels but acts to modify the I2C driver to be compatible with SM Bus.
+
<span style="font-weight: normal;"><u>Slave Address</u></span>
  
<span style="font-weight: normal;"><u>Data (SDA)</u></span>
+
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Slave_Address''.
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''SDA''.
+
''<span style="color:red;">No additional information</span>''
  
I2C data pin commonly referred to as SDA which represents serial data
 
  
<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''.
+
<span style="font-weight: normal;"><u>Mask</u></span>
  
I2C clock pin commonly referred to as SCL which represents serial clock
+
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Mask''.
  
<span style="font-weight: normal;"><u>Label</u></span>
+
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
 +
 
 +
<span style="font-weight: normal;"><u>SDA</u></span>
 +
 
 +
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SDA''.
  
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
+
Pin used for SDA (data signal)
  
Label shown on the comms flasher on the simulation panel.
+
<span style="font-weight: normal;"><u>SCL</u></span>
  
<span style="font-weight: normal;"><u>Injector</u></span>
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_i2c::SCL''.
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''Injector''.
+
Pin used for SCL (clock signal)
  
Lists all the available injector components on the panel to allow the I2C data to have meaning.
+
<span style="font-weight: normal;"><u>Label</u></span>
  
Injectors are available to let you directly type in values, simulate devices and communicate between multiple instances of Flowcode.
+
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
  
<span style="font-weight: normal;"><u>Slave Address</u></span>
+
Label shown on the comms flasher on the simulation panel.
  
This property is of type ''Signed integer'' and can be referenced with the variable name ''Slave_Address''.
+
<span style="font-weight: normal;"><u>Scope Traces</u></span>
  
''<span style="color:red;">No additional information</span>''
+
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ScopeTraces''.
  
 +
Selects if the scope traces are automatically generated or not
  
 +
<span style="font-weight: normal;"><u>Console Data</u></span>
  
<span style="font-weight: normal;"><u>Mask</u></span>
+
This property is of type ''True or false'' and can be referenced with the variable name ''cal_i2c::ConsoleData''.
  
This property is of type ''Signed integer'' and can be referenced with the variable name ''Mask''.
+
Selects if the console data is automatically generated or not
  
0 - don't care;
+
<span style="font-weight: normal;"><u>Injector</u></span>
  
1 - perform match;
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_i2c::Injector''.
  
So address of 0x30 and mask of 0xF0 will allow the slave to respond to addresses of 0x30, 0x31, 0x32, …, 0x3F
+
''<span style="color:red;">No additional information</span>''

Latest revision as of 10:31, 9 May 2018


Author Matrix Ltd.
Version 1.3 (Release)
Category Comms: Interface


Image I2C Slave component

Generic Two Wire I2C Communications Interface

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

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

Parameters

BYTE Last
Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte


Return value

BYTE


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.

Parameters

BYTE Data
Data byte to send on the I²C bus.


Return value

BYTE


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)

Parameters

This macro has no parameters


Return value

BYTE


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.

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

Channel

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

Channel selection

Baud Select

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

Baud rate option selector

Baud Rate

This property is of type Signed integer and can be referenced with the variable name cal_i2c::BAUD.

Baud rate to be used

Stop Delay

This property is of type True or false and can be referenced with the variable name cal_i2c::StopDel.

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 Address

This property is of type Unsigned integer and can be referenced with the variable name Slave_Address.

No additional information


Mask

This property is of type Unsigned integer and can be referenced with the variable name 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

SDA

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)

SCL

This property is of type Single digital pin and can be referenced with the variable name cal_i2c::SCL.

Pin used for SCL (clock signal)

Label

This property is of type Line of text and can be referenced with the variable name label.

Label shown on the comms flasher on the simulation panel.

Scope Traces

This property is of type True or false and can be referenced with the variable name cal_i2c::ScopeTraces.

Selects if the scope traces are automatically generated or not

Console Data

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

Injector

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

No additional information