Configuring sensor
This commit is contained in:
parent
a56804ec46
commit
ee42fc0bbc
1 changed files with 52 additions and 6 deletions
58
Src/main.c
58
Src/main.c
|
@ -18,6 +18,7 @@
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "sensor_registers.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
@ -62,6 +63,49 @@ static void MX_I2C1_Init(void);
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
typedef struct config_s {
|
||||||
|
const uint8_t address;
|
||||||
|
const uint8_t write_read;
|
||||||
|
uint8_t command[2];
|
||||||
|
} Config;
|
||||||
|
|
||||||
|
void configure_sensor() {
|
||||||
|
const uint16_t size_msg = 2; {
|
||||||
|
const uint8_t wakeup_cmd = 1;
|
||||||
|
const uint8_t data[] = { config_reg, wakeup_cmd };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { mbit_trim_reg, 0x0C };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { bias_trim_top_reg, 0x0C };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { bias_trim_bot_reg, 0x0C };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { clk_trim_reg, 0x14 };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { bpa_trim_top_reg, 0x0C };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { bpa_trim_bot_reg, 0x0C };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6); {
|
||||||
|
const uint8_t data[] = { pu_reg, 0x88 };
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, data, size_msg, 6);
|
||||||
|
}
|
||||||
|
HAL_Delay(6);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
|
@ -91,6 +135,14 @@ int main(void) {
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_I2C1_Init();
|
MX_I2C1_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
// TODO: configs
|
||||||
|
configure_sensor(); {
|
||||||
|
uint8_t data = status_reg;
|
||||||
|
uint8_t received_data = 0;
|
||||||
|
HAL_I2C_Master_Transmit(&hi2c1, sensor_addr, &data, 1, 5);
|
||||||
|
HAL_Delay(30);
|
||||||
|
HAL_I2C_Master_Receive(&hi2c1, sensor_addr | 1, &received_data, 1, 5);
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
@ -106,7 +158,6 @@ int main(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void) {
|
void SystemClock_Config(void) {
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
||||||
|
@ -146,8 +197,6 @@ void SystemClock_Config(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief I2C1 Initialization Function
|
* @brief I2C1 Initialization Function
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
*/
|
||||||
static void MX_I2C1_Init(void) {
|
static void MX_I2C1_Init(void) {
|
||||||
/* USER CODE BEGIN I2C1_Init 0 */
|
/* USER CODE BEGIN I2C1_Init 0 */
|
||||||
|
@ -188,8 +237,6 @@ static void MX_I2C1_Init(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO Initialization Function
|
* @brief GPIO Initialization Function
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
*/
|
||||||
static void MX_GPIO_Init(void) {
|
static void MX_GPIO_Init(void) {
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
@ -208,7 +255,6 @@ static void MX_GPIO_Init(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void) {
|
void Error_Handler(void) {
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
|
Loading…
Add table
Reference in a new issue