ST7 S/W IMPLEMENTATION OF I2C BUS MASTER
SetBit(I2C_SR2,AF);
ClrBit(I2C_SR1,ACK);
return;
}
delay(1);
if (ValBit(PADR,SDA))
/* Test of SDA level, if high -> pb */
{
SetBit(I2C_SR2,AF);
ClrBit(I2C_SR1,ACK);
return;
}
delay(1);
SetBit(PADDR,SCL);
/* End of the clock pulse
*/
SetBit(I2C_SR1,ACK);
delay(1);
ClrBit (PADR,SDA);
SetBit(PADDR,SDA);
/* Reconfigure SDA as output to proceed at the next transmission */
}
/*--------------------------------------------------------------------------
ROUTINE NAME : I2C_nAck
INPUT/OUTPUT : None.
DESCRIPTION : Non acknoledge generation from now.
COMMENTS : Transfer sequence = DATA, NACK.
--------------------------------------------------------------------------*/
void I2C_nAck (void)
{
ClrBit(I2C_SR2,ACK); /* Non acknoledge when the master is receiver */
SetBit(PADR,SDA); /* The master pulls the SDA line high
*/
SetBit(PADDR,SCL); /* Output open drain to have a low level */
delay(10);
ClrBit(PADDR,SCL); /* The master generates a clock pulse
*/
delay(10);
SetBit(PADDR,SCL); /* Clock pulse complete
*/
ClrBit(PADR,SDA); /* The master pulls the SDA line high
*/
delay(3);
}
/*--------------------------------------------------------------------------
ROUTINE NAME : I2Cm_Init
INPUT/OUTPUT : None.
DESCRIPTION : I2C peripheral initialisation routine.
COMMENTS : Contains inline assembler instructions in C like mode !
--------------------------------------------------------------------------*/
void I2Cm_Init (void)
11/16