From 8eab8161d37a362cab6b440cca73e88f296133d1 Mon Sep 17 00:00:00 2001 From: maidnl Date: Thu, 16 May 2024 11:45:57 +0200 Subject: [PATCH] Fix for I2C bus not always working correctly after a slave device call end --- libraries/Wire/Wire.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index c7561ea83..4fdffa032 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -437,25 +437,28 @@ void TwoWire::end(void) { if(init_ok) { if(is_master) { if(m_close != nullptr) { - m_close(&m_i2c_ctrl); R_BSP_IrqDisable (m_i2c_cfg.txi_irq); R_BSP_IrqDisable (m_i2c_cfg.rxi_irq); R_BSP_IrqDisable (m_i2c_cfg.tei_irq); R_BSP_IrqDisable (m_i2c_cfg.eri_irq); - + m_close(&m_i2c_ctrl); } } else { if(s_close != nullptr) { - s_close(&s_i2c_ctrl); R_BSP_IrqDisable (s_i2c_cfg.txi_irq); R_BSP_IrqDisable (s_i2c_cfg.rxi_irq); R_BSP_IrqDisable (s_i2c_cfg.tei_irq); R_BSP_IrqDisable (s_i2c_cfg.eri_irq); + s_close(&s_i2c_ctrl); } } } + /* fix for slave that create a sort of lock on the I2C bus when end is called and the master + is not more able to get the I2C buse working */ + R_IOPORT_PinCfg(NULL, g_pin_cfg[sda_pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE); + R_IOPORT_PinCfg(NULL, g_pin_cfg[scl_pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE); init_ok = false; }