Skip to content

Fix for I2C bus not always working correctly after a slave device call end() #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading