Subversion Repositories dashGPS

Rev

Rev 27 | Rev 29 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 28
Line 41... Line 41...
41
/* USER CODE BEGIN PM */
41
/* USER CODE BEGIN PM */
42
 
42
 
43
/* USER CODE END PM */
43
/* USER CODE END PM */
44
 
44
 
45
/* Private variables ---------------------------------------------------------*/
45
/* Private variables ---------------------------------------------------------*/
-
 
46
I2C_HandleTypeDef hi2c1;
46
I2C_HandleTypeDef hi2c2;
47
I2C_HandleTypeDef hi2c2;
47
 
48
 
48
IWDG_HandleTypeDef hiwdg;
49
IWDG_HandleTypeDef hiwdg;
49
 
50
 
50
RTC_HandleTypeDef hrtc;
51
RTC_HandleTypeDef hrtc;
Line 65... Line 66...
65
static int8_t
66
static int8_t
66
user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
67
user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
67
                uint32_t len)
68
                uint32_t len)
68
{
69
{
69
  HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c2, i2c_addr << 1, reg_addr, 1,
70
  HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c2, i2c_addr << 1, reg_addr, 1,
70
                                            reg_data, len, 10000);
71
                                            reg_data, len, 1000);
71
 
72
 
72
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
73
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
73
 
74
 
74
}
75
}
75
static int8_t
76
static int8_t
76
user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
77
user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
77
               uint32_t len)
78
               uint32_t len)
78
{
79
{
79
  HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c2, i2c_addr << 1, reg_addr, 1,
80
  HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c2, i2c_addr << 1, reg_addr, 1,
80
                                           reg_data, len, 10000);
81
                                           reg_data, len, 1000);
81
 
82
 
82
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
83
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
83
 
84
 
84
}
85
}
-
 
86
// the second I2C bus is I2C1, this is used for the external I2C thermometer to avoid problems with noise pickup .
-
 
87
static int8_t
-
 
88
user_i2c2_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
-
 
89
                uint32_t len)
-
 
90
{
-
 
91
  HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c1, i2c_addr << 1, reg_addr, 1,
-
 
92
                                            reg_data, len, 1000);
-
 
93
 
-
 
94
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
-
 
95
 
-
 
96
}
-
 
97
static int8_t
-
 
98
user_i2c2_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data,
-
 
99
               uint32_t len)
-
 
100
{
-
 
101
  HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c1, i2c_addr << 1, reg_addr, 1,
-
 
102
                                           reg_data, len, 1000);
-
 
103
 
-
 
104
  return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK;
-
 
105
 
-
 
106
}
-
 
107
 
-
 
108
static void reset_i2c2(void)
-
 
109
{
-
 
110
 
-
 
111
 
-
 
112
 
-
 
113
 
-
 
114
 
-
 
115
}
85
 
116
 
86
static void
117
static void
87
user_delay_ms (uint32_t ms, void *handle)
118
user_delay_ms (uint32_t ms, void *handle)
88
{
119
{
89
  HAL_Delay (ms);
120
  HAL_Delay (ms);
Line 102... Line 133...
102
  };
133
  };
103
 
134
 
104
struct bmp280_dev bmp2 =
135
struct bmp280_dev bmp2 =
105
  {
136
  {
106
  .intf = BMP280_I2C_INTF,
137
  .intf = BMP280_I2C_INTF,
107
  .read = user_i2c_read,
138
  .read = user_i2c2_read,
108
  .write = user_i2c_write,
139
  .write = user_i2c2_write,
109
  .delay_ms = user_delay_ms,
140
  .delay_ms = user_delay_ms,
110
 
141
 
111
  /* Update interface pointer with the structure that contains both device address and file descriptor */
142
  /* Update interface pointer with the structure that contains both device address and file descriptor */
112
  .dev_id = BMP280_I2C_ADDR_SEC
143
  .dev_id = BMP280_I2C_ADDR_PRIM
113
  };
144
  };
114
 
145
 
115
int8_t rslt;
146
int8_t rslt;
116
 
147
 
117
 
148
 
Line 128... Line 159...
128
static void MX_USART1_UART_Init(void);
159
static void MX_USART1_UART_Init(void);
129
static void MX_TIM3_Init(void);
160
static void MX_TIM3_Init(void);
130
static void MX_I2C2_Init(void);
161
static void MX_I2C2_Init(void);
131
static void MX_RTC_Init(void);
162
static void MX_RTC_Init(void);
132
static void MX_IWDG_Init(void);
163
static void MX_IWDG_Init(void);
-
 
164
static void MX_I2C1_Init(void);
133
/* USER CODE BEGIN PFP */
165
/* USER CODE BEGIN PFP */
134
 
166
 
135
/* USER CODE END PFP */
167
/* USER CODE END PFP */
136
 
168
 
137
/* Private user code ---------------------------------------------------------*/
169
/* Private user code ---------------------------------------------------------*/
Line 170... Line 202...
170
  if (rslt != BMP280_OK)
202
  if (rslt != BMP280_OK)
171
    return rslt;
203
    return rslt;
172
 
204
 
173
}
205
}
174
 
206
 
-
 
207
static void reset_I2C1(void)
-
 
208
{
-
 
209
  HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
-
 
210
  HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_8, GPIO_PIN_SET);
-
 
211
  __HAL_AFIO_REMAP_I2C1_DISABLE();
-
 
212
  int i;
-
 
213
  // clock 18 times
-
 
214
  for (i=0;i<18;++i)
-
 
215
    {
-
 
216
     HAL_Delay (1);
-
 
217
     HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
-
 
218
     HAL_Delay (1);
-
 
219
     HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
-
 
220
    }
-
 
221
   __HAL_AFIO_REMAP_I2C1_ENABLE();
-
 
222
 
-
 
223
}
175
 
224
 
176
 
225
 
177
 
226
 
178
 
227
 
179
/* USER CODE END 0 */
228
/* USER CODE END 0 */
Line 212... Line 261...
212
  MX_TIM3_Init();
261
  MX_TIM3_Init();
213
  MX_I2C2_Init();
262
  MX_I2C2_Init();
214
  MX_RTC_Init();
263
  MX_RTC_Init();
215
  MX_USB_DEVICE_Init();
264
  MX_USB_DEVICE_Init();
216
  MX_IWDG_Init();
265
  MX_IWDG_Init();
-
 
266
  MX_I2C1_Init();
217
  /* USER CODE BEGIN 2 */
267
  /* USER CODE BEGIN 2 */
218
 
268
 
219
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET);
269
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET);
220
  HAL_Delay (1000);
270
  HAL_Delay (1000);
221
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET);
271
  HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET);
222
 
-
 
223
  /* setup the USART control blocks */
272
  /* setup the USART control blocks */
224
 
273
 
225
#if defined SERIAL_UART1
274
#if defined SERIAL_UART1
226
  init_usart_ctl (&uc1, &huart1);
275
  init_usart_ctl (&uc1, &huart1);
227
 
276
 
Line 310... Line 359...
310
    Error_Handler();
359
    Error_Handler();
311
  }
360
  }
312
}
361
}
313
 
362
 
314
/**
363
/**
-
 
364
  * @brief I2C1 Initialization Function
-
 
365
  * @param None
-
 
366
  * @retval None
-
 
367
  */
-
 
368
static void MX_I2C1_Init(void)
-
 
369
{
-
 
370
 
-
 
371
  /* USER CODE BEGIN I2C1_Init 0 */
-
 
372
 
-
 
373
  /* USER CODE END I2C1_Init 0 */
-
 
374
 
-
 
375
  /* USER CODE BEGIN I2C1_Init 1 */
-
 
376
 
-
 
377
  /* USER CODE END I2C1_Init 1 */
-
 
378
  hi2c1.Instance = I2C1;
-
 
379
  hi2c1.Init.ClockSpeed = 100000;
-
 
380
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
-
 
381
  hi2c1.Init.OwnAddress1 = 0;
-
 
382
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
-
 
383
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
-
 
384
  hi2c1.Init.OwnAddress2 = 0;
-
 
385
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
-
 
386
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
-
 
387
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
-
 
388
  {
-
 
389
    Error_Handler();
-
 
390
  }
-
 
391
  /* USER CODE BEGIN I2C1_Init 2 */
-
 
392
 
-
 
393
  /* USER CODE END I2C1_Init 2 */
-
 
394
 
-
 
395
}
-
 
396
 
-
 
397
/**
315
  * @brief I2C2 Initialization Function
398
  * @brief I2C2 Initialization Function
316
  * @param None
399
  * @param None
317
  * @retval None
400
  * @retval None
318
  */
401
  */
319
static void MX_I2C2_Init(void)
402
static void MX_I2C2_Init(void)