ST7 S/W IMPLEMENTATION OF I2C BUS MASTER
if (flag==1) return;
/* If master receiver, go back to I2Cm_Rx() to receive data */
}
}
/*--------------------------------------------------------------------------
ROUTINE NAME : I2Cm_Rx
INPUT/OUTPUT : @ reception buffer + n-2 data/ None.
DESCRIPTION : Receive in data buffer via I2C.
COMMENTS : Most significant bytes first.
--------------------------------------------------------------------------*/
void I2Cm_Rx (char *buffin,char nb)
{
SetBit(I2C_SR1,RCPT);
/* Master in receiver mode
*/
I2Cm_Tx(send_tab,nb);
/* Send the addresses and wait ACK */
if (ValBit(I2C_SR2,AF)) return;
/* If AF -> go back to main and restart the reception */
for (j=nb-2;j!=0xFF;j--)
{
count=1;
buff=0;
ClrBit(PADDR,SDA);
/* SDA as floating input to read data from the EEPROM */
do
{
I2Cm_RxData();
/* Read data bit per bit, MSB first */
count*=2;
}while(count!=0);
I2C_DR=buff;
SetBit(PADDR,SDA);
/* Configure SDA as output
*/
if (j==0)
I2C_nAck();
/* Non acknowledge to make the master generate the STOP */
else
I2C_Ack();
/* To acknowledge read data
*/
buffin[j]=I2C_DR;
}
}
/* Store read data into buffin */
/******************* (c) 2003 STMicroelectronics ************ END OF FILE ***/
15/16