bmeneguele

Untitled

Apr 8th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. uint8_t i2c_send_start(void)
  2. {
  3.     uint8_t timeout_count = 0;
  4.  
  5.     /* Send START condition. */
  6.     LPC_I2C1->I2CONSET = 0x1 << I2CONSET_STA;
  7.  
  8.     /* Wait until START condition is sent. */
  9.     do {
  10.         /* If the transmission takes longer than TIMEOUT, returns error. */
  11.         if (timeout_count++ >= I2C_START_TIMEOUT)
  12.             return I2C_FUNCTION_RETCODE_TIMEOUT;
  13.     } while (!(LPC_I2C1->I2CONSET & (0x1 << I2CONSET_SI)));
  14.  
  15.     /* If the status code differs from I2C_STARTED, returns error. */
  16.     if (i2c_get_status() != I2C_STARTED)
  17.         return I2C_FUNCTION_RETCODE_COMM_FAIL;
  18.  
  19.     /* Clear bit START. */
  20.     LPC_I2C1->I2CONCLR = 0x1 << I2CONSET_STA;
  21.     /* Everything went well. */
  22.     return I2C_FUNCTION_RETCODE_SUCCESS;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment