Skip to content

Commit 8eab816

Browse files
committed
Fix for I2C bus not always working correctly after a slave device call end
1 parent 8d3bb27 commit 8eab816

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: libraries/Wire/Wire.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -437,25 +437,28 @@ void TwoWire::end(void) {
437437
if(init_ok) {
438438
if(is_master) {
439439
if(m_close != nullptr) {
440-
m_close(&m_i2c_ctrl);
441440
R_BSP_IrqDisable (m_i2c_cfg.txi_irq);
442441
R_BSP_IrqDisable (m_i2c_cfg.rxi_irq);
443442
R_BSP_IrqDisable (m_i2c_cfg.tei_irq);
444443
R_BSP_IrqDisable (m_i2c_cfg.eri_irq);
445-
444+
m_close(&m_i2c_ctrl);
446445
}
447446
}
448447
else {
449448
if(s_close != nullptr) {
450-
s_close(&s_i2c_ctrl);
451449
R_BSP_IrqDisable (s_i2c_cfg.txi_irq);
452450
R_BSP_IrqDisable (s_i2c_cfg.rxi_irq);
453451
R_BSP_IrqDisable (s_i2c_cfg.tei_irq);
454452
R_BSP_IrqDisable (s_i2c_cfg.eri_irq);
453+
s_close(&s_i2c_ctrl);
455454

456455
}
457456
}
458457
}
458+
/* fix for slave that create a sort of lock on the I2C bus when end is called and the master
459+
is not more able to get the I2C buse working */
460+
R_IOPORT_PinCfg(NULL, g_pin_cfg[sda_pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE);
461+
R_IOPORT_PinCfg(NULL, g_pin_cfg[scl_pin].pin, IOPORT_CFG_PORT_DIRECTION_INPUT | IOPORT_CFG_PULLUP_ENABLE);
459462
init_ok = false;
460463
}
461464

0 commit comments

Comments
 (0)