你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
举报
查看全部评分
安 发表于 2018-4-20 08:41 我用的103 uart4如下配置:
STM32隐藏
5.18活动板子会不会是STM32L4呢
STM32 CUBE软件中找不到STM32L4系列单片机
Your UAT Feedback is needed within today.
应用
AAA
1q1q
12345
11
11.08
void UART4_Initial(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
// 使能串口4时钟
// 注意 UART4, UART5 是挂载在APB1总线上的,用RCC_APB1PeriphClockCmd()函数初始化!
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
// PC10 做 UART4_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// PC11 做 UART4_RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(UART4, &USART_InitStructure);
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(UART4, &USART_ClockInitStructure);
USART_Cmd(UART4, ENABLE);
USART_ClearFlag(UART4,USART_FLAG_TC);
// 使能UART4接收中断
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
}
// UART4接收中断入口函数
void UART4_IRQHandler(void)
{
unsigned char value;
if(UART4->SR & (1<<5))
{
value = UART4->DR;
UART4_Rx_OK = TRUE;
}
}
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
USART_Cmd(UART4, ENABLE); 在查看一下有没有这两句话
RCC_APB1Periph_UART4, ENABLE 串口4的时钟
查看一下这些的
评分
查看全部评分
PC11在做串口接收功能时,是否应该设置为输入状态呢?输出的话,与外面的信号会打架。
用STM32CubeMX建了个工程,UART4 IO的初始化代码为下图
评分
查看全部评分
评分
查看全部评分
大神,请教一个问题啊,我用UART4转换成232芯片通讯没问题,用485通讯就不行,配置没问题,也能进中断,我中断配置的是这样的
到了4,就不是USARTA4, 而是UART32, 少了个S, 就是非同步(异步)的意思
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(UART4, &USART_ClockInitStructure);
UART4, 是不存在上面这些用于同步的设置的