aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimofey Titovets <nefelim4ag@gmail.com>2025-07-08 21:23:27 +0200
committerKevinOConnor <kevin@koconnor.net>2025-07-09 15:45:52 -0400
commit119d00705836eda8c150437af66c39f58732b492 (patch)
treebccc737a9bcf83ccd4b5fb33bbd106766ec3aff1
parent1931b11001cc7b53c00e82ac992c70d7bd50a310 (diff)
downloadkutter-119d00705836eda8c150437af66c39f58732b492.tar.gz
kutter-119d00705836eda8c150437af66c39f58732b492.tar.xz
kutter-119d00705836eda8c150437af66c39f58732b492.zip
stm32: f0 do not send empty write on read
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
-rw-r--r--src/stm32/stm32f0_i2c.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/stm32/stm32f0_i2c.c b/src/stm32/stm32f0_i2c.c
index da632c35..381fe8b4 100644
--- a/src/stm32/stm32f0_i2c.c
+++ b/src/stm32/stm32f0_i2c.c
@@ -224,16 +224,18 @@ i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg
uint8_t *write_orig = reg;
uint8_t *read_orig = read;
- // Send start, address, reg
- i2c->CR2 = (I2C_CR2_START | config.addr |
- (reg_len << I2C_CR2_NBYTES_Pos));
- while (reg_len--) {
- ret = i2c_wait(i2c, I2C_ISR_TXIS, timeout);
- if (ret != I2C_BUS_SUCCESS)
- goto abrt;
- i2c->TXDR = *reg++;
+ if (reg_len) {
+ // Send start, address, reg
+ i2c->CR2 = (I2C_CR2_START | config.addr |
+ (reg_len << I2C_CR2_NBYTES_Pos));
+ while (reg_len--) {
+ ret = i2c_wait(i2c, I2C_ISR_TXIS, timeout);
+ if (ret != I2C_BUS_SUCCESS)
+ goto abrt;
+ i2c->TXDR = *reg++;
+ }
+ i2c_wait(i2c, I2C_ISR_TC, timeout);
}
- i2c_wait(i2c, I2C_ISR_TC, timeout);
// send restart, read data
i2c->CR2 = (I2C_CR2_START | I2C_CR2_RD_WRN | config.addr |