Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file : main.c
- * @brief : Main program body
- ******************************************************************************
- ** This notice applies to any and all portions of this file
- * that are not between comment pairs USER CODE BEGIN and
- * USER CODE END. Other portions of this file, whether
- * inserted by the user or by software development tools
- * are owned by their respective copyright owners.
- *
- * COPYRIGHT(c) 2019 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "stm32f1xx_hal.h"
- #include "stm32f1xx_it.h"
- /* USER CODE BEGIN Includes */
- #include "inttypes.h"
- #include "i2c-lcd.h"
- #include "string.h"
- #include <stdbool.h>
- /* USER CODE END Includes */
- /* Private variables ---------------------------------------------------------*/
- I2C_HandleTypeDef hi2c1;
- TIM_HandleTypeDef htim4;
- UART_HandleTypeDef huart1;
- UART_HandleTypeDef huart2;
- /* USER CODE BEGIN PV */
- /* Private variables ---------------------------------------------------------*/
- bool sel_USART_send = false; // true=raw, false=string
- uint8_t buffer_USART2_tx[10];
- uint8_t buffer_USART2_rx[10];
- uint8_t buffer_USART1_rx[10];
- uint32_t water_level,input_flw_int,output_flw_int=0;
- uint32_t target_level_pi=0;
- uint32_t target_level_kp=0;
- uint32_t input_flow_cnt,output_flow_cnt=0;
- uint32_t sys_timer=0;
- float input_flow,output_flow=0;
- char cast_buff [10];
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_USART1_UART_Init(void);
- static void MX_USART2_UART_Init(void);
- static void MX_TIM4_Init(void);
- static void MX_I2C1_Init(void);
- static void MX_NVIC_Init(void);
- /* USER CODE BEGIN PFP */
- /* Private function prototypes -----------------------------------------------*/
- char* concat(const char *s1, const char *s2);
- uint8_t KeypadGetKey(void); // Get KEY value from MATRIX KEYPAD
- uint32_t getUSART1(void); // Get WATER_LEVEL from SLAVE STM32
- uint32_t getUSART2(void); // Get TARGET_LEVEL from NANOPI
- void setUSART2(uint32_t value, bool mode); //Send WATER_LEVEL to NANOPI
- /* USER CODE END PFP */
- /* USER CODE BEGIN 0 */
- void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
- {
- if(htim->Instance == TIM4){
- if(htim->Channel==HAL_TIM_ACTIVE_CHANNEL_1)
- {
- input_flow_cnt++;
- }
- else if(htim->Channel==HAL_TIM_ACTIVE_CHANNEL_2)
- {
- output_flow_cnt++;
- }
- else
- {
- }
- }
- }
- void HAL_SYSTICK_Callback()
- {
- sys_timer++;
- if(sys_timer >=1000)
- {
- output_flow=(output_flow_cnt) /7.5;
- input_flow=(input_flow_cnt) /7.5;
- input_flw_int=round(input_flow);
- output_flw_int=round(output_flow);
- output_flow_cnt=0;
- input_flow_cnt=0;
- sys_timer=0;
- }
- }
- void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
- {
- __NOP();
- }
- void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
- {
- if(huart->Instance==USART1)
- {
- water_level=getUSART1();
- }
- if(huart->Instance==USART2)
- {
- target_level_pi=getUSART2();
- }
- }
- /* USER CODE END 0 */
- /**
- * @brief The application entry point.
- *
- * @retval None
- */
- 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_USART1_UART_Init();
- MX_USART2_UART_Init();
- MX_TIM4_Init();
- MX_I2C1_Init();
- /* Initialize interrupts */
- MX_NVIC_Init();
- /* USER CODE BEGIN 2 */
- HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_1);
- HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_2);
- HAL_UART_Receive_IT(&huart1, buffer_USART1_rx, 4);
- HAL_UART_Receive_IT(&huart2, buffer_USART2_rx, 4);
- // HAL_UART_Transmit_IT(&huart2, buffer_USART2_tx, 4);
- volatile char key;
- bool text_flag = false;
- char razina[2];
- static uint8_t i=0;
- HAL_Delay(1000);
- lcd_init();
- HAL_Delay(1000);
- lcd_send_cmd(0x01); //clear screen
- char *mystr1="Targ.Lvl:";
- char *mystr2="Curr.Lvl:";
- char *curr_lvl="25";
- char * new_str1 ;
- char * new_str2 ;
- char * targ_lvl;
- lcd_send_string(mystr1);
- lcd_send_cmd(0xC0);// move cursor to second row
- lcd_send_string(mystr2);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- // Get key pressed
- HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_12); //Toggle the state of pin PC9
- HAL_Delay(1000); //delay 100ms
- key=KeypadGetKey();
- HAL_Delay(50);
- // LCD print
- if (text_flag==true)
- {
- lcd_send_cmd(0x01);
- if((new_str1 = malloc(strlen(mystr1)+strlen(razina)+1)) != NULL)
- {
- new_str1[0] = '\0'; // ensures the memory is an empty string
- strcat(new_str1,mystr1);
- strcat(new_str1,razina);
- }
- lcd_send_cmd(0x01);
- lcd_send_string(new_str1);
- if((new_str2 = malloc(strlen(mystr2)+strlen(curr_lvl)+1)) != NULL)
- {
- new_str2[0] = '\0'; // ensures the memory is an empty string
- strcat(new_str2,mystr2);
- strcat(new_str2,curr_lvl);
- }
- lcd_send_cmd(0xC0);
- lcd_send_string(new_str2);
- }
- // Numerical key pressed
- if ((key != KEYPAD_NO_PRESSED && (key != '*') ) && (key != KEYPAD_NO_PRESSED && (key!='#')))
- {
- HAL_Delay(30);
- razina[i]=key;
- razina[i+1]='\0';
- i++;
- if(i>2)
- {
- i=0;
- }
- text_flag=true;
- }
- // Enter (*) pressed
- else if(key!=KEYPAD_NO_PRESSED && (key =='*'))
- {
- i=0;
- target_level_kp=atoi(razina);
- /* if((targ_lvl = malloc(strlen(razina))) != NULL)
- {
- targ_lvl[0] = '\0'; // ensures the memory is an empty string
- strcpy(targ_lvl,razina);
- }
- */
- text_flag=true;
- }
- else
- {
- text_flag=false;
- }
- /* USER CODE BEGIN 3 */
- //setUSART2(water_level,true);
- // sprintf(buffer_USART2_tx, "Lvl:"%" PRIu32 "\n" "In:" ""%" PRIu32 "\n",input_flw_int);
- sprintf(buffer_USART2_tx,"%" PRIu32 "\n",target_level_kp);
- HAL_UART_Transmit_IT(&huart2,buffer_USART2_tx,5);
- }
- /* USER CODE END 3 */
- }
- /**
- * @brief System Clock Configuration
- * @retval None
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- /**Initializes the CPU, AHB and APB busses clocks
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- /**Initializes the CPU, AHB and APB busses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- /**Configure the Systick interrupt time
- */
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
- /**Configure the Systick
- */
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
- /* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
- }
- /**
- * @brief NVIC Configuration.
- * @retval None
- */
- static void MX_NVIC_Init(void)
- {
- /* TIM4_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(TIM4_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(TIM4_IRQn);
- /* I2C1_EV_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(I2C1_EV_IRQn, 2, 0);
- HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
- /* I2C1_ER_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(I2C1_ER_IRQn, 3, 0);
- HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
- /* RCC_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(RCC_IRQn,1, 0);
- HAL_NVIC_EnableIRQ(RCC_IRQn);
- /* USART1_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(USART1_IRQn, 3, 0);
- HAL_NVIC_EnableIRQ(USART1_IRQn);
- /* USART2_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(USART2_IRQn, 3, 0);
- HAL_NVIC_EnableIRQ(USART2_IRQn);
- }
- /* I2C1 init function */
- static void MX_I2C1_Init(void)
- {
- hi2c1.Instance = I2C1;
- hi2c1.Init.ClockSpeed = 100000;
- hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
- hi2c1.Init.OwnAddress1 = 0;
- hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
- hi2c1.Init.OwnAddress2 = 0;
- hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
- hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
- if (HAL_I2C_Init(&hi2c1) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- }
- /* TIM4 init function */
- static void MX_TIM4_Init(void)
- {
- TIM_ClockConfigTypeDef sClockSourceConfig;
- TIM_MasterConfigTypeDef sMasterConfig;
- TIM_IC_InitTypeDef sConfigIC;
- htim4.Instance = TIM4;
- htim4.Init.Prescaler = 71;
- htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim4.Init.Period = 65535;
- htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
- if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
- if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- if (HAL_TIM_IC_Init(&htim4) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
- sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
- sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
- sConfigIC.ICFilter = 15;
- if (HAL_TIM_IC_ConfigChannel(&htim4, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- if (HAL_TIM_IC_ConfigChannel(&htim4, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- }
- /* USART1 init function */
- static void MX_USART1_UART_Init(void)
- {
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- if (HAL_UART_Init(&huart1) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- }
- /* USART2 init function */
- static void MX_USART2_UART_Init(void)
- {
- huart2.Instance = USART2;
- huart2.Init.BaudRate = 115200;
- 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;
- if (HAL_UART_Init(&huart2) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- }
- /** Configure pins as
- * Analog
- * Input
- * Output
- * EVENT_OUT
- * EXTI
- */
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
- /*Configure GPIO pins : PA4 PA5 PA6 PA7 */
- GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pins : PB1 PB10 PB0 */
- GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_0;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pin : PB12 */
- GPIO_InitStruct.Pin = GPIO_PIN_12;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- }
- /* USER CODE BEGIN 4 */
- uint8_t KeypadGetKey()
- {
- // Scan column 0 (column 0 pin is grounded, other column pins is open drain)
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL0,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL1,GPIO_PIN_SET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL2,GPIO_PIN_SET);
- // Read rows
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW0))
- return '1';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW1))
- return '4';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW2))
- return '7';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW3))
- return '*';
- HAL_Delay(30);
- // Scan column 1 (column 1 pin is grounded, other column pins is open drain)
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL0,GPIO_PIN_SET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL1,GPIO_PIN_RESET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL2,GPIO_PIN_SET);
- // Read rows
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW0))
- return '2';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW1))
- return '5';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW2))
- return '8';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW3))
- return '0';
- HAL_Delay(30);
- // Scan column 2 (column 2 pin is grounded, other column pins is open drain)
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL0,GPIO_PIN_SET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL1,GPIO_PIN_SET);
- HAL_GPIO_WritePin(KEYPAD_GPIO_COL, KEYPAD_PIN_COL2,GPIO_PIN_RESET);
- // Read rows
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW0))
- return '3';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW1))
- return '6';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW2))
- return '9';
- if (!HAL_GPIO_ReadPin(KEYPAD_GPIO_ROW, KEYPAD_PIN_ROW3))
- return '#';
- HAL_Delay(30);
- return KEYPAD_NO_PRESSED;
- }
- char* concat(const char *s1, const char *s2)
- {
- char *result = malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
- strcpy(result, s1);
- strcat(result, s2);
- return result;
- }
- uint32_t getUSART1()
- {
- uint32_t num=0;
- num |= buffer_USART1_rx[0] << 24;
- num |= buffer_USART1_rx[1] << 16;
- num |= buffer_USART1_rx[2] << 8;
- num |= buffer_USART1_rx[3];
- return num;
- }
- uint32_t getUSART2()
- {
- uint32_t num=0;
- num |= buffer_USART2_rx[0] << 24;
- num |= buffer_USART2_rx[1] << 16;
- num |= buffer_USART2_rx[2] << 8;
- num |= buffer_USART2_rx[3];
- return num;
- }
- void setUSART2(uint32_t value, bool mode)
- {
- //mode =TRUE->send RAW uint32, FALSE->send as STRING
- if (mode==true)
- {
- buffer_USART2_tx[0] = value ;
- buffer_USART2_tx[1] = value >>8;
- buffer_USART2_tx[2] = value >> 16;
- buffer_USART2_tx[3] = value >> 24;
- HAL_UART_Transmit_IT(&huart2,buffer_USART2_tx,5);
- }
- else
- {
- sprintf(buffer_USART2_tx, "%" PRIu32 "\n",value);
- HAL_UART_Transmit_IT(&huart2,buffer_USART2_tx,5);
- }
- }
- /* USER CODE END 4 */
- /**
- * @brief This function is executed in case of error occurrence.
- * @param file: The file name as string.
- * @param line: The line in file as a number.
- * @retval None
- */
- void _Error_Handler(char *file, int line)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- while(1)
- {
- }
- /* USER CODE END Error_Handler_Debug */
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement