Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 30 | Rev 31 | ||
---|---|---|---|
Line 130... | Line 130... | ||
130 | .read = user_i2c2_read, |
130 | .read = user_i2c2_read, |
131 | .write = user_i2c2_write, |
131 | .write = user_i2c2_write, |
132 | .delay_ms = user_delay_ms, |
132 | .delay_ms = user_delay_ms, |
133 | 133 | ||
134 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
134 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
135 | .dev_id = BMP280_I2C_ADDR_PRIM |
135 | .dev_id = BMP280_I2C_ADDR_SEC |
136 | }; |
136 | }; |
137 | 137 | ||
138 | int8_t rslt; |
138 | int8_t rslt; |
139 | 139 | ||
140 | 140 | ||
Line 194... | Line 194... | ||
194 | if (rslt != BMP280_OK) |
194 | if (rslt != BMP280_OK) |
195 | return rslt; |
195 | return rslt; |
196 | 196 | ||
197 | } |
197 | } |
198 | 198 | ||
- | 199 | ||
- | 200 | /////////////////////////////////////// |
|
- | 201 | // code dealing with I2C1 |
|
199 | static void reset_I2C1(void) |
202 | static void reset_I2C1(void) |
200 | { |
203 | { |
201 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
204 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
202 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_8, GPIO_PIN_SET); |
205 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_8, GPIO_PIN_SET); |
203 | __HAL_AFIO_REMAP_I2C1_DISABLE(); |
206 | __HAL_AFIO_REMAP_I2C1_DISABLE(); |
Line 212... | Line 215... | ||
212 | } |
215 | } |
213 | __HAL_AFIO_REMAP_I2C1_ENABLE(); |
216 | __HAL_AFIO_REMAP_I2C1_ENABLE(); |
214 | 217 | ||
215 | } |
218 | } |
216 | 219 | ||
- | 220 | // the bus power also takes down the pullup power |
|
- | 221 | static void power_I2C1(uint8_t power) |
|
- | 222 | { |
|
- | 223 | if(power) |
|
- | 224 | { |
|
- | 225 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
|
- | 226 | } |
|
- | 227 | else |
|
- | 228 | { |
|
- | 229 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_RESET); |
|
- | 230 | } |
|
- | 231 | } |
|
- | 232 | ||
- | 233 | typedef enum |
|
- | 234 | { |
|
- | 235 | BMP_NORMAL, // normal operations |
|
- | 236 | BMP_RESET_ACTIVE, // powering down |
|
- | 237 | BMP_PAUSE // pause after powerup |
|
- | 238 | } bmp2state_t; |
|
- | 239 | ||
- | 240 | bmp2state_t bmp2state; |
|
- | 241 | unsigned bmp2nextTime; |
|
- | 242 | unsigned bmp2offset; |
|
- | 243 | ||
217 | void resetBmp2(void) |
244 | void initBmp2(void) |
218 | { |
245 | { |
219 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_RESET); |
- | |
220 | HAL_Delay (400); |
- | |
221 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
- | |
222 | HAL_Delay (200); |
246 | power_I2C1(1); |
223 | init_bmp(&conf2,&bmp2); |
247 | init_bmp(&conf2,&bmp2); |
- | 248 | bmp2state = BMP_NORMAL; |
|
- | 249 | bmp2nextTime = 0; |
|
- | 250 | bmp2offset = 0; |
|
- | 251 | } |
|
- | 252 | ||
- | 253 | void resetBmp2(void) |
|
- | 254 | { |
|
- | 255 | reset_I2C1(); // physically reset the hardware |
|
- | 256 | power_I2C1(0); // power down the bus and devices |
|
- | 257 | bmp2nextTime = HAL_GetTick(); // 600 milliseconds hold the bus reset for |
|
- | 258 | bmp2offset = 600; |
|
- | 259 | bmp2state = BMP_RESET_ACTIVE; |
|
- | 260 | } |
|
- | 261 | ||
- | 262 | uint8_t pollBmp2State(void) |
|
- | 263 | { |
|
- | 264 | if (bmp2state == BMP_NORMAL) |
|
- | 265 | return 1; |
|
224 | 266 | ||
- | 267 | if (HAL_GetTick()-bmp2offset < bmp2nextTime) |
|
- | 268 | return 0; // currently timer running |
|
- | 269 | switch (bmp2state) |
|
- | 270 | { |
|
- | 271 | // at the end of the period, take action |
|
- | 272 | case BMP_RESET_ACTIVE: |
|
- | 273 | power_I2C1(1); |
|
- | 274 | bmp2nextTime = HAL_GetTick(); |
|
- | 275 | bmp2offset = 200; // power up and wait for 200 milliseconds |
|
- | 276 | bmp2state = BMP_PAUSE; |
|
- | 277 | break; |
|
- | 278 | case BMP_PAUSE: |
|
- | 279 | init_bmp(&conf2,&bmp2); |
|
- | 280 | bmp2state = BMP_NORMAL; |
|
- | 281 | return 1; // now in normal operation |
|
- | 282 | // can not get here in normal operation |
|
- | 283 | case BMP_NORMAL: |
|
- | 284 | return 1; |
|
- | 285 | } |
|
- | 286 | return 0; |
|
225 | } |
287 | } |
226 | 288 | ||
227 | 289 | ||
- | 290 | ||
228 | /* USER CODE END 0 */ |
291 | /* USER CODE END 0 */ |
229 | 292 | ||
230 | /** |
293 | /** |
231 | * @brief The application entry point. |
294 | * @brief The application entry point. |
232 | * @retval int |
295 | * @retval int |
Line 278... | Line 341... | ||
278 | EnableSerialRxInterrupt (&uc1); |
341 | EnableSerialRxInterrupt (&uc1); |
279 | 342 | ||
280 | #endif |
343 | #endif |
281 | 344 | ||
282 | init_bmp(&conf,&bmp); |
345 | init_bmp(&conf,&bmp); |
283 | init_bmp(&conf2,&bmp2); |
346 | initBmp2(); |
284 | 347 | ||
285 | cc_init (); |
348 | cc_init (); |
286 | 349 | ||
287 | 350 | ||
288 | uint32_t timeNext = HAL_GetTick () + TICKS_LOOP; |
351 | uint32_t timeNext = HAL_GetTick () + TICKS_LOOP; |