Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
338
mikoC PRO for PIC32
MikroElektronika
I²C Library
The I²C full master I²C module is available with a number of the PIC32 MCU models. The mikroC PRO for PIC32 
provides a library which supports the master I²C mode.
Important
- 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 
x in the routine prototype for a number from 1 to 5
- Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this 
library. 
Library Routines
 
- I2Cx_Init 
 
- I2Cx_Init_Advanced 
 
- I2Cx_Start 
 
- I2Cx_Restart 
 
- I2Cx_Is_Idle 
 
- I2Cx_Read 
 
- I2Cx_Write 
 
- I2Cx_Stop 
I2Cx_Init
Prototype
void I2Cx_Init(unsigned long scl);
Description This function configures and initializes the desired I²C module with default settings.
This function enables the I²C module by setting the I2CEN bit. The rest of the bits in I²C control register 
remains unchanged. Default initialization (after reset) of I²C module is:
- Continue operation in IDLE mode. 
- 7-bit slave address. 
- Slew rate control enabled for High Speed mode (400 kHz). 
- General call address disabled. 
- SCL clock stretching disabled. 
As per the I²C standard, SCL clock may be 100 kHz or 400 kHz. However, the user can specify any 
clock rate up to 1 MHz.
Parameters 
scl
: requested serial clock rate. 
Returns
Nothing.
Requires
MCU with the I²C module.
Example
// Initialize the I2C1 module with clock_rate of 100000
I2C1_Init(100000);
Notes
- Refer to the MCU’s datasheet for correct values of the scl in respect with Fosc. 
- 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 
x in the routine prototype for a number from 1 to 5
- Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet 
before utilizing this library.