Component: I2C (CAL) (Peripheral CAL)

From Flowcode Help
Jump to navigationJump to search


Author Matrix TSL
Version 2.0 (Release)
Category Peripheral CAL


Image I2C (CAL) 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.

Examples

Example showing how to build a component using a CAL component Using CAL Components.


Downloadable macro reference

Slave_Uninit

Uninitialise the Slave

Parameters

This macro has no parameters


Return value

This call does not return a value


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

Parameters

BYTE Buffer
UINT Length


Return value

UINT


Master_Stop

Output a Master Stop

Parameters

This macro has no parameters


Return value

This call does not return a value


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.

Parameters

BYTE Address
7 Bit Address of this device (Bit 0 is ignored)
BYTE Mask
Bit mask used to compare addresses


Return value

This call does not return a value


Master_Uninit

Uninitialise the Master

Parameters

This macro has no parameters


Return value

This call does not return a value


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)

Parameters

This macro has no parameters


Return value

BYTE


Slave_TxByte

Send a data byte, returns Ack/Nak from Master

0=Ack=More, 1=Nak=Last

Parameters

BYTE Data


Return value

BYTE


Transaction_Uninit

Uninitialise the I2C interface

Parameters

This macro has no parameters


Return value

This call does not return a value


Slave_RxByte

Returns the data received, and sends either Ack or Nak

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

Parameters

BYTE Last
Sends Ack if 0, else Nak


Return value

BYTE


Master_Init

Initialise the Master

Parameters

This macro has no parameters


Return value

This call does not return a value


Master_Start

Output a Master Start sequence

Parameters

This macro has no parameters


Return value

This call does not return a value


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

Parameters

BYTE Buffer
UINT Length


Return value

UINT


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.

Parameters

BYTE Data


Return value

BYTE


Master_Restart

Output a Master Restart sequence

Parameters

This macro has no parameters


Return value

This call does not return a value


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.

Parameters

BYTE Last
Range: 0-1 - 0 = Not the last byte to receive, 1 = last byte to receive


Return value

BYTE


Transaction_Initialise

Initialise the I2C interface to communicate with a Slave device at Address

Returns 0 on fail, 1 on success

Parameters

BYTE Address


Return value

BYTE


Simulation macro reference

GetValue

Get the Named property value.

Parameters

STRING Name


Return value

STRING


GetConsoleHandle

Obtains the CAL console handle

Parameters

This macro has no parameters


Return value

HANDLE


SetValue

Change Named property to new Value.

If "CHANNEL" the ports will be also updated from the fcd

Parameters

STRING Name
STRING Value
port value as string


Return value

This call does not return a value


GetList

returns Named property List as filter string

Parameters

STRING Name


Return value

STRING



Property reference

Component Enable

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

No additional information


Channel

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

Channel selection

Mode

This property is of type Fixed list of ints and can be referenced with the variable name 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.

SDA

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

Pin used for SDA (data signal)

SCL

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

Pin used for SCL (clock signal)

Stop Delay

This property is of type True or false and can be referenced with the variable name 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.

Baud Select

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

Baud rate option selector

Baud Rate

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

Baud rate to be used

Slew Rate Control

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

Slew Rate Control Enabled or Disabled

SMBus Inputs

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

When Enabled input logic thresholds are compliant with SMBus specification

Scope Traces

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

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.

Console Data

This property is of type True or false and can be referenced with the variable name 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 Injector.

No additional information