aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Bird <[email protected]>2024-06-21 15:09:57 +0100
committerJamie Bird <[email protected]>2024-06-21 15:09:57 +0100
commit060d1f6e6f36b01e1f0ec4beb20499ac22d94b24 (patch)
tree6bab28f269c2c4566832f8d5769eb4858cd4ea95
parentd5badb94d2098b0360ed1ab8015c37f819771445 (diff)
Fix: Ensure I2C bus is free before master-write operation
The I2C master-write function was failing when executed immediately after an I2C read operation, requiring manual delays to function correctly. This fix introduces a check to ensure the I2C bus is free before initiating the write operation. According to the RM0399 manual for STM32H7 chips, the BUSY bit (Bit 15 in the I2C ISR register) indicates whether a communication is in progress on the bus. The BUSY bit is set by hardware when a START condition is detected and cleared when a STOP condition is detected or when PE = 0. This fix prevents the write operation from starting until the BUSY bit is cleared.
-rw-r--r--embassy-stm32/src/i2c/v2.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 80163c287..27381cd3c 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -109,6 +109,11 @@ impl<'d, M: Mode> I2c<'d, M> {
109 timeout.check()?; 109 timeout.check()?;
110 } 110 }
111 111
112 // Wait for the bus to be free
113 while info.regs.isr().read().busy(){
114 timeout.check()?;
115 };
116
112 let reload = if reload { 117 let reload = if reload {
113 i2c::vals::Reload::NOTCOMPLETED 118 i2c::vals::Reload::NOTCOMPLETED
114 } else { 119 } else {