在使用ST官网的例程X-CUBE-SPN7的UART_UI文件时,发现不知道该怎么通过串口大师来发正确的指令。 发什么都没反应 判断条件里有个Get_UART_Data() == 266 ,这个Get_UART_Data()只是返回 (UART.Instance->RDR); 这个266不知道怎么来的。有没有哪位高人指导一下? void UART_Set_Value() { if(Get_UART_Data() == 266 && (huart2.State != HAL_UART_STATE_BUSY_TX && huart2.State != HAL_UART_STATE_BUSY_TX_RX)) { if(Uart_cmd_flag == 0) { CMD_Parser((char*)aRxBuffer); } else { SIXSTEP_parameters.Uart_value_to_set = UART_num_decode(); switch(SIXSTEP_parameters.Uart_cmd_to_set) { case SETSPD_CMD: /*!< Set the new speed value command received */ PI_parameters.Reference = SIXSTEP_parameters.Uart_value_to_set; SIXSTEP_parameters.Ramp_Start = 1; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; huart2.State = HAL_UART_STATE_READY; break; case INIREF_CMD: /*!< Set the new STARUP_CURRENT_REFERENCE value command received */ SIXSTEP_parameters.Ireference = SIXSTEP_parameters.Uart_value_to_set; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case POLESP_CMD: /*!< Set the Pole Pairs value command received */ SIXSTEP_parameters.NUMPOLESPAIRS = SIXSTEP_parameters.Uart_value_to_set; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case ACCELE_CMD: /*!< Set the Accelleration for Start-up of the motor command received */ SIXSTEP_parameters.ACCEL = SIXSTEP_parameters.Uart_value_to_set; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case DIRECT_CMD: /*!< Set the motor direction */ SIXSTEP_parameters.CW_CCW = SIXSTEP_parameters.Uart_value_to_set; MC_Set_PI_param(&I_parameters); BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case KP_PRM_CMD: /*!< Set the KP PI param command received */ PI_parameters.Kp_Gain = SIXSTEP_parameters.Uart_value_to_set; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case KI_PRM_CMD: /*!< Set the KI PI param command received */ PI_parameters.Ki_Gain = SIXSTEP_parameters.Uart_value_to_set; BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; break; case POTENZ_CMD: /*!< Enable Potentiometer command received */ BUFF_RCV = RXBUFFERSIZE; Uart_cmd_flag = 0; huart2.State = HAL_UART_STATE_READY; HAL_UART_Transmit(&huart2, (uint8_t *)rowLxBuffer, (COUNTOF(rowLxBuffer) - 1),500); UART_FLAG_RECEIVE = TRUE; SIXSTEP_parameters.Potentiometer = SIXSTEP_parameters.Uart_value_to_set; break; } /* switch case */ } /* else */ } /* if */ |
个人还是不怎么习惯使用这种库
因为RDR的值不可能是266啊,最大也不过255.