You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For chips other than the CH32V003 you will need to change the pin numbers to the pins corresponding with the I2C1 peripheral. If you want to use the alternative pins for the I2C periperal in addition to configuring the pins you have to configure the chip to use the the alternative pins using the `I2C1_RM` and `I2C1REMAP1` fields of the `AFIO_PCFR1` register.
23
+
For chips other than the CH32V003 you should change the above pin numbers to the pins corresponding with the I2C1 peripheral.
24
+
25
+
## Alternate Pins
26
+
27
+
Optional: If you want to use alternative pins for the I2C periperal, then you must take an additional step to configure the chip to use one of the 2 alternative pin mappings.
28
+
29
+
You can do this using the `I2C1_RM` and `I2C1REMAP1` fields of the `AFIO_PCFR1` register.
30
+
31
+
Remapping examples:
32
+
33
+
```c++
34
+
// 2 bits [bit 22 and bit 1] of AFIO_PCFR1 register are what control I2C1 pin remapping on ch32v003
35
+
// [high bit, low bit]
36
+
// [I2C1REMAP1, I2C1_RM]
37
+
38
+
// [0, 0] default mapping (SCL on pin PC2, SDA on pin PC1)
39
+
// (note: you don't need to do this, since it's the defualt:)
40
+
AFIO->PCFR1 &= ~AFIO_PCFR1_I2C1_HIGH_BIT_REMAP; // set high bit = 0 (I2C1REMAP1)
41
+
AFIO->PCFR1 &= ~AFIO_PCFR1_I2C1_REMAP; // set low bit = 0 (I2C1_RM)
42
+
43
+
// [0, 1]: Remapping option #1 (SCL on pin PD1, SDA on pin PD0)
44
+
AFIO->PCFR1 &= ~AFIO_PCFR1_I2C1_HIGH_BIT_REMAP; // set high bit = 0 (I2C1REMAP1)
45
+
AFIO->PCFR1 |= AFIO_PCFR1_I2C1_REMAP; // set low bit = 1 (I2C1_RM)
46
+
47
+
// [1, X]: Remapping option #2 (SCL on pin PC5, SDA on pin PC6)
48
+
AFIO->PCFR1 |= AFIO_PCFR1_I2C1_HIGH_BIT_REMAP; // set high bit = 1 (I2C1REMAP1)
49
+
AFIO->PCFR1 |= AFIO_PCFR1_I2C1_REMAP; // set low bit [ignored / don't care] (I2C1_RM)
50
+
```
51
+
52
+
## Initialization
20
53
21
-
Then initialize the I2C1 peripheral in slave mode using:
54
+
Initialize the I2C1 peripheral in slave mode using:
0 commit comments