Component: I2C (CAL) (Misc)

From Flowcode Help
Jump to navigationJump to search
Author Matrix TSL
Version 2.0
Category Misc


I2C component

CAL = Code Abstraction Layer - Allows one code base to run on a wide range of chips. A low level implementation giving direct access to the Two Wire I²C peripheral.

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


Macro reference

GetConsoleHandle

Fc9-comp-macro.png GetConsoleHandle
Obtains the CAL console handle 
Fc9-h32-icon.png - HANDLE Return


GetList

Fc9-comp-macro.png GetList
returns Named property List as filter string  
Fc9-string-icon.png - STRING Name
 
Fc9-string-icon.png - STRING Return


GetValue

Fc9-comp-macro.png GetValue
Get the Named property value.  
Fc9-string-icon.png - STRING Name
 
Fc9-string-icon.png - STRING Return


Master_Init

Fc9-comp-macro.png Master_Init
Initialise the Master 
Fc9-void-icon.png - VOID Return


Master_Restart

Fc9-comp-macro.png Master_Restart
Output a Master Restart sequence 
Fc9-void-icon.png - VOID Return


Master_RxByte

Fc9-comp-macro.png Master_RxByte
Returns a received data byte. Set Last=0 if there is following more Master_RxByte macros Set Last=1 if this is the last Master_RxByte and it is followed with Master_Stop. If Last = 1 the I2C bus will be presented with a 'Nack' condition. 
Fc9-u8-icon.png - BYTE Last
Range: 0-1 - 0 = Not the last byte to receive, 1 = last byte to receive 
Fc9-u8-icon.png - BYTE Return


Master_Start

Fc9-comp-macro.png Master_Start
Output a Master Start sequence 
Fc9-void-icon.png - VOID Return


Master_Stop

Fc9-comp-macro.png Master_Stop
Output a Master Stop 
Fc9-void-icon.png - VOID Return


Master_TxByte

Fc9-comp-macro.png Master_TxByte
Send a data byte and collects the acknowledge from the slave. Returns 0 for Ack received. Returns 1 for Ack not received - slave not responding. 
Fc9-u8-icon.png - BYTE Data
Data byte to write to the I2C bus 
Fc9-u8-icon.png - BYTE Return


Master_Uninit

Fc9-comp-macro.png Master_Uninit
Uninitialise the Master 
Fc9-void-icon.png - VOID Return


SetValue

Fc9-comp-macro.png SetValue
Change Named property to new Value. If "CHANNEL" the ports will be also updated from the fcd  
Fc9-string-icon.png - STRING Name
 
Fc9-string-icon.png - STRING Value
port value as string 
Fc9-void-icon.png - VOID Return


Slave_Init

Fc9-comp-macro.png Slave_Init
Initialise the Slave with the given Address, or range of Addresses. Only address bits that have a corresponding bit set in the Mask will be compared with the incoming bus address. 
Fc9-u8-icon.png - BYTE Address
7 Bit Address of this device (Bit 0 is ignored) 
Fc9-u8-icon.png - BYTE Mask
Bit mask used to compare addresses 
Fc9-void-icon.png - VOID Return


Slave_RxByte

Fc9-comp-macro.png Slave_RxByte
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
Sends Ack if 0, else Nak 
Fc9-u8-icon.png - BYTE Return


Slave_Status

Fc9-comp-macro.png Slave_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


Slave_TxByte

Fc9-comp-macro.png Slave_TxByte
Send a data byte, returns Ack/Nak from Master 0=Ack=More, 1=Nak=Last 
Fc9-u8-icon.png - BYTE Data
 
Fc9-u8-icon.png - BYTE Return


Slave_Uninit

Fc9-comp-macro.png Slave_Uninit
Uninitialise the Slave 
Fc9-void-icon.png - VOID Return


Transaction_Initialise

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


Transaction_Read

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


Transaction_Uninit

Fc9-comp-macro.png Transaction_Uninit
Uninitialise the I2C interface 
Fc9-void-icon.png - VOID Return


Transaction_Write

Fc9-comp-macro.png Transaction_Write
Attempt to write Length number of bytes to the I2C slave from the given Buffer. Ensure that the Buffer is large enough. Returns the number of bytes written, the caller should check that this matches requested Length 
Fc9-u8-icon.png - BYTE Buffer
Buffer of bytes to write to the I2C 
Fc9-u16-icon.png - UINT Length
Number of bytes to send out, MS bit 0x8000 signifies no Stop if set 
Fc9-u16-icon.png - UINT Return


Property reference

Fc9-prop-icon.png Properties
Fc9-type-7-icon.png Component Enable
Allows the component to be easily disabled from generating code, allowing for multiple CAL components to be easily created. For example a sensor IC with both I2C and SPI communications interfaces. 
Fc9-conn-icon.png Connections
Fc9-type-16-icon.png Channel
Channel selection 
Fc9-type-16-icon.png Mode
Defines if the component will be used for Master or Slave communications. Master mode supports a software bitbanged I2C channel. Slave mode requires a hardware I2C peripheral to catch the communications from the Master. 
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 Options
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-16-icon.png Baud Select
Baud rate option selector 
Fc9-type-14-icon.png Baud Rate
Baud rate to be used 
Fc9-type-16-icon.png Slew Rate Control
Slew Rate Control Enabled or Disabled 
Fc9-type-16-icon.png SMBus Inputs
When Enabled input logic thresholds are compliant with SMBus specification 
Fc9-conn-icon.png Simulation
Fc9-type-7-icon.png Scope Traces
Selects if the component pin connections are automatically generated on the data recorder window or not. Yes: Automatically add the component pins to a group on the data recorder which will reflect the sim data during simultion. No: Do not show the pin signals on the data recorder window. 
Fc9-type-7-icon.png Console Data
Selects if the console data is automatically generated or not 
Fc9-type-16-icon.png API
Specifies the API component on the panel to interact with to provide comms simulation. 

Component Source Code

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

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