各位前辈 ,大家好。最近在STM32F103RE上面配置UART4进行串口数据的收发,遇到了一些问题。板子上UART4的TTL电平出来后接到TTL转232电平转换电路上。目前测试的现象是:1、单片机接上外围的TTL转232电平转换电路后,UART4可以进发送完成中断,但进不了接收中断。改为查询的接收方式,也不能接收,查看UART4的SR寄存器,发现RXNE位并没有置位,所以就进不了接收中断。 2、去掉外围电平转换电路后,让单片机Tx引脚接Rx引脚,单片机可以进行自发自收,可以进入到接收中断。 有换过其他103的板子试过,现象也是一样的,应该是程序哪里出了问题。 后将UART4的引脚映射为USART3可以采用中断接收,暂时解决了串口收发的问题,但想弄明白UART4的问题。 |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
UART4初始化配置如下:
local void lvIF_UartConfig( uint32_t dwBaudrate )
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef *aptIO;
USART_InitTypeDef *aptUSART;
aptIO = &GPIO_InitStructure;
aptUSART = &USART_InitStructure;
USART_PORT_RCC_EN;
USART_RCC_EN;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
/* Set PC10 ~ PC11 pins as UART4 TXD ~ RXD */
/* Set PA9 ~ PA10 pins as UART1 TXD ~ RXD */
aptIO->GPIO_Pin = USART_TX_PIN;
aptIO->GPIO_Mode = GPIO_Mode_AF_PP;
aptIO->GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( USART_GPIO_PORT, aptIO );
aptIO->GPIO_Pin = USART_RX_PIN;
aptIO->GPIO_Mode = GPIO_Mode_IN_FLOATING;
aptIO->GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( USART_GPIO_PORT, aptIO );
aptUSART->USART_BaudRate = dwBaudrate;
aptUSART->USART_WordLength = USART_WordLength_8b;
aptUSART->USART_StopBits = USART_StopBits_1;
aptUSART->USART_Parity = USART_Parity_No;
aptUSART->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
aptUSART->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init( USED_USART, aptUSART );
/*!< Enable interruption of RDA(Receive Data Avaliable) and THRE (Transmit
*!< Holding Register Empty). */
USART_ITConfig( USED_USART, USART_IT_RXNE, ENABLE );
// USART_DMACmd( USED_USART, USART_DMAReq_Tx, ENABLE );
USART_ClearFlag( USED_USART, USART_FLAG_TC );
USART_ClearFlag( USED_USART, USART_FLAG_TXE );
USART_Cmd( USED_USART, ENABLE );
}
global void gvIF_SysInterruptionConfig( void )
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitTypeDef *ptNVIC;
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2 );
ptNVIC->NVIC_IRQChannel = UART4_IRQn;
ptNVIC->NVIC_IRQChannelPreemptionPriority = 1 ;
ptNVIC->NVIC_IRQChannelSubPriority = 0 ;
ptNVIC->NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( ptNVIC );
}
UART4中断服务函数
void UART4_IRQHandler( void )
{
gvcbIF_USART_IRQHandler();
}
global void gvcbIF_USART_IRQHandler( void )
{
uint8_t abInChar = 0xFF;
USART_TypeDef *pUart = USED_USART;
#warning "Becare to re-entry this function. "
if( USART_GetITStatus( pUart, USART_IT_RXNE ) != RESET )
{
/* Get the character from UART Buffer and transfer back it by UART. */
abInChar = (uint8_t)USART_ReceiveData( pUart );
USART_SendData( pUart, abInChar );
if( gwRcvIndex < UART_RX_BUFFER )
{
lbRxdData[gwRcvIndex++] = abInChar;
}
USART_ClearITPendingBit( pUart, USART_IT_RXNE );
}
}
C:\Users\Administrator\Desktop\微信图片_20181207160121
UART4åå§ååçå¯åå¨å¼
1、硬件设计错误;
2、芯片损坏。
3、上位机发送电路故障,没有发送数据到STM32。
评分
查看全部评分