Mikroelektronika MIKROE-738 Datenbogen
mikroC PRO for PIC32
MikroElektronika
415
Software I²C Library
The mikroC PRO for PIC32 provides routines for implementing Software I²C communication. These routines are
hardware independent and can be used with any MCU. The Software I²C library enables you to use MCU as Master in
I²C communication. Multi-master mode is not supported.
Important:
- This library implements time-based activities, so interrupts need to be disabled when using Software I²C.
- All I²C Library functions are blocking-call functions (they are waiting for I²C clock line to become logical one).
- The pins used for the Software I²C communication should be connected to the pull-up resistors. Turning off the LEDs
connected to these pins may also be required.
- Every Software I²C library routine has its own counterpart in Hardware I²C library, except
I2C_Repeated_Start.
Soft_I2C_Start
is used instead of
I2C_Repeated_Start
.
- Working clock frequency of the Software I²C is 20kHz.
The following variable must be defined
in all projects using RS-485 Library:
Description:
Example:
extern sbit Soft_I2C_Scl;
Soft I²C Clock line.
sbit Soft_I2C_Scl at RB11_bit;
extern sbit Soft_I2C_Sda;
Soft I²C Data line.
sbit Soft_I2C_Sda at RB12_bit;
extern
sbit
Soft_I2C_Scl_
Direction;
Direction of the Soft I²C Clock
pin.
sbit
Soft_I2C_Scl_Direction
at
TRISB11_bit;
extern
sbit
Soft_I2C_Sda_
Direction;
Direction of the Soft I²C Data pin.
sbit
Soft_I2C_Sda_Direction
at
TRISB12_bit;
External dependencies of Software I²C Library
Library Routines
- Soft_I2C_Init
- Soft_I2C_Start
- Soft_I2C_Read
- Soft_I2C_Write
- Soft_I2C_Stop
- Soft_I2C_Break