diff --git a/Core/Src/main.c b/Core/Src/main.c index c8df600..29e263d 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -82,9 +82,9 @@ uint8_t send_data_flag_cmd = 0; /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { /* USER CODE BEGIN 1 */ @@ -121,17 +121,18 @@ int main(void) MX_TIM1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ - // HAL_GPIO_WritePin(DO_EN_GPIO_Port, DO_EN_Pin, GPIO_PIN_SET); // DO输出使能 - + /*配置各串口的DMA接收*/ + // start HAL_UARTEx_ReceiveToIdle_DMA(&huart4, lcd_uart4.rx_data_temp, ARRAY_LEN(lcd_uart4.rx_data_temp)); HAL_UARTEx_ReceiveToIdle_DMA(&huart6, ble1_uart6.rx_data_temp, ARRAY_LEN(ble1_uart6.rx_data_temp)); HAL_UARTEx_ReceiveToIdle_DMA(&huart3, ble2_uart3.rx_data_temp, ARRAY_LEN(ble2_uart3.rx_data_temp)); HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp)); HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp)); HAL_UARTEx_ReceiveToIdle_DMA(&huart1, usb_uart1.rx_data_temp, ARRAY_LEN(usb_uart1.rx_data_temp)); - hart_ht1200m_reset(); // 初始化HT1200M模块 - HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // PWM输出,用于驱动HT1200M模块 - HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_ALL); + // end + hart_ht1200m_reset(); // 初始化HT1200M模块 + HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // PWM输出,用于驱动HT1200M模块 + HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_ALL); // 旋转编码器输入,用于检测旋转编码器状态 /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ @@ -152,22 +153,22 @@ int main(void) } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage - */ + */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ + * in the RCC_OscInitTypeDef structure. + */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; @@ -182,9 +183,8 @@ void SystemClock_Config(void) } /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; @@ -283,19 +283,20 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) /* USER CODE END 4 */ /** - * @brief Period elapsed callback in non blocking mode - * @note This function is called when TIM4 interrupt took place, inside - * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment - * a global variable "uwTick" used as application time base. - * @param htim : TIM handle - * @retval None - */ + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM4 interrupt took place, inside + * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment + * a global variable "uwTick" used as application time base. + * @param htim : TIM handle + * @retval None + */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* USER CODE BEGIN Callback 0 */ /* USER CODE END Callback 0 */ - if (htim->Instance == TIM4) { + if (htim->Instance == TIM4) + { HAL_IncTick(); } /* USER CODE BEGIN Callback 1 */ @@ -304,9 +305,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) } /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ @@ -318,14 +319,14 @@ void Error_Handler(void) /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ diff --git a/User/application/src/communication_protocol.c b/User/application/src/communication_protocol.c index 7d8076d..e690039 100644 --- a/User/application/src/communication_protocol.c +++ b/User/application/src/communication_protocol.c @@ -25,6 +25,15 @@ void communication_exception(uint8_t *tx_data, const uint8_t *const rx_data, com tx_data[6] = FRAME_TAIL; // 帧尾 } +/** + * @brief 获取AI数据并封装成通信帧 + * + * 该函数从指定的AI通道获取模拟数据,并将其封装成一个通信帧。 + * + * @param ai_data 指向communication_ai_t结构体的指针,包含AI通道信息 + * @param tx_data 指向uint8_t数组的指针,用于存储生成的通信帧 + * @param rx_data 指向const uint8_t数组的指针,包含接收到的命令数据 + */ void communication_get_ai(communication_ai_t *ai_data, uint8_t *tx_data, const uint8_t *const rx_data) { float32_u analog_data; diff --git a/User/application/src/tcpclient.c b/User/application/src/tcpclient.c index 30ace26..96b0815 100644 --- a/User/application/src/tcpclient.c +++ b/User/application/src/tcpclient.c @@ -89,13 +89,6 @@ void TCP_Client_Init(void) client_pcb = tcp_new(); IP4_ADDR(&server_ip, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3); // ϲIPַ - // printf("IP ַΪ: %d.%d.%d.%d\n", - // ip4_addr1(&server_ip), - // ip4_addr2(&server_ip), - // ip4_addr3(&server_ip), - // ip4_addr4(&server_ip)); - // printf("ͻ˿ʼ!\n"); - // ʼ tcp_connect(client_pcb, &server_ip, TCP_CLIENT_PORT, client_connected); ip_set_option(client_pcb, SOF_KEEPALIVE); diff --git a/User/driver/ad7124.h b/User/driver/ad7124.h index 24a668f..1fb12be 100644 --- a/User/driver/ad7124.h +++ b/User/driver/ad7124.h @@ -220,6 +220,7 @@ typedef enum } ad7124_registers_addr_e; // 寄存器地址 typedef enum { + AD7124_SIZE_1 = 1, AD7124_SIZE_2 = 2, AD7124_SIZE_3 = 3, diff --git a/User/driver/ht1200m.c b/User/driver/ht1200m.c index bf2421c..8805f50 100644 --- a/User/driver/ht1200m.c +++ b/User/driver/ht1200m.c @@ -1,5 +1,16 @@ #include "ht1200m.h" +/** + * @brief 重置hart_ht1200m模块 + * + * 该函数用于重置hart_ht1200m模块,通过操作硬件复位引脚和RTS引脚实现。 + * + * 具体步骤如下: + * 1. 将HART1和HART2的复位引脚置高电平,启动复位过程。 + * 2. 延时10毫秒,确保复位过程完成。 + * 3. 将HART1和HART2的复位引脚置低电平,结束复位过程。 + * 4. 将HART1和HART2的RTS引脚设置为接收状态,准备接收数据。 + */ extern void hart_ht1200m_reset(void) { HART1_RESET_ON; diff --git a/User/driver/uart_lcd.c b/User/driver/uart_lcd.c index ec3587c..0aa3171 100644 --- a/User/driver/uart_lcd.c +++ b/User/driver/uart_lcd.c @@ -4,19 +4,26 @@ extern ip4_addr_t ipaddr; uint8_t ip_addr[24] = {0}; +/** + * @brief 通过UART向LCD屏幕绘制IP地址 + * + * 此函数通过UART接口向LCD屏幕发送IP地址,以便在屏幕上显示。 + * + * @note 此函数假定已经正确初始化了UART接口,并且LCD屏幕已经正确连接到UART接口。 + */ void uart_lcd_draw_ipaddr(void) { - - ip_addr[0] = 0xEE; + // 串口发送的固定值为串口屏指令指定的帧头帧尾 + ip_addr[0] = 0xEE; // 帧头 ip_addr[1] = 0xB1; - ip_addr[2] = 0x10; - ip_addr[3] = 0x00; - ip_addr[4] = 0x00; - ip_addr[5] = 0x00; - ip_addr[6] = 0x03; + ip_addr[2] = 0x10; // 命令码,此处为文本控件文本设置指令 + ip_addr[3] = 0x00; // 画面ID高位地址 + ip_addr[4] = 0x00; // 画面ID低位地址 + ip_addr[5] = 0x00; // 控件ID高位地址 + ip_addr[6] = 0x03; // 控件ID低位地址 char *ip_addr_str = ipaddr_ntoa(&ipaddr); MEMCPY(ip_addr + 7, (uint8_t *)ip_addr_str, strlen(ip_addr_str)); - ip_addr[7 + strlen(ip_addr_str)] = 0xFF; + ip_addr[7 + strlen(ip_addr_str)] = 0xFF; // 帧尾,下列都为帧尾 ip_addr[8 + strlen(ip_addr_str)] = 0xFC; ip_addr[9 + strlen(ip_addr_str)] = 0xFF; ip_addr[10 + strlen(ip_addr_str)] = 0xFF;