Mikroelektronika MIKROE-442 데이터 시트

다운로드
페이지 726
366
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
I²C Library
The I²C full master I²C module is available with a number of the dsPIC30/33 and PIC24 MCU models. The mikroBasic 
PRO for dsPIC30/33 and PIC24 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 3
- 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_Start 
 
- I2Cx_Restart 
 
- I2Cx_Is_Idle 
 
- I2Cx_Read 
 
- I2Cx_Write 
 
- I2Cx_Stop 
I2Cx_Init
Prototype
sub procedure I2Cx_Init(dim scl as longint)
Description 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 
- IPMI mode disabled 
- 7-bit slave address 
- slew rate control enabled 
- general call address disabled 
- software or receive clock stretching disabled 
Parameters 
scl
: requested serial clock rate. 
Returns
Nothing.
Requires
MCU with the I²C module.
Example
‘ Initialize the I2C1 module with clock_rate=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 3.
Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet 
before utilizing this library.