/****************************************************************************
* Function: BOOL StartTransfer( I2C_MODULE i2c_port, BOOL restart );
* Summary: Starts (or restarts) a transfer to/from the EEPROM.
* Description: This routine starts (or restarts) a transfer to/from the
* EEPROM, waiting (in a blocking loop) until the start (or re-
* start) condition has completed.
*
* Precondition: The I2C module must have been initialized.
* Parameters: restart - If FALSE, send a "Start" condition
* - If TRUE, send a "Restart" condition
* i2c_port- I2C1 or I2C2
*
* Returns: TRUE - If successful
* FALSE - If a collision occurred during Start signaling
* Remarks: This is a blocking routine that waits for the bus to be idle
* and the Start (or Restart) sequence to complete.
*****************************************************************************/
BOOL StartTransfer( I2C_MODULE i2c_port, BOOL restart )
{
I2C_STATUS status;
/* Send the Start (or Restart) sequence */
if(restart)
{
I2CRepeatStart(i2c_port);
}
else
{
/* Wait for the bus to be idle, then start the transfer */
while( !I2CBusIsIdle(i2c_port) );
if(I2CStart(i2c_port) != I2C_SUCCESS)
{
printf("Error: Bus collision during transfer Start\n");
return FALSE;
}
}
/* Wait for the START or REPEATED START to complete */
do
{
status = I2CGetStatus(i2c_port);
} while ( !(status & I2C_START) );
return TRUE;
}