【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
问题已解决,原因是USART_GetFlagStatus和USART_GetITStatus,,,,,获取ORE标记,需用USART_GetFlagStatus,然后清0
评分
查看全部评分
{
USART_InitTypeDef USART_InitStructure; //定义串口初始化结构体
NVIC_InitTypeDef NVIC_InitStructure;
USART_ClockInitTypeDef usartClock;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Enable the USART Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_DeInit(USART2);//串口状态到初始状态
USART_InitStructure.USART_BaudRate = 9600; //波特率默认为9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1;//1个停止位
USART_InitStructure.USART_Parity = USART_Parity_No ; //无校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//禁用RTSCTS硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//使能发送接收
usartClock.USART_Clock = USART_Clock_Disable; //串口同步时钟禁止
usartClock.USART_CPOL = USART_CPOL_Low; //时钟下降沿有效
usartClock.USART_CPHA = USART_CPHA_2Edge;//数据在第二个时钟沿捕捉
usartClock.USART_LastBit = USART_LastBit_Disable; //最后数据位的时钟脉冲不输出到SCLK引脚
USART_ClockInit(USART2,&usartClock);//初始化串口时钟
USART_Init(USART2, &USART_InitStructure);//初始化调试串口(串口1)
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); //开启接收字节中断
USART_ITConfig(USART2,USART_IT_IDLE,ENABLE); //开启接收空闲中断
USART_Cmd(USART2, ENABLE);//调试串口(串口1)使能
}
{
USART_InitTypeDef USART_InitStructure; //定义串口初始化结构体
NVIC_InitTypeDef NVIC_InitStructure;
USART_ClockInitTypeDef usartClock;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Enable the USART Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_DeInit(USART1);//串口状态到初始状态
USART_InitStructure.USART_BaudRate = BusBaudRate; //波特率默认为9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1;//1个停止位
USART_InitStructure.USART_Parity = USART_Parity_No ; //无校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//禁用RTSCTS硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//使能发送接收
usartClock.USART_Clock = USART_Clock_Disable; //串口同步时钟禁止
usartClock.USART_CPOL = USART_CPOL_Low; //时钟下降沿有效
usartClock.USART_CPHA = USART_CPHA_2Edge;//数据在第二个时钟沿捕捉
usartClock.USART_LastBit = USART_LastBit_Disable;//最后数据位的时钟脉冲不输出到SCLK引脚
USART_ClockInit(USART1,&usartClock);//初始化串口时钟
USART_Init(USART1, &USART_InitStructure);//初始化串口
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//开启接收中断
USART_Cmd(USART1, ENABLE);//调试串口(串口1)使能
}
{
if(USART_GetITStatus(USART2,USART_IT_RXNE) != RESET)//接收一字节数据
{
if(FlagIdle == 1)
{
Com2RevBuff[Com2RecvPtr++]= USART_ReceiveData(USART2);
if(Com2RevBuff[0] == 0x42)
{
if(Com2RecvPtr >= 24)
{
FlagIdle = 2;
Com2RecvPtr = 0;
}
}
else
{
Com2RecvPtr = 0;
}
}
else
{
USART_ReceiveData(USART2);
Com2RecvPtr = 0;
}
}
if(USART_GetITStatus(USART2,USART_IT_ORE) != RESET)//接收一字节数据
{
USART_ClearFlag(USART2, USART_FLAG_ORE);
USART_ReceiveData(USART2);
}
}
评分
查看全部评分
只要断开上位机发送,产品就会重启,然后恢复正常
评分
查看全部评分
确实是本机的地址码,就是设备每次都是运行一段时间。刚开始上位机发过来,产品也有返回。。。过一段时间,一直在发相同的命令,就没有回应了。。。。断开上位机发送一下,会看到产品重启,然后又恢复正常。。。。。然后按照上面的逻辑,是不是就会貌似死机的现象
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
那应该考虑接收中断如果发生溢出需要先读SR,再读DR寄存器
USART_ClearFlag(USART2,USART_FLAG_ORE); //读SR
USART_ReceiveData(USART2); //读DR
加了一个溢出中断判定,好像还是不行
if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) != RESET)
{
Com1Recv.Buff[Com1Recv.Ptr++] = USART_ReceiveData(USART1);
if(Com1Recv.Ptr >= MAX_BYTES_COM_RECV) //溢出了,丢掉
{
Com1Recv.Ptr = 0;
}
}
if(USART_GetITStatus(USART1,USART_IT_ORE) != RESET)//接收一字节数据
{
USART_ClearFlag(USART1, USART_FLAG_ORE);
USART_ReceiveData(USART1);
}
}
ST官方文档可以参考: