User Manual
Application Note
SMBus communication with MLX90614
390119061402 Page 30 of 32 Jan-2008
Rev 004
//************************************************************************************************************
// STOP CONDITION ON SMBus
//************************************************************************************************************
//Name: STOP_bit
//Function: Generates STOP condition on SMBus
//Parameters: No
//Return: No
//Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0"
//***********************************************************************************************************
void STOP_bit(void)
{
mSCL_LOW(); // Clear SCL line
Delay10TCYx( TBUF ); // Wait a few microseconds
mSDA_LOW(); // Clear SDA line
Delay10TCYx( TBUF ); // Wait a few microseconds
mSCL_HIGH(); // Set SCL line
Delay10TCYx( TBUF ); // Stop condition setup time(Tsu:sto=4.0us min)
mSDA_HIGH(); // Set SDA line
}
//************************************************************************************************************
// TRANSMIT DATA ON SMBus
//************************************************************************************************************
//Name: TX_byte
//Function: Sends a byte on SMBus
//Parameters: unsigned char TX_buffer ( the byte which will be send on the SMBus )
//Return: unsigned char Ack_bit (acknowledgment bit)
// 0 - ACK
// 1 - NACK
//Comments: Sends MSbit first
//***********************************************************************************************************
unsigned char TX_byte(unsigned char Tx_buffer)
{
unsigned char Bit_counter;
unsigned char Ack_bit;
unsigned char bit_out;
for(Bit_counter=8; Bit_counter; Bit_counter--)
{
if(Tx_buffer&0x80)
bit_out=1; // If the current bit of Tx_buffer is 1 set bit_out
else
bit_out=0; // else clear bit_out
send_bit(bit_out); // Send the current bit on SDA
Tx_buffer<<=1; // Get next bit for checking
}
Ack_bit=Receive_bit(); // Get acknowledgment bit
return Ack_bit;
}// End of TX_byte()