Connecting to ELM327 BT with HC05 [STM32] (Not as simply as look like)

1.7k Views Asked by At

i would like to connect STM32F4 with ELM327 via bluetooth using HC-05. I've got some specifc problem. Everytime when i try to use "AT+LINK", the HC-05 responds "FAIL".

Hardware:

  • STM32F411V + HC-05
  • iCar2 Vgate elm327 BT v3.0

I've already done:

  1. I've tested ELM327 with commercial Apps, terminals etc. - it connected, and worked well.
  2. I've tested HC-05 - configured, worked very well with BT terminals
  3. Tried to use diffrent configuration of AT Commands to get autoconnection between Elm327 and HC - everytime "FAIL".

This is part of code, which i used:

HAL_UART_Receive_IT(&huart2, BufforMsg, 1);

  HAL_Delay(10000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+ORGL\r\n", strlen("AT+ORGL\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+NAME=MASTER\r\n", strlen("AT+NAME=MASTER\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+UART=9600,1,0\r\n", strlen("AT+UART=9600,1,0\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+RESET\r\n", strlen("AT+RESET\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+ROLE=1\r\n", strlen("AT+ROLE=1\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+PSWD=1234\r\n", strlen("AT+PSWD=1234\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+INIT\r\n", strlen("AT+INIT\r\n"), 100); //HC-05:OK

  HAL_Delay(10000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+RMAAD\r\n", strlen("AT+RMAAD\r\n"), 100); //HC-05:OK

  HAL_Delay(1000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+PAIR=86DC,B0,ABF7F1,20\r\n", strlen("AT+PAIR=86DC,B0,ABF7F1,20\r\n"), 100); //HC-05:OK

  HAL_Delay(21000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+BIND=86DC,B0,ABF7F1\r\n", strlen("AT+BIND=86DC,B0,ABF7F1\r\n"), 100); //HC-05:OK

  HAL_Delay(3000);

  HAL_UART_Transmit(&huart2, (uint8_t *)"AT+LINK=86DC,B0,ABF7F1\r\n", strlen("AT+LINK=86DC,B0,ABF7F1\r\n"), 100); //HC-05:FAIL + INQ: Mac Address

  HAL_Delay(3000);

  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, 0 );

I've tried also diffrent configurations of these commands, but all the time the same -> FAIL. Btw. I know that i set buadrate 9600, but it doesnt matter in AT Commands mode. The light on HC blinks very fast of 1s, then blinks slowly (as well as in connected mode) for 2s, but then blinks again very fast and then again slowly and over and over again. I guess the HC is trying to connect to the Elm all the time. The mac address is correct - i used few MacAdress scanners and the address is similar everywhere. The ELM327 require password every time when i connect to it (even if the device is paired with my smartphone). I read probably all topics on StakOVF and others sites. The solutions, which i found, didnt work. Has anyone idea, what's wrong?

1

There are 1 best solutions below

0
On

Following is the sequence of AT Commands in order to successfully connect to ELM327 Adapter using HC-05:

 - AT+RESET
 - AT+ROLE=1
 - AT+CMODE=0
 - AT+INIT
 - AT+BIND=0011,22,334455 //Replace with MAC Address of ELM327
 - AT+PAIR=0011,22,334455,20 //Replace with MAC Address of ELM327, 20 is the timeout value
 - AT+LINK=0011,22,334455 //Replace with MAC Address of ELM327

You also need to make sure that ELM327 is not connected to any other device while you are attempting this connection. You may have previously connected to mobile phone to test with terminal application. So to be safe, turn off the Bluetooth of your mobile phone.

Also make sure there are appropriate wait times between these AT commands.

If your ELM327 needs password every time you try to connect, you may also use the AT+PSWD command you were using.

After the connection is successful, you may also need to perform configuration at ELM327 using AT commands to set the ISO standard, turn on/off the echo etc.