User Manual
Application Note
SMBus communication with MLX90614
390119061402 Page 29 of 32 Jan-2008
Rev 004
♦ APPENDIX – SMBus exemplary functions for PIC18 using microchip
MCC18 compiler
//SMBus control signals
#define _SCL_IO TRISCbits.TRISC3 // Pin RC3 direction control bit
#define _SDA_IO TRISCbits.TRISC4 // Pin RC4 direction control bit
#define _SCL PORTCbits.RC3 // Assigns pin RC3 for SLC line
#define _SDA PORTCbits.RC4 // Assigns pin RC4 for SDA line
#define mSDA_HIGH() _SDA_IO=1; // Sets SDA line
#define mSDA_LOW() _SDA=0;_SDA_IO=0; // Clears SDA line
#define mSCL_HIGH() _SCL=1;_SCL_IO=0; // Sets SCL line
#define mSCL_LOW() _SCL=0;_SCL_IO=0; // Clears SCL line
//High and Low level of clock @ Fosc=11.0592MHz, Tcy=362ns
#define HIGHLEV 3
#define LOWLEV 1
//Delay constants @ Fosc=11.0592MHz, Tcy=362ns
#define TBUF 2
//***********************************************************************************************************
// START CONDITION ON SMBus
//***********************************************************************************************************
//Name: START_bit
//Function: Generates START condition on SMBus
//Parameters: No
//Return: No
//Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0"
//***********************************************************************************************************
void START_bit(void)
{
mSDA_HIGH(); // Set SDA line
Delay10TCYx( TBUF ); // Wait a few microseconds
mSCL_HIGH(); // Set SCL line
Delay10TCYx( TBUF ); // Generate bus free time between Stop
// and Start condition (Tbuf=4.7us min)
mSDA_LOW(); // Clear SDA line
Delay10TCYx( TBUF ); // Hold time after (Repeated) Start
// Condition. After this period, the first clock is generated.
//(Thd:sta=4.0us min)
mSCL_LOW(); // Clear SCL line
Delay10TCYx( TBUF ); // Wait a few microseconds
}