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.

EK-TM4C123GXL: Struggling to send 2-character commands over bluetooth & UART. Help appreciated.

Part Number: EK-TM4C123GXL

I'm trying to get my TM4C communicating over Bluetooth with a BLUESMiRF Silver device. I would like to send simple two-letter commands from my laptop to the BLUESMiRF via Bluetooth, and then via UART from the BLUESMiRF to the TM4C.

Laptop ---(Bluetooth)---> BLUESMiRF ---(UART)---> TM4C

My connections are as follows:

TM4C UART PB0 RX <----> BLUESMiRF TX

TM4C UART PB1 TX <---> BLUESMiRF RX

TM4C +3.3V <---> BLUESMiRF Vcc

TM4C GND <---> BLUESMiRF GND

I am powering the TM4C via micro-USB connected to my PC.

I am trying to type the commands into Tera Term that is connected to a COM port that is the Bluetooth connection to the BLUESMiRF. When I connect to the correct COM it verifies my Bluetooth connection by lighting a green LED on the BLUESMiRF.

If somebody could check my code and see if something is wrong, I would be very appreciative. When I type in Tera Term I'm expecting it to send the data to the TM4C and trigger a UART RX interrupt, and then print certain information depending on the data sent. Thanks.

-----------------------------------------------------------------------------

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include <string.h>

#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

char command[2] = " ";
char speed[4] = " ";

void UART1Handler(void)
{
uint32_t ui32Status;
ui32Status = ROM_UARTIntStatus(UART1_BASE, true);
ROM_UARTIntClear(UART1_BASE, ui32Status);

UARTgets(command, strlen(command) + 1);
UARTprintf("\n");
if (!strcmp(command, "SS")) // Set Speed
{
UARTprintf("Please enter desired motor speed from 1-100 percent.\n");
UARTgets(speed, strlen(speed) + 1);
}
else if (!strcmp(command, "ES")) // Emergency Stop
{
UARTprintf("Stopping motors...");
}
else if (!strcmp(command, "ST")) // Start
{
UARTprintf("Starting motors...");
}

UARTprintf("\n");
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
SysCtlDelay(10000000);
}

void ConfigureUART(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
ROM_IntMasterEnable();
ROM_GPIOPinConfigure(GPIO_PB0_U1RX);
ROM_GPIOPinConfigure(GPIO_PB1_U1TX);
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(1, 115200, 16000000);
IntRegister(INT_UART1, UART1Handler);
ROM_IntEnable(INT_UART1);
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_TX);
}

/******************************************* MAIN ***********************************************/
int main(void)
{
ROM_FPULazyStackingEnable();
ROM_SysCtlClockSet(
SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
ConfigureUART();
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
while (1)
{

}
}

  • I did not see anything in the code. Have you verified that you are receiving characters from the BLUESMiRF device by looking at the BLUESMiRF TX pin with a scope? Also make sure that R29 (just to the left of the 32KHz crystal) is unpopulated.

    Once you get the receive interrupt working, I suggest you not do all of your work inside of the interrupt routine. In general, you should get in and out of an interrupt quickly. For this simple exercise you might not use interrupts at all. A better way to use the interrupt would be to simply read a single character in the receive interrupt routine and put it in a buffer. Check if that character ended the command, either by checking the number of characters you received, or checking if the character is a return '\r'. If a new command was received, set a flag and return to your main loop. In the main loop, you constantly check for the flag that says you have a new command to process. While it may not seem necessary now, if the project grows and uses other interrupts, you will find that you do not respond to the other interrupts quickly enough because you spent too much time in the UART1Handler routine.