File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -615,7 +615,14 @@ void I2C1_EV_IRQHandler(void) {
615615void I2C1_ER_IRQHandler (void ) {
616616 MP_STATIC_ASSERT (I2C1_ER_IRQn > 0 );
617617 IRQ_ENTER (I2C1_ER_IRQn );
618- i2c_er_irq_handler (1 );
618+ #if MICROPY_HW_ENABLE_HW_I2C_TARGET
619+ if (i2c_target_enabled & 1 ) {
620+ i2c_slave_ev_irq_handler (I2C1 );
621+ } else
622+ #endif
623+ {
624+ i2c_er_irq_handler (1 );
625+ }
619626 IRQ_EXIT (I2C1_ER_IRQn );
620627}
621628#endif // defined(MICROPY_HW_I2C1_SCL)
Original file line number Diff line number Diff line change 2828
2929#if defined(STM32F4 )
3030
31+ // The hardware triggers the following IRQs for the given scenarios:
32+ // - scan (0-length write): ADDR STOPF
33+ // - write of n bytes: ADDR RXNE*n STOPF
34+ // - read of n bytes: ADDR TXE*(n+1) AF
35+ // - write of n bytes then read of m bytes: ADDR RXNE*n ADDR TXE*(m+1) AF
36+
3137void i2c_slave_init_helper (i2c_slave_t * i2c , int addr ) {
32- i2c -> CR2 = I2C_CR2_ITBUFEN | I2C_CR2_ITEVTEN | 4 << I2C_CR2_FREQ_Pos ;
38+ i2c -> CR2 = I2C_CR2_ITBUFEN | I2C_CR2_ITEVTEN | 4 << I2C_CR2_FREQ_Pos | I2C_CR2_ITERREN ;
3339 i2c -> OAR1 = 1 << 14 | addr << 1 ;
3440 i2c -> OAR2 = 0 ;
3541 i2c -> CR1 = I2C_CR1_ACK | I2C_CR1_PE ;
3642}
3743
3844void i2c_slave_ev_irq_handler (i2c_slave_t * i2c ) {
3945 uint32_t sr1 = i2c -> SR1 ;
46+
47+ // Clear all error flags.
48+ i2c -> SR1 &= ~(I2C_SR1_SMBALERT | I2C_SR1_TIMEOUT | I2C_SR1_PECERR | I2C_SR1_OVR | I2C_SR1_AF | I2C_SR1_ARLO | I2C_SR1_BERR );
49+
50+ if (sr1 & I2C_SR1_AF ) {
51+ // A NACK in TX mode, which is a stop condition.
52+ i2c_slave_process_tx_end (i2c );
53+ }
4054 if (sr1 & I2C_SR1_ADDR ) {
4155 // Address matched
4256 // Read of SR1, SR2 needed to clear ADDR bit
You can’t perform that action at this time.
0 commit comments