请问怎么提供串口大师给STM32F302-NUCLEO发送指令

2019-07-14 15:29发布

在使用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 */  
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
16条回答
Ryita
1楼-- · 2019-07-14 21:53
自己也改过串口参数,但是有问题,有时候串口就堵死了,就想看看官方实现的是怎么样,有没有可以参考的资料啊
xieweibin
2楼-- · 2019-07-14 23:16
可能是串口的数据长度不能超过266个。
Green_LJ
3楼-- · 2019-07-15 02:27
 精彩回答 2  元偷偷看……
YZDIC
4楼-- · 2019-07-15 04:30
个人还是不怎么习惯使用这种库
zhi168
5楼-- · 2019-07-15 05:41
签到是一种态度
60user189
6楼-- · 2019-07-15 10:48
个人还是不怎么习惯使用这种库

一周热门 更多>