最近在學習GM65二維碼識別模塊,在這程序中遇到到了一些困難,想請教一下論壇的大佬。
首先,這個二維碼識別模塊是串口通信,這里我用了USART3,通過串口中斷來接受資料,代碼和串口接受的資料如下:
static uint8_t ch;
void USART3_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//USART_DeInit(USART3);
//PB10---->TX
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//PB11---->RX
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits =USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART3,&USART_InitStruct);
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3, USART_FLAG_TC);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//使能串口接收中斷
NVIC_InitStruct.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void USART3_IRQHandler(void)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
{
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
ch = USART_ReceiveData(USART3);
printf("ch=%c\r\n",ch);
}
USART_ClearFlag(USART3, USART_FLAG_TC);//解決丟失第一個字符
}
讀出的資料為ch = 123+321(這是二維碼的內容)
我現在遇到的問題是,如何將這個資料放到陣列,比如num[] = {1,2,3,3,2,1};或者num[] = {1,2,3,+,3,2,1};
在這里嘗試了一些辦法沒有解決,實在沒別的思路了,所以請教一下,
請大佬幫忙指點一下,萬分感謝,真誠感謝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/269140.html
標籤:C語言
上一篇:結構體問題
