update version to v2.0.6

This commit is contained in:
Artery-MCU
2022-06-30 17:13:55 +08:00
parent 6dc6595ed7
commit 98a0ee73ef
1057 changed files with 29487 additions and 2644 deletions

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file i2c_application.c
* @version v2.0.5
* @date 2022-05-20
* @version v2.0.6
* @date 2022-06-28
* @brief the driver library of the i2c peripheral
**************************************************************************
* Copyright notice & Disclaimer
@@ -121,34 +121,6 @@ void i2c_config(i2c_handle_type* hi2c)
i2c_enable(hi2c->i2cx, TRUE);
}
/**
* @brief clear the addr flag.
* @param hi2c: the handle points to the operation information.
* @retval none.
*/
void i2c_addr_flag_clear(i2c_handle_type* hi2c)
{
__IO uint32_t tmpreg;
tmpreg = hi2c->i2cx->sts1;
tmpreg = hi2c->i2cx->sts2;
}
/**
* @brief clear the stop flag.
* @param hi2c: the handle points to the operation information.
* @retval none.
*/
void i2c_stop_flag_clear(i2c_handle_type* hi2c)
{
__IO uint32_t tmpreg;
tmpreg = hi2c->i2cx->sts1;
tmpreg = hi2c->i2cx->ctrl1_bit.i2cen = TRUE;
}
/**
* @brief wait for the transfer to end.
* @param hi2c: the handle points to the operation information.
@@ -177,11 +149,33 @@ i2c_status_type i2c_wait_end(i2c_handle_type* hi2c, uint32_t timeout)
}
/**
* @brief wait for the flag.
* @brief wait for the flag to be set or reset, only BUSYF flag
* is waiting to be reset, and other flags are waiting to be set
* @param hi2c: the handle points to the operation information.
* @param flag: flag to wait.
* @param status: status to wait.
* @param event_check: flag to check while waiting for the flag.
* @param flag: specifies the flag to check.
* this parameter can be one of the following values:
* - I2C_STARTF_FLAG: start condition generation complete flag.
* - I2C_ADDR7F_FLAG: 0~7 bit address match flag.
* - I2C_TDC_FLAG: transmit data complete flag.
* - I2C_ADDRHF_FLAG: master 9~8 bit address header match flag.
* - I2C_STOPF_FLAG: stop condition generation complete flag.
* - I2C_RDBF_FLAG: receive data buffer full flag.
* - I2C_TDBE_FLAG: transmit data buffer empty flag.
* - I2C_BUSERR_FLAG: bus error flag.
* - I2C_ARLOST_FLAG: arbitration lost flag.
* - I2C_ACKFAIL_FLAG: acknowledge failure flag.
* - I2C_OUF_FLAG: overflow or underflow flag.
* - I2C_PECERR_FLAG: pec receive error flag.
* - I2C_TMOUT_FLAG: smbus timeout flag.
* - I2C_ALERTF_FLAG: smbus alert flag.
* - I2C_TRMODE_FLAG: transmission mode.
* - I2C_BUSYF_FLAG: bus busy flag transmission mode.
* - I2C_DIRF_FLAG: transmission direction flag.
* - I2C_GCADDRF_FLAG: general call address received flag.
* - I2C_DEVADDRF_FLAG: smbus device address received flag.
* - I2C_HOSTADDRF_FLAG: smbus host address received flag.
* - I2C_ADDR2_FLAG: own address 2 received flag.
* @param event_check: check other error flags while waiting for the flag.
* parameter as following values:
* - I2C_EVENT_CHECK_NONE
* - I2C_EVENT_CHECK_ACKFAIL
@@ -189,47 +183,63 @@ i2c_status_type i2c_wait_end(i2c_handle_type* hi2c, uint32_t timeout)
* @param timeout: maximum waiting time.
* @retval i2c status.
*/
i2c_status_type i2c_wait_flag(i2c_handle_type* hi2c, uint32_t flag, flag_status status, uint32_t event_check, uint32_t timeout)
i2c_status_type i2c_wait_flag(i2c_handle_type* hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout)
{
while(i2c_flag_get(hi2c->i2cx, flag) == status)
if(flag == I2C_BUSYF_FLAG)
{
/* check the ack fail flag */
if(event_check & I2C_EVENT_CHECK_ACKFAIL)
while(i2c_flag_get(hi2c->i2cx, flag) != RESET)
{
if(i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET)
/* check timeout */
if((timeout--) == 0)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
hi2c->error_code = I2C_ERR_TIMEOUT;
/* clear ack fail flag */
i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG);
hi2c->error_code = I2C_ERR_ACKFAIL;
return I2C_ERR_ACKFAIL;
return I2C_ERR_TIMEOUT;
}
}
/* check the stop flag */
if(event_check & I2C_EVENT_CHECK_STOP)
}
else
{
while(i2c_flag_get(hi2c->i2cx, flag) == RESET)
{
if(i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET)
/* check the ack fail flag */
if(event_check & I2C_EVENT_CHECK_ACKFAIL)
{
/* clear stop flag */
i2c_stop_flag_clear(hi2c);
if(i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
hi2c->error_code = I2C_ERR_STOP;
/* clear ack fail flag */
i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG);
return I2C_ERR_STOP;
hi2c->error_code = I2C_ERR_ACKFAIL;
return I2C_ERR_ACKFAIL;
}
}
}
/* check timeout */
if((timeout--) == 0)
{
hi2c->error_code = I2C_ERR_TIMEOUT;
/* check the stop flag */
if(event_check & I2C_EVENT_CHECK_STOP)
{
if(i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET)
{
/* clear stop flag */
i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG);
return I2C_ERR_TIMEOUT;
hi2c->error_code = I2C_ERR_STOP;
return I2C_ERR_STOP;
}
}
/* check timeout */
if((timeout--) == 0)
{
hi2c->error_code = I2C_ERR_TIMEOUT;
return I2C_ERR_TIMEOUT;
}
}
}
@@ -279,7 +289,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
i2c_start_generate(hi2c->i2cx);
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -297,7 +307,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
i2c_data_send(hi2c->i2cx, (uint8_t)((address & 0x0300) >> 7) | 0xF0);
/* wait for the addrh flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR10;
@@ -309,7 +319,7 @@ i2c_status_type i2c_master_write_addr(i2c_handle_type *hi2c, uint16_t address, u
}
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -335,7 +345,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
i2c_start_generate(hi2c->i2cx);
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -353,7 +363,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
i2c_data_send(hi2c->i2cx, (uint8_t)((address & 0x0300) >> 7) | 0xF0);
/* wait for the addrh flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDRHF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR10;
@@ -364,7 +374,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
i2c_data_send(hi2c->i2cx, (uint8_t)(address & 0x00FF));
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -372,13 +382,13 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* generate restart condtion */
i2c_start_generate(hi2c->i2cx);
/* wait for the start flag to be set */
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_STARTF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_START;
@@ -390,7 +400,7 @@ i2c_status_type i2c_master_read_addr(i2c_handle_type *hi2c, uint16_t address, ui
}
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
hi2c->error_code = I2C_ERR_ADDR;
@@ -418,7 +428,7 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -436,12 +446,12 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
while(size > 0)
{
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -455,7 +465,7 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin
}
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -486,7 +496,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -498,7 +508,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -507,12 +517,12 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
while(size > 0)
{
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -526,7 +536,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
}
/* wait for the stop flag to be set */
if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -535,7 +545,7 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_
}
/* clear stop flag */
i2c_stop_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -561,7 +571,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -587,7 +597,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
i2c_ack_enable(hi2c->i2cx, FALSE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -601,7 +611,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
i2c_ack_enable(hi2c->i2cx, FALSE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
else
{
@@ -609,7 +619,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
i2c_ack_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
while(size > 0)
@@ -620,7 +630,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
if(size == 1)
{
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -636,7 +646,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
else if(size == 2)
{
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -659,7 +669,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
else
{
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -675,7 +685,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
size--;
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -698,7 +708,7 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint
else
{
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -732,7 +742,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -744,7 +754,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -753,12 +763,12 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
if(hi2c->i2cx->oaddr1_bit.addr1mode == I2C_ADDRESS_MODE_10BIT)
{
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -767,13 +777,13 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
while(size > 0)
{
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -787,7 +797,7 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16
}
/* wait for the ackfail flag to be set */
if(i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_5;
}
@@ -823,7 +833,7 @@ i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address,
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -841,7 +851,7 @@ i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address,
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* enable interrupt */
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
@@ -870,7 +880,7 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -882,13 +892,13 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_2;
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* enable interrupt */
i2c_interrupt_enable(hi2c->i2cx, I2C_EVT_INT | I2C_DATA_INT | I2C_ERR_INT, TRUE);
@@ -918,7 +928,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -944,7 +954,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
i2c_ack_enable(hi2c->i2cx, FALSE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -955,7 +965,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
i2c_master_receive_ack_set(hi2c->i2cx, I2C_MASTER_ACK_NEXT);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -966,7 +976,7 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address,
i2c_ack_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
/* enable interrupt */
@@ -996,7 +1006,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1008,18 +1018,18 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
i2c_ack_enable(hi2c->i2cx, TRUE);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_2;
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
if(hi2c->i2cx->oaddr1_bit.addr1mode == I2C_ADDRESS_MODE_10BIT)
{
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1028,7 +1038,7 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
/* enable interrupt */
@@ -1059,7 +1069,7 @@ i2c_status_type i2c_master_transmit_dma(i2c_handle_type* hi2c, uint16_t address,
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1083,7 +1093,7 @@ i2c_status_type i2c_master_transmit_dma(i2c_handle_type* hi2c, uint16_t address,
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* enable dma request */
i2c_dma_enable(hi2c->i2cx, TRUE);
@@ -1112,7 +1122,7 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1130,7 +1140,7 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin
i2c_dma_config(hi2c, hi2c->dma_rx_channel, pdata, size);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1142,7 +1152,7 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin
i2c_dma_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
return I2C_OK;
}
@@ -1169,7 +1179,7 @@ i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address,
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1198,7 +1208,7 @@ i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address,
if(size == 1)
{
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1218,7 +1228,7 @@ i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address,
i2c_dma_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
return I2C_OK;
@@ -1245,7 +1255,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1264,7 +1274,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1275,10 +1285,10 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
if(hi2c->i2cx->oaddr1_bit.addr1mode == I2C_ADDRESS_MODE_10BIT)
{
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the addr7 flag to be set */
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_ADDR7F_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1288,7 +1298,7 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* enable dma request */
i2c_dma_enable(hi2c->i2cx, TRUE);
@@ -1315,7 +1325,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1333,10 +1343,10 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1350,7 +1360,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
while(size > 0)
{
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1364,7 +1374,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
}
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1397,7 +1407,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1418,10 +1428,10 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1433,7 +1443,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1456,7 +1466,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
i2c_ack_enable(hi2c->i2cx, FALSE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1467,7 +1477,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
i2c_master_receive_ack_set(hi2c->i2cx, I2C_MASTER_ACK_NEXT);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1478,7 +1488,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
i2c_ack_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
while(size > 0)
@@ -1489,7 +1499,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
if(size == 1)
{
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1505,7 +1515,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
else if(size == 2)
{
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1528,7 +1538,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
else
{
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1544,7 +1554,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
size--;
/* wait for the tdc flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1567,7 +1577,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
else
{
/* wait for the rdbf flag to be set */
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, RESET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1607,7 +1617,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1625,10 +1635,10 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1640,7 +1650,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1677,7 +1687,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1695,10 +1705,10 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1710,7 +1720,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1733,7 +1743,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
i2c_ack_enable(hi2c->i2cx, FALSE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1744,7 +1754,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
i2c_master_receive_ack_set(hi2c->i2cx, I2C_MASTER_ACK_NEXT);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1755,7 +1765,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
i2c_ack_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
/* enable interrupt */
@@ -1787,7 +1797,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1811,10 +1821,10 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1826,7 +1836,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1863,7 +1873,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
hi2c->error_code = I2C_OK;
/* wait for the busy flag to be reset */
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, SET, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK)
{
return I2C_ERR_STEP_1;
}
@@ -1890,10 +1900,10 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
}
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1905,7 +1915,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
i2c_data_send(hi2c->i2cx, mem_address);
/* wait for the tdbe flag to be set */
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
{
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
@@ -1925,7 +1935,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
if(size == 1)
{
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
/* disable ack */
i2c_ack_enable(hi2c->i2cx, FALSE);
@@ -1945,7 +1955,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
i2c_dma_enable(hi2c->i2cx, TRUE);
/* clear addr flag */
i2c_addr_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_ADDR7F_FLAG);
}
return I2C_OK;
@@ -2076,7 +2086,7 @@ void i2c_slave_tx_isr_int(i2c_handle_type* hi2c)
i2c_interrupt_enable(hi2c->i2cx, I2C_DATA_INT | I2C_EVT_INT | I2C_ERR_INT, FALSE);
/* wait for the ackfail flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear ackfail flag */
i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG);
@@ -2111,7 +2121,7 @@ void i2c_slave_rx_isr_int(i2c_handle_type* hi2c)
else if(i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET)
{
/* clear stop flag */
i2c_stop_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG);
/* transfer complete */
hi2c->status = I2C_END;
@@ -2167,14 +2177,14 @@ void i2c_dma_tx_irq_handler(i2c_handle_type* hi2c)
{
case I2C_DMA_MA_TX:
/* wait for the tdc flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_TDC_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
hi2c->status = i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* generate stop condtion */
i2c_stop_generate(hi2c->i2cx);
break;
case I2C_DMA_SLA_TX:
/* wait for the ackfail flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
hi2c->status = i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear ackfail flag */
i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG);
@@ -2226,10 +2236,10 @@ void i2c_dma_rx_irq_handler(i2c_handle_type* hi2c)
break;
case I2C_DMA_SLA_RX:
/* wait for the stop flag to be set */
hi2c->status = i2c_wait_flag(hi2c, I2C_STOPF_FLAG, RESET, I2C_EVENT_CHECK_NONE, hi2c->timeout);
hi2c->status = i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, hi2c->timeout);
/* clear stop flag */
i2c_stop_flag_clear(hi2c);
i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG);
break;
default:
break;

View File

@@ -1,8 +1,8 @@
/**
**************************************************************************
* @file i2c_application.h
* @version v2.0.5
* @date 2022-05-20
* @version v2.0.6
* @date 2022-06-28
* @brief i2c application libray header file
**************************************************************************
* Copyright notice & Disclaimer
@@ -114,7 +114,6 @@ typedef struct
{
i2c_type *i2cx; /*!< i2c registers base address */
uint8_t *pbuff; /*!< pointer to i2c transfer buffer */
__IO uint16_t psize; /*!< i2c transfer size */
__IO uint16_t pcount; /*!< i2c transfer counter */
__IO uint32_t mode; /*!< i2c communication mode */
__IO uint32_t timeout; /*!< i2c wait time */
@@ -135,9 +134,8 @@ typedef struct
void i2c_config (i2c_handle_type* hi2c);
void i2c_lowlevel_init (i2c_handle_type* hi2c);
void i2c_reset_ctrl2_register (i2c_handle_type* hi2c);
i2c_status_type i2c_wait_end (i2c_handle_type* hi2c, uint32_t timeout);
i2c_status_type i2c_wait_flag (i2c_handle_type* hi2c, uint32_t flag, flag_status status, uint32_t event_check, uint32_t timeout);
i2c_status_type i2c_wait_flag (i2c_handle_type* hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout);
i2c_status_type i2c_master_transmit (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
i2c_status_type i2c_master_receive (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);