Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t i2c_send_start(void)
- {
- uint8_t timeout_count = 0;
- /* Send START condition. */
- LPC_I2C1->I2CONSET = 0x1 << I2CONSET_STA;
- /* Wait until START condition is sent. */
- do {
- /* If the transmission takes longer than TIMEOUT, returns error. */
- if (timeout_count++ >= I2C_START_TIMEOUT)
- return I2C_FUNCTION_RETCODE_TIMEOUT;
- } while (!(LPC_I2C1->I2CONSET & (0x1 << I2CONSET_SI)));
- /* If the status code differs from I2C_STARTED, returns error. */
- if (i2c_get_status() != I2C_STARTED)
- return I2C_FUNCTION_RETCODE_COMM_FAIL;
- /* Clear bit START. */
- LPC_I2C1->I2CONCLR = 0x1 << I2CONSET_STA;
- /* Everything went well. */
- return I2C_FUNCTION_RETCODE_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment