我用的STM32F030C8T6做通讯,TTL主动发送数据采集室内空气参数模块数据,但是用了好几个达人的例程都是一直死在中断,望请协助!万分感谢 //初始化函数 void initUart(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); /* USART2 Pins configuration ******/ /* Connect pin to Periph */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); /* Configure pins as AF pushpull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 9600; 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(USART1,&USART_InitStructure); USART_ClearFlag(USART1,USART_FLAG_TC); USART_ITConfig(USART1,USART_IT_TC,ENABLE); //USART_ITConfig(USART1,USART_IT_TXE,ENABLE); USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); USART_Cmd(USART1,ENABLE); //使能串口 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //使能串口中断 } //网上下的例程 void Usart_TxByte(uint8_t dat) { USART_SendData(USART1,dat); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) != SET); } /** * @brief send string * @param string -> pointer string will be send * @retval None */ void Usart_TxString(uint8_t *string) { while(*string != '\0') Usart_TxByte(*string++); } /** * @brief interrupt server function * @param None * @retval None */ void USART1_IRQHandler(void) { static uint8_t n = 0; //一直可以进入 if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)) //溢出中断 USART1->ICR |= 1 << 3;// USART_ReceiveData(USART1); //空读清除ORE位 //一直可以进入 if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { Usart_TxByte(USART_ReceiveData(USART1)); } //一直可以进入 if(USART_GetITStatus(USART1, USART_IT_TC) != RESET) { if(TestString[n] == '\0') { USART_ClearFlag(USART1,USART_FLAG_TC); Tx_BusyFlag = 0;n = 0; } else { Tx_BusyFlag = 1; USART_SendData(USART1,TestString[n++]); } } } |
STM32F107+LWIP---如何检查tcp通讯断开?并重新连接
有没有用过数字式mems麦克风的,想问下SPI通讯的问题
stm32f103 CAN通讯多帧发送问题?
STM32F107作为USB主机模拟串口通讯不成功(采用PL2303芯片)
STM32F103C8 LIN通讯例程
求助,丐版J-Link通讯不上
ethernet可以与ethercat通讯吗?
LIS3DH SPI 通讯问题
STM32F373 CAN通讯问题CAN_FLAG_LEC
请教高手看看,STM32F1的多机通讯,地址匹配唤醒问题
评分
查看全部评分
而:
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
Usart_TxByte(USART_ReceiveData(USART1));
}
按理应该接收完成后再发送,否则当然要无限死循环了。
评分
查看全部评分
评分
查看全部评分
谢谢反馈!