Docs

Micro-controllers, wireless transmission and database

Head

STM32 HC-05 Bluetooth Module

Prerequisites

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

Wiring Diagram

Diagram

Image1

Image2

STM32CubeIDE Settings

Set PA1 to GPIO_Output

Enable USART1 asynchronous

Parameter Settings --> Basic Parameters --> Baud rate 9600

NVIC Settings --> USART1 global interrupt --> (Tick)

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN PV */
uint8_t rxData;
/* USER CODE END PV */

  /* USER CODE BEGIN 2 */
  HAL_UART_Receive_IT(&huart1,&rxData,1); // Enabling interrupt receive
  /* USER CODE END 2 */

/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if(huart->Instance==USART1)
  {
    if(rxData==78) // Ascii value of 'N' is 78 (N for NO)
    {
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 0);
    }
    else if (rxData==89) // Ascii value of 'Y' is 89 (Y for YES)
    {
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 1);
    }
    HAL_UART_Receive_IT(&huart1,&rxData,1); // Enabling interrupt receive again
  }
}
/* USER CODE END 4 */