I²C Library
The I²C full master I²C module is available with a number of the MCU models. The mikroPascal PRO for FT90x provides a library which supports the master I²C mode.

- I²C library routines require you to specify the module you want to use. To select the desired I²C module, simply change the letter n in the routine prototype for a number from 0 to 5.
- Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.
- Library routine prototypes may vary from family to family, so please pay attention to the desired routine section.
Library Routines
- I2CM1_Init
- I2CM1_Soft_Reset
- I2CM1_Set_Slave_Address
- I2CM1_Read
- I2CM1_Read_10Bit
- I2CM1_Read_Bytes
- I2CM1_Write
- I2CM1_Write_10Bit
- I2CM1_Write_Bytes
- I2CM_Set_Active
Generic Routines
- I2CM_Soft_Reset
- I2CM_Set_Slave_Address
- I2CM_Read
- I2CM_Read_10Bit
- I2CM_Read_Bytes
- I2CM_Write
- I2CM_Write_10Bit
- I2CM_Write_Bytes
I2CM1_Init
Prototype |
procedure I2CM1_Init(speedMode : byte; swap : byte); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function configures and initializes the I²C module with the standard user-defined settings. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Returns |
Nothing. |
||||||||||||||||
Requires |
Routine requires MCU with the I²C module. |
||||||||||||||||
Example |
// Initialize the I2C module with the standard bitrate, swapping disabled I2CM1_Init(_I2CM_SPEED_MODE_STANDARD, _I2CM_SWAP_DISABLE); |
||||||||||||||||
Notes |
|
I2CM1_Soft_Reset
Prototype |
procedure I2CM1_Soft_Reset(); |
---|---|
Description |
This function resets the whole I²C Master controller. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
// Reset I2C Master I2CM1_Soft_Reset(); |
Notes |
|
I2CM1_Set_Slave_Address
Prototype |
procedure I2CM1_Set_Slave_Address(slaveAddress : byte); |
---|---|
Description |
Sets the address which the I²C Master will place on the bus, i.e. Slave address. |
Parameters |
|
Returns |
Nothing. |
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
// Set slave address I2CM1_Set_Slave_Address(0x0A); |
Notes |
|
I2CM1_Read
Prototype |
function I2CM1_Read(dataIn : ^byte); |
---|---|
Description |
Receives a single byte from the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Read(@bufferIn); // read bytes and store to bufferIn. |
Notes |
|
I2CM1_Read_10Bit
Prototype |
function I2CM1_Read_10Bit(dataIn : ^byte; address10Bit : word) : byte; |
---|---|
Description |
Receives a single byte from the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Read_10Bit(@bufferIn, address); // read bytes and store to bufferIn. |
Notes |
|
I2CM1_Read_Bytes
Prototype |
function I2CM1_Read_Bytes(bufferIn : ^byte; numBytesToReceive : word) : byte; |
---|---|
Description |
Receives multiple bytes from the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Read_Bytes(@bufferIn, 16); // read 16 bytes and store it to bufferIn. |
Notes |
|
I2CM1_Write
Prototype |
function I2CM1_Write(dataOut : byte) : byte; |
---|---|
Description |
Routine sends a single byte via the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Write(dataOut); // write a byte |
Notes |
|
I2CM1_Write_10Bit
Prototype |
function I2CM1_Write_10Bit(dataOut : byte; address10Bit : word) : byte; |
---|---|
Description |
Routine sends a single byte via the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Write_10Bit(@bufferOut, address); |
Notes |
|
I2CM1_Write_Bytes
Prototype |
function I2CM1_Write_Bytes(bufferOut : ^byte; numBytesToSend : word) : byte; |
---|---|
Description |
Routine sends multiple bytes via the I²C bus. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM1_Write_Bytes(@bufferOut, 16); |
Notes |
|
I2CM_Set_Active
Prototype |
procedure I2CM_Set_Active(
|
---|---|
Description |
Sets the active I²C module which will be used by the I²C routines. |
Parameters |
|
Returns |
Nothing. |
Requires |
Used I²C module must be initialized before using this function. See the I2CM1_Init routine. |
Example |
I2CM_Set_Active(@I2CM1_Soft_Reset, @I2CM1_Set_Slave_Address, @I2CM1_Write, @I2CM1_Write_10Bit, @I2CM1_Write_Bytes, @I2CM1_Read, @I2CM1_Read_10Bit, @I2CM1_Read_Bytes); // Sets the I2CM1 module active |
Notes |
Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library. |
I2CM_Soft_Reset
Prototype |
procedure I2CM_Soft_Reset(); |
---|---|
Description |
This procedure resets the whole I²C Master controller. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this procedure. See I2CM1_Init routine. |
Example |
// Reset I2C Master I2CM_Soft_Reset(); |
Notes |
None. |
I2CM_Set_Slave_Address
Prototype |
procedure I2CM_Set_Slave_Address(slaveAddress : byte); |
---|---|
Description |
Sets the address which the I²C Master will place on the bus, i.e. Slave address. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
Nothing. |
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
// Set slave address I2CM_Set_Slave_Address(0x0A); |
Notes |
None. |
I2CM_Read
Prototype |
function I2CM_Read(dataIn : ^byte); This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
---|---|
Description |
Receives a single byte from the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Read(@dataIn); |
Notes |
None. |
I2CM_Read_10Bit
Prototype |
function I2CM_Read_10Bit(dataIn : ^byte; address10Bit : word); |
---|---|
Description |
Receives a single byte from the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Read_10Bit(@bufferIn, address); // read bytes and store to bufferIn. |
Notes |
None. |
I2CM_Read_Bytes
Prototype |
function I2CM_Read_Bytes(bufferIn : byte; numBytesToReceive : word); |
---|---|
Description |
Receives multiple bytes from the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Read_Bytes(@bufferIn, 16); // read 16 bytes and store it to bufferIn. |
Notes |
None. |
I2CM_Write
Prototype |
function I2CM_Write(dataOut : byte) : byte; |
---|---|
Description |
Routine sends a single byte via the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Write(dataOut); // write a byte |
Notes |
None. |
I2CM_Write_10Bit
Prototype |
function I2CM_Write_10Bit(dataOut : byte; address10Bit : word) : byte; |
---|---|
Description |
Routine sends a single byte via the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Write_10Bit(@bufferOut, address); |
Notes |
None. |
I2CM_Write_Bytes
Prototype |
function I2CM_Write_Bytes(bufferOut : ^byte; numBytesToSend : word) : byte; |
---|---|
Description |
Routine sends multiple bytes via the I²C bus. This is a generic routine which uses the active I²C module previously activated by the I2CM_Set_Active routine. |
Parameters |
|
Returns |
|
Requires |
Routine requires MCU with the I²C module. Used I²C module must be initialized before using this function. See I2CM1_Init routine. |
Example |
I2CM_Write_Bytes(@bufferOut, 16); |
Notes |
None. |
What do you think about this topic ? Send us feedback!