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.

CCS/EK-TM4C123GXL: Connecting the HC-06 Bluetooth to the TM4C123 Microcontroller

Part Number: EK-TM4C123GXL


Tool/software: Code Composer Studio

Hey guys,

So I've been learning the TM4C123 for a bit and I've hit a snag when connecting to a different UART pin. Because I'm trying to run SensHub and the HC-06 on the same controller I'm restricted by what pins I can connect to, so I tried to move an example of UART1 to UART3, and while following the workbook and datasheet I can't see where my error is. 

When running with UART 1 this is the code and the output:

#include <stdint.h>
#include <stdbool.h>

#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "uart.h"
#include "uartstdio.h"


int main(void) {
 SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

 SysCtlPeripheralReset(SYSCTL_PERIPH_UART1);
 SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

 GPIOPinConfigure(GPIO_PB0_U1RX);
 GPIOPinConfigure(GPIO_PB1_U1TX);

 GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

 UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC); //16 MHz crystal oscill
 UARTStdioConfig(1, 38400, 16000000); //port 1, baud rate, 16 MHz oscill



 IntMasterEnable(); //enable processor interrupts
 IntEnable(INT_UART1); //enable the UART interrupt
 UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts

  UARTCharPut(UART1_BASE, 'E');
  UARTCharPut(UART1_BASE, 'n');
  UARTCharPut(UART1_BASE, 't');
  UARTCharPut(UART1_BASE, 'e');
  UARTCharPut(UART1_BASE, 'r');
  UARTCharPut(UART1_BASE, ' ');
  UARTCharPut(UART1_BASE, 'T');
  UARTCharPut(UART1_BASE, 'e');
  UARTCharPut(UART1_BASE, 'x');
  UARTCharPut(UART1_BASE, 't');
  UARTCharPut(UART1_BASE, ':');
  UARTCharPut(UART1_BASE, ' ');


 while (1) //let interrupt handler do the UART echo function
 {
     // if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
 }
}

void UARTIntHandler(void)
{
 uint32_t ui32Status;

 ui32Status = UARTIntStatus(UART1_BASE, true); //get interrupt status

 UARTIntClear(UART1_BASE, ui32Status); //clear the asserted interrupts

 while(UARTCharsAvail(UART1_BASE)) //loop while there are chars
 {
     UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE)); //echo character

 }
}

However, when trying to switch to UART 3 I don't get any output. This is the code:

Actually, It seems this version get's stuck on the first character.

#include <stdint.h>
#include <stdbool.h>

#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "uart.h"
#include "uartstdio.h"


int main(void) {
 SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

 SysCtlPeripheralReset(SYSCTL_PERIPH_UART3);
 SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOC);

 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

 GPIOPinConfigure(GPIO_PC6_U3RX);
 GPIOPinConfigure(GPIO_PC7_U3TX);

 GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

 UARTClockSourceSet(UART3_BASE, UART_CLOCK_PIOSC); //16 MHz crystal oscill
 UARTStdioConfig(3, 38400, 16000000); //port 1, baud rate, 16 MHz oscill



 IntMasterEnable(); //enable processor interrupts
 IntEnable(INT_UART3); //enable the UART interrupt
 UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); //only enable RX and TX interrupts

  UARTCharPut(UART3_BASE, 'E');
  UARTCharPut(UART3_BASE, 'n');
  UARTCharPut(UART3_BASE, 't');
  UARTCharPut(UART3_BASE, 'e');
  UARTCharPut(UART3_BASE, 'r');
  UARTCharPut(UART3_BASE, ' ');
  UARTCharPut(UART3_BASE, 'T');
  UARTCharPut(UART3_BASE, 'e');
  UARTCharPut(UART3_BASE, 'x');
  UARTCharPut(UART3_BASE, 't');
  UARTCharPut(UART3_BASE, ':');
  UARTCharPut(UART3_BASE, ' ');


 while (1) //let interrupt handler do the UART echo function
 {

 }
}

void UARTIntHandler(void)
{
 uint32_t ui32Status;

 ui32Status = UARTIntStatus(UART3_BASE, true); //get interrupt status

 UARTIntClear(UART3_BASE, ui32Status); //clear the asserted interrupts

 while(UARTCharsAvail(UART3_BASE)) //loop while there are chars
 {
     UARTCharPutNonBlocking(UART3_BASE, UARTCharGetNonBlocking(UART3_BASE)); //echo character

 }
}

Thank you for any help or suggestions.

  • Hello Kala,

    For the bottom example,

    UARTStdioConfig(3, 38400, 16000000); //port 1, baud rate, 16 MHz oscill

    That configuration is incorrect. The port cannot be set to 3 for that API, only 0-2 are acceptable inputs. That may be the issue with that code.

    For the top example which is what you ultimately want working, do you hit any FaultISR's if you pause the code? If so, you may not have transferred the ISR from UART3 to UART1 in the startup_ccs.c file. Just my first guess based on what is presented initially.

  • Hey Ralph,

    Okay, I'll look into UARTStdioConfig. I didn't know that it only worked for 0-2.  Though, just for expedience, is there a command that works like UARTStdioConfig for UART3?

    I do get stuck in a FaultISR and I did thing about the startup_ccs.c file so I double checked and I do have the extern call:

    //Extern Declaration for Interrupts
    extern void UARTIntHandler(void);


    And I believe I moves the ISR correctly?

        IntDefaultHandler,                      // UART0 Rx and Tx
        IntDefaultHandler,                      // UART1 Rx and Tx


        IntDefaultHandler,                      // SSI2 Rx and Tx
        IntDefaultHandler,                      // SSI3 Rx and Tx
                UARTIntHandler,                      // UART3 Rx and Tx
        IntDefaultHandler,                      // UART4 Rx and Tx
        IntDefaultHandler,                      // UART5 Rx and Tx


    Thank you,
    Kala

  • Here is a portion of the schematic I was trying to implement, if it's helpful?

  • Hello Kala,

    There isn't any other commands for Port 3 and beyond but you can add them such as discussed in this post: e2e.ti.com/.../1283926

    The ISR does look like it's moved correctly and actually I should have said you would have landed in IntDefaultHandler if you hadn't. Landing in Fault ISR is a very good clue for debug though.

    Let's focus on UART1 since that is what you need ultimately.

    I tested your code out by using UART0 which lets me see console output on PC and had no issues with the setup. Can you change the startup_ccs.c file to reflect the UART1 setup and then try running that code and see if you get into FaultISR with that?
  • Hey Ralph,

    Sorry for the delay, I am having an issue with the PWM response speed of my project that I had to fix and then when it was I found that I'm getting junk reads when the balancing bot is oscillating too quickly, which I'm still working on.

    BUT thank you, I got some time today and worked through the page you linked and it worked a charm. I've updated the uartstdio.c file and UART3 is now enabled in the example code, so I should know what to do to implement it in my project now.

    Side note, because I was jumping between uart1 and 3 when I was writing up my examples to ask ppl where there were errors. I did forget to more the interrupt in startup the second time going back to uart3 and the error loop I was supposed to go into was the IntDefaultHandler.

    Thank you!
    Kala
  • May I add that your naming your UART Interrupt Handler, "UARTIntHandler" is likely too broad.     (and nondescript!)

    Adding the number of the specific interrupt (i.e. "UARTIntHandler3") yields far more clarity - especially important as (other) interrupts (even other UARTs) are added to your, 'witches brew.'     (Not that you - by any ways/means - resemble those employing 'Non-Bot' brooms - for transport...)