Untitled
Never
#include "main.h" #include "usart.h" #include "gpio.h" #include "string.h" void SystemClock_Config(void); volatile uint8_t recv_char; volatile uint16_t RxCounter; volatile char RxBuffer[256]; volatile char RxBuffer_Tx_Send[256]; int temp; int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); for(uint8_t temp=0; temp<256; temp++) { RxBuffer[temp] = '\0'; RxBuffer_Tx_Send[temp] = '\0'; } HAL_UART_Receive_IT(&huart1, &recv_char, 1); while (1) { /* USER CODE END WHILE */ HAL_UART_Transmit(&huart2, RxBuffer_Tx_Send, strlen(RxBuffer_Tx_Send), 256); HAL_Delay(1000); } } void NMEA_Handler(void) { int i = 0; RxBuffer[RxCounter] = recv_char; RxCounter++; if ( (RxBuffer[RxCounter - 2] != '\r') && (RxBuffer[RxCounter - 1] != '\n') && (RxCounter == 255) ) {RxCounter = 253;} else if ( (RxBuffer[RxCounter -2] != '\r') && (RxBuffer[RxCounter -1] != '\n') ) { if(RxBuffer[0] == '$') { for(i=0; i<256; i++) { RxBuffer_Tx_Send[i] = RxBuffer[i]; RxBuffer[i] = 0; } RxCounter = 0; } else { for(i=0; i<256; i++) {RxBuffer[i] = 0;} RxCounter = 0; } } } void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4; RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** 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_1) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* 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****/