File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed 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_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