From c867d5647b41cdfb826ccd8d93ddec73d1e4791a Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Fri, 25 Aug 2023 15:24:03 +1000 Subject: [PATCH] soc/cores/i2c: only change SDA when SCL is stable Avoid changing SDA immediately in states WRITE0 and READ0 to guarantee SDA hold is > 0 --- litex/soc/cores/i2c.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/litex/soc/cores/i2c.py b/litex/soc/cores/i2c.py index 8d2fb50ad..6a7fbd331 100644 --- a/litex/soc/cores/i2c.py +++ b/litex/soc/cores/i2c.py @@ -232,11 +232,19 @@ class I2CMaster(Module, AutoCSR): self.sda_t = TSTriple() self.specials += self.sda_t.get_tristate(pads.sda) self.comb += [ - self.sda_t.oe.eq(~i2c.sda_o), self.sda_t.o.eq(0), i2c.sda_i.eq(self.sda_t.i), ] + # only change SDA when SCL is stable + self.scl_i_n = Signal() # previous scl_i + self.sync += [ + self.scl_i_n.eq(self.scl_t.i), + If(self.scl_i_n == i2c.scl_o, + self.sda_t.oe.eq(~i2c.sda_o), + ), + ] + # Event Manager. self.submodules.ev = EventManager() self.ev.idle = EventSourceProcess(edge="rising")