Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(wire): ensure i2c bus is ready#1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 1 commit intostm32duino:mainfromfpistm:i2c_err
Jul 29, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletionslibraries/Wire/src/utility/twi.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -848,6 +848,7 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
uint32_ttickstart=HAL_GetTick();
uint32_tdelta=0;
uint32_terr=0;
HAL_StatusTypeDefstatus=HAL_OK;

/* When size is 0, this is usually an I2C scan / ping to check if device is there and ready */
if (size==0) {
Expand All@@ -856,12 +857,26 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
#if defined(I2C_OTHER_FRAME)
uint32_tXferOptions=obj->handle.XferOptions;// save XferOptions value, because handle can be modified by HAL, which cause issue in case of NACK from slave
#endif

do {
#if defined(I2C_OTHER_FRAME)
if (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle),dev_address,data,size,XferOptions)==HAL_OK) {
status=HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle),dev_address,data,size,XferOptions);
#else
if (HAL_I2C_Master_Transmit_IT(&(obj->handle),dev_address,data,size)==HAL_OK) {
status=HAL_I2C_Master_Transmit_IT(&(obj->handle),dev_address,data,size);
#endif
// Ensure i2c ready
if (status==HAL_BUSY) {
delta= (HAL_GetTick()-tickstart);
if (delta>I2C_TIMEOUT_TICK) {
ret=I2C_BUSY;
break;
}
}else {
ret= (status==HAL_OK) ?I2C_OK :I2C_ERROR;
}
}while (status==HAL_BUSY);

if (ret==I2C_OK) {
tickstart=HAL_GetTick();
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle))!=HAL_I2C_STATE_READY)&& (delta<I2C_TIMEOUT_TICK)) {
delta= (HAL_GetTick()-tickstart);
Expand DownExpand Up@@ -926,16 +941,31 @@ i2c_status_e i2c_master_read(i2c_t *obj, uint8_t dev_address, uint8_t *data, uin
uint32_ttickstart=HAL_GetTick();
uint32_tdelta=0;
uint32_terr=0;
HAL_StatusTypeDefstatus=HAL_OK;

#if defined(I2C_OTHER_FRAME)
uint32_tXferOptions=obj->handle.XferOptions;// save XferOptions value, because handle can be modified by HAL, which cause issue in case of NACK from slave
#endif

do {
#if defined(I2C_OTHER_FRAME)
if (HAL_I2C_Master_Seq_Receive_IT(&(obj->handle),dev_address,data,size,XferOptions)==HAL_OK) {
status=HAL_I2C_Master_Seq_Receive_IT(&(obj->handle),dev_address,data,size,XferOptions);
#else
if (HAL_I2C_Master_Receive_IT(&(obj->handle),dev_address,data,size)==HAL_OK) {
status=HAL_I2C_Master_Receive_IT(&(obj->handle),dev_address,data,size);
#endif
// Ensure i2c ready
if (status==HAL_BUSY) {
delta= (HAL_GetTick()-tickstart);
if (delta>I2C_TIMEOUT_TICK) {
ret=I2C_BUSY;
break;
}
}else {
ret= (status==HAL_OK) ?I2C_OK :I2C_ERROR;
}
}while (status==HAL_BUSY);

if (ret==I2C_OK) {
tickstart=HAL_GetTick();
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle))!=HAL_I2C_STATE_READY)&& (delta<I2C_TIMEOUT_TICK)) {
delta= (HAL_GetTick()-tickstart);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp