#include "sys.h"
#include "delay.h"
UART_HandleTypeDef USART1_Handler;
void USART1_Init()
{
USART1_Handler.Instance = USART1;
USART1_Handler.Init.BaudRate = 115200;
USART1_Handler.Init.WordLength = USART_WORDLENGTH_8B;
USART1_Handler.Init.StopBits = USART_STOPBITS_1;
USART1_Handler.Init.Parity = USART_PARITY_NONE;
USART1_Handler.Init.HwFlowCtl = UART_HWCONTROL_NONE;
USART1_Handler.Init.OverSampling = UART_OVERSAMPLING_16;
USART1_Handler.Init.Mode = USART_MODE_TX_RX;
HAL_UART_Init(&USART1_Handler);
}
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_Initure;
if(huart->Instance == USART1)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
GPIO_Initure.Pin = GPIO_PIN_9;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_PULLUP;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
GPIO_Initure.Pin = GPIO_PIN_10;
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
}
}
int main(void)
{
uint8_t buff[] = "test";
HAL_Init();
Stm32_Clock_Init(360,25,2,8);
delay_init(180);
USART1_Init();
while(1)
{
HAL_UART_Transmit(&USART1_Handler,buff,sizeof(buff),1000);
delay_ms(300);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
晶振用的多少的?把文件system_stm32f4xx.c和stm32f4xx_hal_confi.h中的宏定义 HSE_VALUE,全部修改为你自己开发板所使用的晶振大小
一周热门 更多>