#include "sys.h"
#include "delay.h"
u8 rdata[1];
UART_HandleTypeDef USART1_Handler;
void UART_Init(u32 bound)
{
USART1_Handler.Instance=USART1;
USART1_Handler.Init.BaudRate=bound;
USART1_Handler.Init.WordLength=UART_WORDLENGTH_8B;
USART1_Handler.Init.Mode=UART_MODE_TX_RX;
USART1_Handler.Init.StopBits=UART_STOPBITS_1;
USART1_Handler.Init.Parity=UART_PARITY_NONE;
USART1_Handler.Init.HwFlowCtl=UART_HWCONTROL_NONE;
HAL_UART_Init(&USART1_Handler);
}
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIOA_Init;
if(huart->Instance==USART1)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
GPIOA_Init.Pin=GPIO_PIN_9|GPIO_PIN_10;
GPIOA_Init.Speed=GPIO_SPEED_HIGH;
GPIOA_Init.Mode=GPIO_MODE_AF_PP;
GPIOA_Init.Alternate=GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA,&GPIOA_Init);
HAL_NVIC_EnableIRQ(USART1_IRQn);
HAL_NVIC_SetPriority(USART1_IRQn,3,3);
}
}
void USART1_IQRHandler(void)
{
HAL_UART_RxCpltCallback(&USART1_Handler);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
u8 rec;
if(huart->Instance==USART1)
{
rec=*((huart->pRxBuffPtr)-1);
HAL_UART_Transmit(&USART1_Handler,&rec,1,1000);
}
}
int main(void)
{
//u8 tab[] = "asdad";
Cache_Enable();
HAL_Init();
Stm32_Clock_Init(432,25,2,9);
delay_init(216);
UART_Init(115200);
HAL_UART_Receive_IT(&USART1_Handler,(u8 *)rdata,1);
while(1)
{
//HAL_UART_Transmit(&USART1_Handler,tab, sizeof(tab), 100);
//delay_ms(100);
}
} |