/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
*
© Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "string.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;
UART_HandleTypeDef huart2;
unsigned char buf[1];
uint8_t buffer[5];
char temp_int;
char temp_frac;
int temperature;
uint32_t rawIRValue;
uint32_t rawRedValue;
const int avgAmount=64;
int baseValue=0;
int x=0;
int16_t an_x[100];
int32_t n_denom;
/*
int16_t IR_AC_Max=20;
int16_t IR_AC_Min=-20;
int16_t IR_AC_Signal_Current = 0;
int16_t IR_AC_Signal_Previous = 0;
int16_t IR_AC_Signal_min = 0;
int16_t IR_AC_Signal_max = 0;
int16_t IR_Average_Estomated;
int16_t positiveEdge=0;
int16_t negativeEdge=0;
int16_t ir_avg_reg=0;
int16_t cbuf[32];
uint8_t offset =0;
static const uint16_t FIRCoeffs[12]= {172, 321, 579, 927, 1360, 1858, 2390, 2916, 3391, 3768, 4012, 4096};
*/
uint32_t un_ir_mean, n_ir_buffer_length;
int32_t k;
int dcIR, olddcIR, filteredIRValue;
int dcRed, olddcRed, filteredRedValue;
int v1[2], lpFiltered1;
int values[6], sum, avg, result;
char count, inde;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_I2C1_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
// RedLED Pulse Amplitude
RedLEDPulseAmpl();
// IR Pulse Amplitude
IRPulseAmpl();
//Setting Mode HR and SPO2
Mode();
//INITFIFO
INITFIFO();
//FIFOConfig
FIFOConfig();
//SPO2 Mode Config
SPO2config();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
GetRAWDATA();
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
//Average of IR
for (x=0; x