Skip to content

Commit d9d9f70

Browse files
author
Jamie Smith
authored
STM32 I2C v2 HAL: Fix repeated starts in transaction mode (#153)
* Try and fix repeated start for transactional I2C API * Use OTHER_FRAME everywhere
1 parent 9a4bdb8 commit d9d9f70

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -931,21 +931,17 @@ static void prep_for_restart_if_needed(struct i2c_s *obj_s) {
931931
* STOP at the end of the current transaction.
932932
*/
933933
static uint32_t get_hal_xfer_options(struct i2c_s *obj_s, bool stop) {
934-
if (obj_s->state == STM_I2C_SB_READ_IN_PROGRESS || obj_s->state == STM_I2C_SB_WRITE_IN_PROGRESS) {
935-
if(stop) {
936-
// Generate restart condition and stop at end
937-
return I2C_OTHER_AND_LAST_FRAME;
938-
} else {
939-
// Generate restart condition but don't send STOP
940-
return I2C_OTHER_FRAME;
941-
}
934+
(void)obj_s;
935+
936+
// Note: The naming used by STM32 HAL is quite counterintuitive. "OTHER_FRAME" means "always send a
937+
// start/restart condition at the start of the frame". In contrast, "FIRST_FRAME" means "don't send
938+
// a start/restart if the previous transfer was going the same direction".
939+
if(stop) {
940+
// Generate start condition and stop at end
941+
return I2C_OTHER_AND_LAST_FRAME;
942942
} else {
943-
if(stop) {
944-
// Generate start condition and stop at end
945-
return I2C_FIRST_AND_LAST_FRAME;
946-
} else {
947-
return I2C_LAST_FRAME;
948-
}
943+
// Generate only the start condition
944+
return I2C_OTHER_FRAME;
949945
}
950946
}
951947

0 commit comments

Comments
 (0)