STM32 标准库 将结构中6个不同的数据与之后更新的这六个数据进行对比,如果不同则标志位++并保存之前的数据在结构体数组中, 但是没有将USART3中的数据传给要检测是否一样的数据,请修改void Openmv_RXtask(void) { if((Openmv_Flag == 1)&&(USART3_RX_BUF[3]!=0 )) { Openmv.Color_Num = USART3_RX_BUF[2]; Openmv.Shape_Num = USART3_RX_BUF[3]; Openmv.Openmv_X = USART3_RX_BUF[4] | USART3_RX_BUF[5] <<8; Openmv.Openmv_Y = USART3_RX_BUF[6] | USART3_RX_BUF[7] <<8; Openmv.Openmv_W = USART3_RX_BUF[8] | USART3_RX_BUF[9] <<8; Openmv.Openmv_H = USART3_RX_BUF[10]| USART3_RX_BUF[11]<<8; Openmv_Flag = 0; USART3_RX_STA = 0; // printf("%d\r\n",Openmv.Shape_Num); //USART_ITConfig(USART3,USART_IT_RXNE,ENABLE); } }inline void checkAndUpdate(Openmv_InitTypeDef *myStruct) { printf("没进来了\r\n"); static uint16_t prevData1, prevData2, prevData3, prevData4, prevData5, prevData6; printf("%d\r\n",prevData1); if (myStruct->Color_Num != prevData1 || myStruct->Shape_Num != prevData2 || myStruct->Openmv_X != prevData3 || myStruct->Openmv_Y != prevData4 || myStruct->Openmv_W != prevData5 || myStruct->Openmv_H != prevData6) { printf("进来了\r\n"); OpenmvArray[myStruct->flag] = *myStruct; myStruct->flag++; // 保存之前的数据到结构体数组中 prevData1 = myStruct->Color_Num; prevData2 = myStruct->Shape_Num; prevData3 = myStruct->Openmv_X; prevData4 = myStruct->Openmv_Y; prevData5 = myStruct->Openmv_W; prevData6 = myStruct->Openmv_H; } }
时间: 2024-03-02 08:53:23 浏览: 94
STM32ZGT6的中文数据手册(datasheet)
5星 · 资源好评率100%
你需要把 USART3 接收到的数据传递给 checkAndUpdate 函数进行比较。修改后的代码如下:
```
void Openmv_RXtask(void) {
if((Openmv_Flag == 1)&&(USART3_RX_STA & 0x8000)) {
Openmv.Color_Num = USART3_RX_BUF[2];
Openmv.Shape_Num = USART3_RX_BUF[3];
Openmv.Openmv_X = USART3_RX_BUF[4] | USART3_RX_BUF[5] <<8;
Openmv.Openmv_Y = USART3_RX_BUF[6] | USART3_RX_BUF[7] <<8;
Openmv.Openmv_W = USART3_RX_BUF[8] | USART3_RX_BUF[9] <<8;
Openmv.Openmv_H = USART3_RX_BUF[10]| USART3_RX_BUF[11]<<8;
Openmv_Flag = 0;
USART3_RX_STA = 0;
checkAndUpdate(&Openmv); // 将结构体传递给 checkAndUpdate 函数进行比较
}
}
inline void checkAndUpdate(Openmv_InitTypeDef *myStruct) {
static uint16_t prevData1, prevData2, prevData3, prevData4, prevData5, prevData6;
if (myStruct->Color_Num != prevData1 || myStruct->Shape_Num != prevData2 ||
myStruct->Openmv_X != prevData3 || myStruct->Openmv_Y != prevData4 ||
myStruct->Openmv_W != prevData5 || myStruct->Openmv_H != prevData6) {
OpenmvArray[myStruct->flag] = *myStruct;
myStruct->flag++;
prevData1 = myStruct->Color_Num;
prevData2 = myStruct->Shape_Num;
prevData3 = myStruct->Openmv_X;
prevData4 = myStruct->Openmv_Y;
prevData5 = myStruct->Openmv_W;
prevData6 = myStruct->Openmv_H;
}
}
```
修改后的代码中,我们增加了一个判断 USART3_RX_STA 是否为接收完成标志位的判断,只有当接收完成后才会进行处理。同时,在 Openmv_RXtask 函数中,我们将结构体传递给 checkAndUpdate 函数进行比较。
阅读全文