AnsweredAssumed Answered

HC-06 Bluetooth Module Configure with UART

Question asked by schenk.kyle on Jul 11, 2014
Latest reply on Jul 11, 2014 by Andrew Neil
Hi,

I would like to know if it would be better to send AT commands to the HC-06 Bluetooth module via an interrupt handler or a while(1) in the main as well as some pointers on the code I am trying to get correct and working. I am not sure if I require delays to allow module to reply. Perhaps some kind of scan and printf to see what is being sent and received would help, something like below?

void USART1_IRQHandler(void)
{
  static int tx_index = 0;
  static int rx_index = 0;
    char StringRX[12];
    volatile char StringAT[] = "AT";
    volatile char StringBAUD[] = "AT+BAUD4";
    volatile char StringNAME[] = "AT+NAMETest";
    volatile char StringPIN[] = "AT+PIN4321";

  // ------------------StringAT------------------
  if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)        
  {
    USART_SendData(USART1, StringAT[tx_index++]);
   
    if (tx_index >= (sizeof(StringRX) - 1))
      tx_index = 0;
  }
    
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // Received characters modify string
  {
    StringRX[rx_index++] = USART_ReceiveData(USART1);
   
    if (rx_index >= (sizeof(StringRX) - 1))
      rx_index = 0;
  }
    
    // ------------------StringBAUD------------------
    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // Transmit the string in a loop
  {
    USART_SendData(USART1, StringBAUD[tx_index++]);
   
    if (tx_index >= (sizeof(StringRX) - 1))
      tx_index = 0;
    }
    
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // Received characters modify string
  {
    StringRX[rx_index++] = USART_ReceiveData(USART1);
   
    if (rx_index >= (sizeof(StringRX) - 1))
      rx_index = 0;
  }
    
    // ------------------StringNAME------------------
    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // Transmit the string in a loop
  {
    USART_SendData(USART1, StringNAME[tx_index++]);
   
    if (tx_index >= (sizeof(StringRX) - 1))
      tx_index = 0;
  }
    
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // Received characters modify string
  {
    StringRX[rx_index++] = USART_ReceiveData(USART1);
   
    if (rx_index >= (sizeof(StringRX) - 1))
      rx_index = 0;
  }
    
    // ------------------StringPIN------------------
    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // Transmit the string in a loop
  {
    USART_SendData(USART1, StringPIN[tx_index++]);
   
    if (tx_index >= (sizeof(StringRX) - 1))
      tx_index = 0;
  }
    
    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // Received characters modify string
  {
    StringRX[rx_index++] = USART_ReceiveData(USART1);
   
    if (rx_index >= (sizeof(StringRX) - 1))
      rx_index = 0;
  }
}

Outcomes