解决中断冲突

This commit is contained in:
2025-03-12 15:03:24 +08:00
parent 145dde360e
commit 84ad34d5f1
20 changed files with 164 additions and 116 deletions

View File

@ -15,9 +15,8 @@ uint8_t g_rx_buffer[RXBUFFERSIZE];
//平均次数
uint8_t Target_Average_Times = 1;
uint16_t Receive_Data_Buffer[USART2_RX_BUFFER_SIZE - 1];
uint16_t USART2_RX_Buffer[USART2_RX_BUFFER_SIZE];
uint16_t Receive_Data_Buffer[USART2_RX_BUFFER_SIZE - 1];
uint16_t Average_Buffer[USART2_RX_BUFFER_SIZE - 1];
uint16_t Moving_Buffer[10][USART2_RX_BUFFER_SIZE - 1];
uint16_t Moving_Average_Buffer[USART2_RX_BUFFER_SIZE - 1];
@ -34,9 +33,9 @@ float Temperature = 0;
* 3 发送多次均数据
* 4 发送滑动平均数据
*/
uint8_t Send_Data_Type = 0;
uint8_t Send_Data_Type = 0;
uint32_t sn = 1;
uint8_t busy_sta = 0;
double bochangxishu[4] = {0,0,0,0};
void swap_buf(uint8_t *p , uint32_t size);
@ -63,10 +62,9 @@ void Send_Data(uint8_t command,uint8_t *pData, uint16_t Size) {
void mymain()
{
// HAL_Delay(5000);
HAL_NVIC_SetPriorityGrouping(2);
HAL_UART_Receive_IT(&huart1, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
setvbuf(stdout, NULL, _IONBF, 0);
dma_init(DMA2_Stream7, DMA_REQUEST_USART1_TX);
/////
@ -91,6 +89,7 @@ void mymain()
if (a != 0) {
shutter_time = a;
mode = 1;
busy_sta = 0;
}
Last_Receive_Data_Count = Receive_Data_Count;
memset(g_usart_rx_buf,0,200);
@ -104,7 +103,6 @@ void mymain()
//处理数据
if (Receive_Data_Count > Last_Receive_Data_Count)
{
// Send_Data((uint8_t *)Receive_Data_Buffer,USART2_RX_BUFFER_SIZE*2);
//2多次平均
Average_Times ++;
if(Average_Times <= Target_Average_Times ) {
@ -129,7 +127,7 @@ void mymain()
if((Send_Data_Type & 0x80) !=0)
{
Send_Data_Type = Send_Data_Type & 0x7F;
uint16_t sgi_result[USART2_RX_BUFFER_SIZE];
uint16_t sgi_result[USART2_RX_BUFFER_SIZE - 1];
// printf("AAA");
switch (Send_Data_Type)
{
@ -152,9 +150,9 @@ void mymain()
break;
}
Send_Data_Type = Send_Data_Type & 0x7F;
busy_sta = 0;
}
}
}
}
}
@ -167,8 +165,14 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
__HAL_UART_DISABLE(&huart2);
memcpy(Receive_Data_Buffer, USART2_RX_Buffer+2, USART2_RX_BUFFER_SIZE*2);
memcpy((uint8_t *)Receive_Data_Buffer,&USART2_RX_Buffer[2], (USART2_RX_BUFFER_SIZE-2)*2);
Receive_Data_Count ++;
// if (__HAL_DMA_GET_FLAG(&g_dma_handle, DMA_FLAG_TCIF3_7))
// {
// __HAL_DMA_CLEAR_FLAG(&g_dma_handle, DMA_FLAG_TCIF3_7);
// HAL_UART_DMAStop(&huart1);
// }
// HAL_UART_Transmit_DMA(&huart1,(uint8_t *)Receive_Data_Buffer,USART2_RX_BUFFER_SIZE*2);
HAL_UART_Receive_DMA(&huart2, (uint8_t *)USART2_RX_Buffer, USART2_RX_BUFFER_SIZE*2);
}
@ -200,11 +204,18 @@ void commander_run(void)
// printf("data_length %d \r\n",data_length);
uint8_t data_type = 0;
uint8_t command_data[USART_REC_LEN] = {0};
// data_length = IRIS_Cut_Befor_Header(g_usart_rx_buf,data_length);
data_length = IRIS_Cut_Befor_Header(g_usart_rx_buf,data_length);
int ret = IRIS_STM32_Protocol_Unpack(g_usart_rx_buf,data_length,&data_type,command_data);
// printf( "ret %d \r\n",ret);
if (ret > 0) {
if (busy_sta == 1) {
uint8_t str = 0xff;
Send_Data(0x40,&str,1);
memset(g_usart_rx_buf,0,200);
g_usart_rx_sta=0;
return;
}
switch(data_type)
{
// 获取设备信息
@ -238,6 +249,7 @@ void commander_run(void)
//自动曝光
case 0x52:{
mode = 0;
busy_sta = 1;
Send_Data(0x52,command_data,1);
break;
}
@ -319,6 +331,7 @@ void commander_run(void)
}
//获取数据
case 0x61: {
busy_sta = 1;
Send_Data_Type = Send_Data_Type | 0x80;
// Send_Data(0x61,command_data,5);
break;