cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect 3 HC-05 devices using STM32 and CubeIDE?

ahmetgunduz
Associate III

Hi,

i am using STM32F407 and CubeIDE. I am trying to use 1 master and 2 slave at the same time. I can connect any slave to the master. I am trying to implement a sinmple alghoritm for 2 slaves. I change device address which master is connected at 10 seconds interval.And when i try to connect both of them at the same time, my master always stays in AT Mode. It doesn't never blink fast (when it bilnks fast, it indicates that it is not in AT mode and searching for a device). Also my slave sends data. What is the problem with master?

Here is datasheet: https://components101.com/sites/default/files/component_datasheet/HC-05%20Datasheet.pdf

int main(void)
{
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART6_UART_Init();
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); //Reset HC-05
  HAL_Delay(1000);
  HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET);// set high to 'key' pin  to enter AT Mode
  HAL_Delay(1000);
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//set low to reset pin
  HAL_Delay(3000);
  HAL_UART_Transmit(&huart6,(uint8_t*)"AT+ROLE=1\r\n",sizeof("AT+ROLE=1\r\n")-1,100);
  HAL_Delay(1000);
 HAL_UART_Transmit(&huart6(uint8_t*)"AT+CMODE=0\r\n",sizeof("AT+CMODE=0\r\n")-1,100);
  HAL_Delay(1000);
 
 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);
 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//exit AT mode
  /* USER CODE BEGIN 2 */
  __HAL_UART_ENABLE_IT(&huart6,UART_IT_RXNE); //enable usart interrupt
  /* USER CODE END 2 */
 
  while (1)
  {
       /* FIRST SLAVE */
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);
	HAL_Delay(1000);
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET);
	 HAL_Delay(1000);
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//i entered AT mode to change slave addres
	HAL_UART_Transmit(&huart6(uint8_t*)"AT+BIND=98D3,31,F63543\r\n",sizeof("AT+BIND=98D3,31,F63543\r\n")-1,100); //address of slave
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//exit AT mode
 
         HAL_Delay(50000);//wait for data transmission
 
            /*SECOND SLAVE */
       	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);
	HAL_Delay(1000);
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET);
	 HAL_Delay(1000);
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//i entered AT mode to change slave addres
HAL_UART_Transmit(&huart6(uint8_t*)"AT+BIND=98D3:31:F537A2\r\n",sizeof("AT+BIND=98D3:31:F537A2\r\n")-1,100); //address of slave
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);
	 HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);//exit AT mode
 
         HAL_Delay(50000);//wait for data transmission
 }
}

Slave configuration:

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);// reset hc-05
  delay_ms(1000);
  HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET);// set high to 'key' pin  to enter AT
   delay_ms(1000);
  HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);// entered AT mode 
  delay_ms(3000);
  HAL_UART_Transmit(&huart1,(uint8_t*)"AT+ROLE=0\r\n",sizeof("AT+ROLE=0\r\n")-1,100);
  delay_ms(1000);
  HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);//exit AT mode

0 REPLIES 0