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 28
28
29
29
#if defined(STM32F4 )
30
30
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
+
31
37
void 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 ;
33
39
i2c -> OAR1 = 1 << 14 | addr << 1 ;
34
40
i2c -> OAR2 = 0 ;
35
41
i2c -> CR1 = I2C_CR1_ACK | I2C_CR1_PE ;
36
42
}
37
43
38
44
void i2c_slave_irq_handler (i2c_slave_t * i2c ) {
39
45
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
+ }
40
54
if (sr1 & I2C_SR1_ADDR ) {
41
55
// Address matched
42
56
// Read of SR1, SR2 needed to clear ADDR bit
You can’t perform that action at this time.
0 commit comments