Revision b4885314 boards/DiWheelDrive/board.c
boards/DiWheelDrive/board.c | ||
---|---|---|
96 | 96 |
palSetPad(GPIOC, GPIOC_SYS_PD_N); |
97 | 97 |
} |
98 | 98 |
|
99 |
inline void boardClearI2CBus(const uint8_t scl_pad) { |
|
99 |
inline void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad) {
|
|
100 | 100 |
|
101 | 101 |
uint8_t i; |
102 | 102 |
|
103 |
// configure I²C SCL open drain |
|
103 |
// configure I²C SCL and SDA open drain
|
|
104 | 104 |
palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN); |
105 |
palSetPadMode(GPIOB, sda_pad, PAL_MODE_OUTPUT_OPENDRAIN); |
|
105 | 106 |
|
106 |
// perform bus clear as per I²C Specification v5 3.1.16 |
|
107 |
for (i = 0x00u; i < 0x09u; i++) { |
|
107 |
// perform a 2-wire software reset for the eeprom (see AT24C01BN-SH-B datasheet, chapter 3) |
|
108 |
// note: clock is ~50kHz (20us per cycle) |
|
109 |
palSetPad(GPIOB, sda_pad); |
|
110 |
palClearPad(GPIOB, scl_pad); |
|
111 |
chThdSleepMicroseconds(10); |
|
112 |
palSetPad(GPIOB, scl_pad); |
|
113 |
chThdSleepMicroseconds(5); |
|
114 |
palClearPad(GPIOB, sda_pad); |
|
115 |
chThdSleepMicroseconds(5); |
|
116 |
palClearPad(GPIOB, scl_pad); |
|
117 |
chThdSleepMicroseconds(5); |
|
118 |
palSetPad(GPIOB, sda_pad); |
|
119 |
chThdSleepMicroseconds(5); |
|
120 |
for (i = 0; i < 9; ++i) { |
|
121 |
palSetPad(GPIOB, scl_pad); |
|
122 |
chThdSleepMicroseconds(10); |
|
123 |
palClearPad(GPIOB, scl_pad); |
|
124 |
chThdSleepMicroseconds(10); |
|
125 |
} |
|
126 |
palSetPad(GPIOB, scl_pad); |
|
127 |
chThdSleepMicroseconds(5); |
|
128 |
palClearPad(GPIOB, sda_pad); |
|
129 |
chThdSleepMicroseconds(5); |
|
130 |
palClearPad(GPIOB, scl_pad); |
|
131 |
chThdSleepMicroseconds(10); |
|
132 |
palSetPad(GPIOB, scl_pad); |
|
133 |
chThdSleepMicroseconds(5); |
|
134 |
palSetPad(GPIOB, sda_pad); |
|
135 |
chThdSleepMicroseconds(5); |
|
136 |
palClearPad(GPIOB, scl_pad); |
|
137 |
chThdSleepMicroseconds(10); |
|
138 |
|
|
139 |
// perform bus clear as per I²C Specification v6 3.1.16 |
|
140 |
// note: clock is 100kHz (10us per cycle) |
|
141 |
for (i = 0; i < 10; i++) { |
|
108 | 142 |
palClearPad(GPIOB, scl_pad); |
109 | 143 |
chThdSleepMicroseconds(5); |
110 | 144 |
palSetPad(GPIOB, scl_pad); |
... | ... | |
113 | 147 |
|
114 | 148 |
// reconfigure I²C SCL |
115 | 149 |
palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); |
150 |
palSetPadMode(GPIOB, sda_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); |
|
116 | 151 |
|
152 |
return; |
|
117 | 153 |
} |
Also available in: Unified diff