Subversion Repositories dashGPS

Rev

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

Rev 9 Rev 11
Line 21... Line 21...
21
#include "main.h"
21
#include "main.h"
22
 
22
 
23
/* Private includes ----------------------------------------------------------*/
23
/* Private includes ----------------------------------------------------------*/
24
/* USER CODE BEGIN Includes */
24
/* USER CODE BEGIN Includes */
25
#include "libSerial/serial.h"
25
#include "libSerial/serial.h"
26
 
-
 
-
 
26
#include "libBMP280/bmp280.h"
27
#include "display.h"
27
#include "display.h"
28
/* USER CODE END Includes */
28
/* USER CODE END Includes */
29
 
29
 
30
/* Private typedef -----------------------------------------------------------*/
30
/* Private typedef -----------------------------------------------------------*/
31
/* USER CODE BEGIN PTD */
31
/* USER CODE BEGIN PTD */
Line 42... Line 42...
42
/* USER CODE END PM */
42
/* USER CODE END PM */
43
 
43
 
44
/* Private variables ---------------------------------------------------------*/
44
/* Private variables ---------------------------------------------------------*/
45
CAN_HandleTypeDef hcan;
45
CAN_HandleTypeDef hcan;
46
 
46
 
-
 
47
I2C_HandleTypeDef hi2c2;
-
 
48
 
47
SPI_HandleTypeDef hspi1;
49
SPI_HandleTypeDef hspi1;
48
 
50
 
49
TIM_HandleTypeDef htim3;
51
TIM_HandleTypeDef htim3;
50
TIM_HandleTypeDef htim4;
52
TIM_HandleTypeDef htim4;
51
 
53
 
52
UART_HandleTypeDef huart1;
54
UART_HandleTypeDef huart1;
53
 
55
 
54
/* USER CODE BEGIN PV */
56
/* USER CODE BEGIN PV */
-
 
57
typedef struct
-
 
58
{
-
 
59
  uint8_t dev_addr;
-
 
60
} interface_t;
-
 
61
 
-
 
62
static int8_t
-
 
63
user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t len)
-
 
64
{
-
 
65
    HAL_StatusTypeDef st = HAL_I2C_Mem_Write(&hi2c2, i2c_addr<<1, reg_addr, 1, reg_data, len, 10000);
-
 
66
 
-
 
67
  return st != HAL_OK ?  BMP280_E_COMM_FAIL: BMP280_OK;
-
 
68
 
-
 
69
}
-
 
70
static int8_t
-
 
71
user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint32_t len)
-
 
72
{
-
 
73
  HAL_StatusTypeDef st = HAL_I2C_Mem_Read(&hi2c2, i2c_addr<<1, reg_addr, 1, reg_data, len, 10000);
-
 
74
 
-
 
75
  return st != HAL_OK ?  BMP280_E_COMM_FAIL: BMP280_OK;
-
 
76
 
-
 
77
}
-
 
78
 
-
 
79
static void
-
 
80
user_delay_ms (uint32_t ms, void *handle)
-
 
81
{
-
 
82
  HAL_Delay (ms);
-
 
83
 
-
 
84
}
-
 
85
 
-
 
86
 
-
 
87
 
-
 
88
 
-
 
89
struct bmp280_dev bmp =
-
 
90
  {
-
 
91
 
-
 
92
  .intf = BMP280_I2C_INTF, .read = user_i2c_read, .write = user_i2c_write,
-
 
93
      .delay_ms = user_delay_ms,
-
 
94
 
-
 
95
      /* Update interface pointer with the structure that contains both device address and file descriptor */
-
 
96
     .dev_id =  BMP280_I2C_ADDR_PRIM };
-
 
97
 
-
 
98
int8_t rslt;
-
 
99
struct bmp280_config conf;
-
 
100
 
55
 
101
 
56
/* USER CODE END PV */
102
/* USER CODE END PV */
57
 
103
 
58
/* Private function prototypes -----------------------------------------------*/
104
/* Private function prototypes -----------------------------------------------*/
59
void SystemClock_Config(void);
105
void SystemClock_Config(void);
Line 61... Line 107...
61
static void MX_CAN_Init(void);
107
static void MX_CAN_Init(void);
62
static void MX_SPI1_Init(void);
108
static void MX_SPI1_Init(void);
63
static void MX_TIM4_Init(void);
109
static void MX_TIM4_Init(void);
64
static void MX_USART1_UART_Init(void);
110
static void MX_USART1_UART_Init(void);
65
static void MX_TIM3_Init(void);
111
static void MX_TIM3_Init(void);
-
 
112
static void MX_I2C2_Init(void);
66
/* USER CODE BEGIN PFP */
113
/* USER CODE BEGIN PFP */
67
 
114
 
68
/* USER CODE END PFP */
115
/* USER CODE END PFP */
69
 
116
 
70
/* Private user code ---------------------------------------------------------*/
117
/* Private user code ---------------------------------------------------------*/
Line 103... Line 150...
103
  MX_CAN_Init();
150
  MX_CAN_Init();
104
  MX_SPI1_Init();
151
  MX_SPI1_Init();
105
  MX_TIM4_Init();
152
  MX_TIM4_Init();
106
  MX_USART1_UART_Init();
153
  MX_USART1_UART_Init();
107
  MX_TIM3_Init();
154
  MX_TIM3_Init();
-
 
155
  MX_I2C2_Init();
108
  /* USER CODE BEGIN 2 */
156
  /* USER CODE BEGIN 2 */
109
  __HAL_RCC_USART1_CLK_ENABLE();
157
  __HAL_RCC_USART1_CLK_ENABLE();
110
  /* setup the USART control blocks */
158
  /* setup the USART control blocks */
111
  init_usart_ctl (&uc1, huart1.Instance);
159
  init_usart_ctl (&uc1, &huart1);
112
 
160
 
113
  EnableSerialRxInterrupt (&uc1);
161
  EnableSerialRxInterrupt (&uc1);
114
 
162
 
-
 
163
 
-
 
164
  /* Initialize the bmp280 */
-
 
165
  rslt = bmp280_init(&bmp);
-
 
166
//  print_rslt(" bmp280_init status", rslt);
-
 
167
 
-
 
168
  /* Always read the current settings before writing, especially when
-
 
169
   * all the configuration is not modified
-
 
170
   */
-
 
171
  rslt = bmp280_get_config(&conf, &bmp);
-
 
172
 // print_rslt(" bmp280_get_config status", rslt);
-
 
173
 
-
 
174
  /* configuring the temperature oversampling, filter coefficient and output data rate */
-
 
175
  /* Overwrite the desired settings */
-
 
176
  conf.filter = BMP280_FILTER_COEFF_2;
-
 
177
 
-
 
178
  /* Temperature oversampling set at 4x */
-
 
179
  conf.os_temp = BMP280_OS_4X;
-
 
180
 
-
 
181
  /* Pressure over sampling none (disabling pressure measurement) */
-
 
182
  conf.os_pres = BMP280_OS_4X;
-
 
183
 
-
 
184
  /* Setting the output data rate as 1HZ(1000ms) */
-
 
185
  conf.odr = BMP280_ODR_1000_MS;
-
 
186
  rslt = bmp280_set_config(&conf, &bmp);
-
 
187
  //print_rslt(" bmp280_set_config status", rslt);
-
 
188
 
-
 
189
  /* Always set the power mode after setting the configuration */
-
 
190
  rslt = bmp280_set_power_mode(BMP280_NORMAL_MODE, &bmp);
-
 
191
  //print_rslt(" bmp280_set_power_mode status", rslt);
-
 
192
 
-
 
193
 
-
 
194
 
115
  cc_init ();
195
  cc_init ();
116
  HAL_Delay (1000);
-
 
117
  /* USER CODE END 2 */
196
  /* USER CODE END 2 */
118
 
197
 
119
  /* Infinite loop */
198
  /* Infinite loop */
120
  /* USER CODE BEGIN WHILE */
199
  /* USER CODE BEGIN WHILE */
121
  while (1)
200
  while (1)
122
    {
201
    {
123
      cc_run ();
202
      cc_run (&bmp);
124
 
-
 
125
 
203
 
126
      HAL_Delay (50);
204
      HAL_Delay (50);
127
 
205
 
128
    /* USER CODE END WHILE */
206
    /* USER CODE END WHILE */
129
 
207
 
Line 206... Line 284...
206
  /* USER CODE END CAN_Init 2 */
284
  /* USER CODE END CAN_Init 2 */
207
 
285
 
208
}
286
}
209
 
287
 
210
/**
288
/**
-
 
289
  * @brief I2C2 Initialization Function
-
 
290
  * @param None
-
 
291
  * @retval None
-
 
292
  */
-
 
293
static void MX_I2C2_Init(void)
-
 
294
{
-
 
295
 
-
 
296
  /* USER CODE BEGIN I2C2_Init 0 */
-
 
297
 
-
 
298
  /* USER CODE END I2C2_Init 0 */
-
 
299
 
-
 
300
  /* USER CODE BEGIN I2C2_Init 1 */
-
 
301
 
-
 
302
  /* USER CODE END I2C2_Init 1 */
-
 
303
  hi2c2.Instance = I2C2;
-
 
304
  hi2c2.Init.ClockSpeed = 100000;
-
 
305
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
-
 
306
  hi2c2.Init.OwnAddress1 = 0;
-
 
307
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
-
 
308
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
-
 
309
  hi2c2.Init.OwnAddress2 = 0;
-
 
310
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
-
 
311
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
-
 
312
  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
-
 
313
  {
-
 
314
    Error_Handler();
-
 
315
  }
-
 
316
  /* USER CODE BEGIN I2C2_Init 2 */
-
 
317
 
-
 
318
  /* USER CODE END I2C2_Init 2 */
-
 
319
 
-
 
320
}
-
 
321
 
-
 
322
/**
211
  * @brief SPI1 Initialization Function
323
  * @brief SPI1 Initialization Function
212
  * @param None
324
  * @param None
213
  * @retval None
325
  * @retval None
214
  */
326
  */
215
static void MX_SPI1_Init(void)
327
static void MX_SPI1_Init(void)