Звезда не активнаЗвезда не активнаЗвезда не активнаЗвезда не активнаЗвезда не активна
 


void runCmdFromUart(void){
  uint32_t frequency = 0;
  uint32_t ARR_reg_val = 0;
  uint32_t PSC_reg_val = 7;
  static uint32_t pulses = 1000; //im ms
  
  if(receiveBuffer[0] == 'f'){ //frequency
    frequency += (receiveBuffer[1] - 0x30) *100000;
    frequency += (receiveBuffer[2] - 0x30) *10000;
    frequency += (receiveBuffer[3] - 0x30) *1000;
    frequency += (receiveBuffer[4] - 0x30) *100;
    frequency += (receiveBuffer[5] - 0x30) *10;
    frequency += receiveBuffer[6] - 0x30;
   if(frequency > 10000) 
     PSC_reg_val = 0;
   else
     if(frequency > 100)
     PSC_reg_val = 7;
     else
     PSC_reg_val = 4095;
   
  ARR_reg_val = (BASE_FREQ/(PSC_reg_val+1))/frequency;
  LL_TIM_WriteReg(TIM1, PSC, PSC_reg_val);
  LL_TIM_WriteReg(TIM1, ARR, ARR_reg_val);
  
  CountTim1P = pulses-1;
  LL_TIM_WriteReg(TIM1, CCR1, 0);
  LL_TIM_OC_SetCompareCH4(TIM1, (ARR_reg_val/2)); //50% PWM, 100 kHz
  
  
  
  }
  if(receiveBuffer[0] == 'd'){
    if(receiveBuffer[1] == '1')
      LL_GPIO_ResetOutputPin(DIR_GPIO_Port,DIR_Pin);
    else
      if(receiveBuffer[1] == '0')
        LL_GPIO_SetOutputPin(DIR_GPIO_Port,DIR_Pin);
  }
  if(receiveBuffer[0] == 'e'){
    if(receiveBuffer[1] == '1')
      LL_GPIO_ResetOutputPin(ENABLE_GPIO_Port,ENABLE_Pin);
    else
      if(receiveBuffer[1] == '0')
        LL_GPIO_SetOutputPin(ENABLE_GPIO_Port,ENABLE_Pin);
  }
  if(receiveBuffer[0] == 'p'){ //pulses
   pulses = 0;
   pulses += (receiveBuffer[1] - 0x30) *100000000;
   pulses += (receiveBuffer[2] - 0x30) *10000000;
   pulses += (receiveBuffer[3] - 0x30) *1000000;
   pulses += (receiveBuffer[4] - 0x30) *100000;
   pulses += (receiveBuffer[5] - 0x30) *10000;
   pulses += (receiveBuffer[6] - 0x30) *1000;
   pulses += (receiveBuffer[7] - 0x30) *100;
   pulses += (receiveBuffer[8] - 0x30) *10;
   pulses += receiveBuffer[9] - 0x30;
  }

}

void TIM1_CC_IRQHandler(void)
{
  /* USER CODE BEGIN TIM1_CC_IRQn 0 */

  /* USER CODE END TIM1_CC_IRQn 0 */
  /* USER CODE BEGIN TIM1_CC_IRQn 1 */
  LL_TIM_ClearFlag_CC1(TIM1);
  if(CountTim1P)
    CountTim1P--;
  else 
    LL_TIM_OC_SetCompareCH4(TIM1, 0xFFFF);
  /* USER CODE END TIM1_CC_IRQn 1 */
}