view Small_CPU/Src/uart.c @ 475:4b000e2386c2 Improve_Button_Sleep

Changed default values: Invalid pressure was signalled using the float 100.0 causing the OSTC to enter dive mode if for some I2C communication was disturbed during startup. The default value for button responsitivness was set to 85% without considering the needed HWOS transformation calculation. Applying that the value for 85% is 51 PowerOnReset is state is now identified using the same functionality as already introduced for the battery charge handling. Initialization of pressure sensor in case of I2C problems only if the initialization was not successfull before: The pressure sensor is reset via a I2C commend in case of a I2C error. A reset might be helpfull in case of a "hanging" ADC operation but that would not be indicated by a I2C problem => resetting the sensor in case of a I2C problem might cause (small) change of pressure value
author ideenmodellierer
date Tue, 12 May 2020 22:52:05 +0200
parents 5f11787b4f42
children 1b995079c045
line wrap: on
line source

/**
  ******************************************************************************
  * @file    uart.c 
  * @author  heinrichs weikamp gmbh
  * @version V0.0.1
  * @date    27-March-2014
  * @brief   button control
  *           
  @verbatim                 
  ============================================================================== 
                        ##### How to use #####
  ============================================================================== 
  @endverbatim
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
  *
  ******************************************************************************
  */ 
/* Includes ------------------------------------------------------------------*/
#include "uart.h"

/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef huart2;


/* Exported functions --------------------------------------------------------*/

void MX_USART2_UART_Init(void)
{
/* pullup special */
  GPIO_InitTypeDef   GPIO_InitStructure;
  __GPIOA_CLK_ENABLE();
  GPIO_InitStructure.Pin = GPIO_PIN_2;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); 

/* regular init */	
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 1200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  HAL_UART_Init(&huart2);
}


uint8_t UART_ButtonAdjust(uint8_t *array)
{
	uint8_t answer[4];
	
	HAL_UART_Transmit(&huart2,array,4,1000);
	HAL_UART_Receive(&huart2,answer,4,2000);
	if(	(answer[0] == array[0])
		&&(answer[1] == array[1])
		&&(answer[2] == array[2])
		&&(answer[3] == array[3]))
	return 1;
	else
	return 0;
}

void MX_USART2_UART_DeInit(void)
{
	HAL_UART_DeInit(&huart2);
}


/************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/