Disconnect and connection problem with BC118 + STM32

Hi, I’m using BC118 module with a host STM32L1 and I have almost perfect connection I send and receive frames without problem but, when I try to disconnect and connect Smart Melody from Android mobile and I try send again frames my device freeze it, and I don’t know why, my config is:

HAL_UART_Transmit(&huart2, (uint8_t*)“RTR\r”, 4, 1000);// 1s
HAL_UART_Transmit(&huart2, (uint8_t*)“RST\r”, 4, 1000); // 1s
HAL_UART_Transmit(&huart2, (uint8_t*)“SET ADVP=SLOW\r”, 14, 1000); //
HAL_UART_Transmit(&huart2, (uint8_t*)“SET ADVS=5000 5000\r”,19 , 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)“SET SNAME=376A44\r”, 17, 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)“WRT\r”, 4,1000);
HAL_UART_Transmit(&huart2, (uint8_t*)“RST\r”, 4, 1000);

sometimes I try to use this parameter but I’m not sure if it is useful

//HAL_UART_Transmit(&huart2, (uint8_t*)“SET BOND=ON\r”, 12, 1000);

Maybe I have problem in my code, but maybe not.

Thank a lot for your help and time.

David Steckler.