Вс дек 17, 2017 20:17:33
#include "main.h"
#include "stm32f1xx_hal.h"
UART_HandleTypeDef huart1;
uint8_t str_welcome[] = "Welcome to test\r\nReady...\r\n";
volatile int rx_cplt;
uint8_t receivedByte;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_UART_Receive_IT(&huart1, &receivedByte, 1);
while (1)
{
if(rx_cplt)
{
rx_cplt = 0;
HAL_UART_Transmit_IT(&huart1, (uint8_t*)s, strlen(s));
}
}
}
void SystemClock_Config(void)
{
.....
}
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_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
static void MX_GPIO_Init(void)
{
....
....
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart == &huart1)
{
if(receivedByte == '\n') rx_cplt = 1;
HAL_UART_Receive_IT(&huart1, &receivedByte, 1);
}
}
void _Error_Handler(char * file, int line)
{
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
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,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif
Вс дек 17, 2017 21:21:57
Вс дек 17, 2017 22:00:49
Вс дек 17, 2017 22:53:22
Пн дек 18, 2017 02:51:59
Пн дек 18, 2017 04:41:42
Пн дек 18, 2017 15:59:04
Пн дек 18, 2017 18:04:23
Сб дек 23, 2017 04:59:04