This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial port "Hello world" with Bluetooth Device



Hello,

We have been struggling trying to do a "hello world" with a bluetooth device that runs using AT commands (serial commands).      What is even more embarrassing is that we have code that is already working since this is already a commercial device.  We need to update the device due to obsolescence but cant even step through the code to get a response to the commands we send using the original (obsolete bluetooth module).

We know the obsolete BT module (Microchip RN42) is properly configured as we can send serial commands to it at a baud rate of 115k directly from a computer.  We can thus change the name and put it in command mode (using $$$).  Its only when its connected to the MSP430 that we cant get a response.

For the first command we need to send, $$$ (puts it into command mode), there is an expected response shown in the code below in bold.  Basically when we send the command $$$ from the microcontroller, the BT module should respond "END".  However, we never get an expected character.   

Things we have done to debug this problem.

        ---We have a COM port terminal open in the code composer studio but we can get a blip (nothing changes).  We try to type  the $$$ characters into the terminal, we still dont get a response. 

        ---When we step through the code, none of the key "expression"  change to anything expected although they do seem to change.  example shown below after transmitting the first $.

 

Questions

   How do you type characters into the com port terminal so as to send them to the remote bluetooth module.  Do I just type into the space shown below although I cant see any of the characters being typed?

  Another question, is there a better way to trap the error or what is causing this?

void ATxBT(void) {

// ------------------------------------------------------------------
// This command causes the device to ENTER COMMAND MODE, return "CMD"
repeat = 1;
while(repeat){
SendString("$$$",1);
}

}


void SendString(const char * s, int ATstate)
{
volatile char received = 0;
volatile uint32_t WaitCounter = 0;

unsigned char g;

while(*s){
g=(*s++);
Transmit232(g);
}

WaitCounter = 0x00000000;
while (!((UCA1IFG&UCRXIFG) | ((WaitCounter == 0xFFFFF)))) {
WaitCounter++;
}
received = UCA1RXBUF; // Expected "C, A or E" character
if (received == 'C' | received == 'A' | received == 'E') {
while(!(UCA1IFG&UCRXIFG));
received = UCA1RXBUF; // Expected "M, O or N" character
if (received == 'M' | received == 'O' | received == 'N') {
while(!(UCA1IFG&UCRXIFG));
received = UCA1RXBUF; // Expected "D, K or D" character
if (received == 'D' | received == 'K' | received == 'D') {
repeat = 0;
}
}
}

// READ LAST CHARACTERS RESPONSE <CR><LF>
while (!((UCA1IFG&UCRXIFG) | ((WaitCounter == 0xFFFFF))));
received = UCA1RXBUF;
while (!((UCA1IFG&UCRXIFG) | ((WaitCounter == 0xFFFFF))));
received = UCA1RXBUF;

// Change microcontroller UART Baud Rate to 115K (bluetooth default)
if (WaitCounter == 0xFFFFF){

UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; // Baud Rate Source BRCLK = SMCLK

// Config 115200 baud rate with 25MHz system clock (SMLK)
// processors.wiki.ti.com/.../USCI_UART_Baud_Rate_Gen_Mode_Selection
UCA1BR0 = 217; // 115200
UCA1BR1 = 0; // 115200 According to User's Guide.
UCA1MCTL = UCBRS_0 + UCBRF_0; // Modulation UCBRSx=0, UCBRFx=0

UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt

flagchangebaudrate = 1;
__delay_cycles(6000000); // Delay for UART to settle
}

}

void Transmit232(unsigned char CharToSend)
{
UCA1TXBUF = CharToSend; // Load buffer with CharToSend
while(!(UCA1IFG&UCTXIFG)); // Wait transmite complete
}

Really appreciate any help we can get 

thank you

Jim