新手入门
- 积分
- 7
- 金钱
- 7
- 注册时间
- 2022-6-6
- 在线时间
- 3 小时
|
5金钱
stm32的程序不做修改,用串口助手和stm32通信 接收和发送都正常,重复发送也ok,用GM65模块和
STM32通信接收发送也都能实现,但是gm65模块在次执行扫码后,串口接收数据未更新,没有变化。那位大神帮忙指点一下。
void USART1_IRQHandler(void)
{
static uint8_t RxState = 0;
static uint8_t pRxPacket = 0;
if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
uint8_t RxData = USART_ReceiveData(USART1);
if (RxState == 0 )
{
if (Serial_RxFlag == 0 && RxData == 'D')
{
RxState = 1;
}
pRxPacket = 0;
}
else if (RxState == 1)
{
if (RxData == '\r')
{
RxState = 2;
}
else
{
Serial_RxPacket[pRxPacket] = RxData;
pRxPacket ++;
}
}
else if (RxState == 2)
{
if (RxData == '\n')
{
RxState = 0;
Serial_RxPacket[pRxPacket] = '\0';
Serial_RxFlag = 1;
}
}
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
}
int main(void)
{
uint8_t Serial_TxPacket[9]={0x7E,0x00,0x08,0x01,0x00,0x02,0x01,0xAB,0xCD};
uint8_t KeyNum = 0,i=0;
OLED_Init();
LED_Init();
Key_Init();
Serial_Init();
OLED_ShowString(1, 1, "RxPacket");
while (1)
{
KeyNum = Key_GetNum() ;
OLED_ShowNum(4,1,KeyNum,1);
if(KeyNum == 1)
{
OLED_ShowNum(4,1,KeyNum,1);
Serial_SendArray(Serial_TxPacket,9);
Delay_ms(100);
}
OLED_ShowString(2, 1, " ");
OLED_ShowString(2, 1, Serial_RxPacket);
Serial_RxFlag = 0;
}
}
|
|