Micro-controllers, wireless transmission and database
This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A
Enable USART1 asynchronous
Parameter Settings --> Basic Parameters --> Baud rate 9600
NVIC Settings --> USART1 global interrupt --> (Tick)
Click Timer → Click TIM2 →
Clock Source set to Internal Clock
Channel2 set to PWM Generation CH2
Configuration → Parameter Settings →
Prescaler set to 127
Counter Period 625
/* USER CODE BEGIN PV */ uint8_t rx_data; int pwm = 0; /* USER CODE END PV */ /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); HAL_UART_Receive_IT(&huart1,&rx_data,1); // receive data (one character only) /* USER CODE END 2 */ /* USER CODE BEGIN 4 */ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if(huart->Instance==USART1) { if(rx_data == 82) //if "R" reset { pwm = 0; } else if(rx_data == 65) // if "A" set pwm { __HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_2, pwm * 2); } else if(rx_data > 47 && rx_data < 58) // if "0" - "9" construct { pwm = pwm * 10 + rx_data - 48; } // Enabling interrupt receive again (one character only) HAL_UART_Receive_IT(&huart1,&rx_data,1); } } /* USER CODE END 4 */