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.

Bluetooth module hc05 with tiva launchpad

Other Parts Discussed in Thread: TM4C123GH6PM

I am using bluetooth module HC-05 , it works on the UART module, i am using UART1, and have connected to my TIVA Launchpad and my laptop. I am able to transmit data from TIVA launchpad to laptop, but when i doing it vice-versa that is from laptop to TIVA Launchpad data i receive on Launchpad is corrupted many times(around 7 times out of 10 trials).

Following is the link of HC05 bluetooth module with arduino: http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/?ALLSTEPS

I am sending HELLO string from launchpad to Laptop, then i am sending a character from laptop to launchpad, and printing it back, when i receive 0 it turn off the LED else LED will light up.

What actually happening is I am Hello string on terminal of my laptop but the character i am sending from laptop to launchpad is some garbage value many times.

Below is my code: 

/* Defines the base address of the memories and peripherals */

#include "inc/hw_memmap.h"

/* Defines the common types and macros */
#include "inc/hw_types.h"

/* Defines and Macros for GPIO API */
#include "driverlib/gpio.h"
#include "inc/hw_gpio.h"
/* Prototypes for the system control driver */
#include "driverlib/sysctl.h"

/* Defines and Macros for UART API */
#include "driverlib/uart.h"
#include "inc/lm4f230h5qr.h"

tBoolean flag=0;
unsigned char a,b;
int main(void)
{
/*Set the clocking to directly run from the crystal at 8MHz*/
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);


/* Make the UART pins be peripheral controlled. */
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//Enabling PF1 as output
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
/* Sets the configuration of a UART. */
UARTConfigSetExpClk(UART1_BASE,16000000, 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

while(1)
{
UARTCharPut(UART1_BASE,72);//H
UARTCharPut(UART1_BASE,69);//E
UARTCharPut(UART1_BASE,76);//L
UARTCharPut(UART1_BASE,76);//L
UARTCharPut(UART1_BASE,79);//O
while(!UARTCharsAvail(UART1_BASE));
a=UARTCharGet(UART1_BASE);
if(a == 48)
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
}
UARTCharPut(UART1_BASE,a);
}

}

  • Hi Sarthak,

    Can you put a break point at UARTCharGet and instead of reading the data in a variable read the same through the debugger by directly accessing the UART_O_DR register. Do make sure that you read the entire 32-bits of data. The lower 8 bits is the character that you have sent from Laptop to Launch pad and the nexy 4 bits will show if there is an error.

    Regards

    Amit Ashara

  • hi amit,

    Actually i am using custom toolchain on eclipse, and debugger is not running, but instead of bluetooth if i connect FTDI232(https://www.sparkfun.com/products/retired/8772) on the same uart, run the same code launchpad start receiving the correct data, also i have tested the bluetooth module on arduino and its working smooth.

    regards

  • Sarthak Gupta said:
    character i am sending from laptop to launchpad is some garbage value many times.

    Use of a scope - to measure incoming, UART bit widths - could not hurt.

    Diagnosis (key register read/review) surely valid.  In addition - insure that the ground connection between your MCU board & remote UART is solid/proper.   [edit1]  (See now that you're using external xtal!)   Further  -  we don't see which source you've chosen for System Clock - highest UART accuracy results when proper, external xtal w/ proper (to spec) bypass caps are employed.  IIRC - an error of >5% will "disorder" UART bit recovery - your error rate is high enough to suggest this may be your causal nexus...

    Your report of success w/FTDI module concerns - that is (iirc) a USB to UART converter - thus it's "unclear" as to how you interposed the FTDI module between HC-05 "Uart" (one assumes) and the FTDI module...

    Suspect now that you did NOT place FTDI module between HC-05 & MCU - instead between laptop (via USB) & MCU.  (which is NOT "apples to apples comparison)   Thus - the bit rate of HC-05 AND the ground connection between HC-05 & MCU "remain (likely) unknown/untested" by that FTDI "test..."

    [edit 2]  Visited your link - your module is MCU "Safe."  One other "horror" invades - that HC-05 must xmit CMOS (3V3) signal levels - NOT RS232!   Such will likely damage the MCU's RX pin - from any MCU maker.  Level translators are normal/customary means of managing RS232 to MCU (CMOS) signal level translations...

    Yet one more idea - HC-05 lists power draw @ 3V3 of ~50mA.  Perhaps that increases under transmit - and if you've "stolen/borrowed" power from the launchpad - the 3V3 regulator may "dip." 

  • Whenever I connect scope to the UART Rx, PB0 of Launchpad. The Uart stops receiving the data (though data earlier it was receiving was corrupt), but when i connect pullup resistor (or uses internal pull up) to uart rx pin (PB0), it starts receiving data correctly and also it showing it nicely on scope too.

    Just for my curiosity what is the internal pull up resistor value? I checked it in datasheet of TM4C123GH6PM but didnt find it.

  • Hello Sarthak,

    The internal Pull Up/Down is 20K with MIN-MAX variation of of 13-35K. Please note that UART protocol assumes that the bus idle state is Level High. Hence the UART TX has to ensure that the line is pulled high when not transmitting a data. That is why using a Pull Up recovers UART to work correctly.

    Please check if the UART TX pin from the device which is sending to TM4C UART RX drives the line high when there is no active transaction

    Regards

    Amit

  • Hello,

    I am also working on a UART1 of TIVAC launchpad. So I have did its initialization but on my terminal window it was nothing. I am also pasting my code for your reference if anybody can rectify what would be the issue of not getting my output.

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

    volatile int g_ui32Flags;


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

    void Timer0IntHandler(void)
    {
    char cOne, cTwo;
    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    HWREGBITW(&g_ui32Flags, 0) ^= 1;
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, g_ui32Flags << 1);
    ROM_IntMasterDisable();
    cOne = HWREGBITW(&g_ui32Flags, 0) ? '1' : '0';
    cTwo = HWREGBITW(&g_ui32Flags, 1) ? '1' : '0';
    UARTprintf("\rT1: %c T2: %c", cOne, cTwo);
    ROM_IntMasterEnable();
    }
    void Timer1IntHandler(void)
    {
    char cOne, cTwo;
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    HWREGBITW(&g_ui32Flags, 1) ^= 1;
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, g_ui32Flags << 1);
    ROM_IntMasterDisable();
    cOne = HWREGBITW(&g_ui32Flags, 0) ? '1' : '0';
    cTwo = HWREGBITW(&g_ui32Flags, 1) ? '1' : '0';
    UARTprintf("\rT1: %c T2: %c", cOne, cTwo);
    ROM_IntMasterEnable();
    }

    unsigned char inbyte;
    int main(void)
    {
    //Setting clock
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //initialize UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);


    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_2);

    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_PIN_2);
    SysCtlDelay(SysCtlClockGet() / 30);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0);


    UARTConfigSetExpClk(UART1_BASE,16000000, 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 9600, 16000000);
    UARTprintf("welcome");


    while(1)
    {
    UARTCharPut(UART1_BASE,'s');
    UARTCharPut(UART1_BASE,'t');
    UARTCharPut(UART1_BASE,'a');
    UARTCharPut(UART1_BASE,'r');
    UARTCharPut(UART1_BASE,'t');
    while(!UARTCharsAvail(UART1_BASE));
    inbyte=UARTCharGet(UART1_BASE);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_PIN_2);
    SysCtlDelay(SysCtlClockGet() / 30);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0);

    UARTCharPut(UART1_BASE,inbyte);
    }

    }

    If I  make make change from UART1 to UART0 it works fine. Other than UART0 i tried on every other UART it did not worked on any other UART i.e. from UART1 to UART7. I have connected launchpad to my PC and I am checking on my Terminal window. I am not even getting "hello" if I use any other UART other than UART0. Is there anything missing out in my code? Or is there any thing related to hardware?

  • Hi I am also facing the same problem......UART0 is working fine and rest i checked on UART1 is not working.....Can anybody sort out this problem for us.

    Thanks

  • Hello Sushil,

    I would suggest attaching the code and scope/LA snapshots to see what is happening on the UART RX and TX lines. Please do make sure that the UART RX into Tiva is not 0.

    Regards

    Amit

  • Hi Amit Sir,

    here is the code,error is giving on the lines GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX);

    Please resolve it for me...

    Thanks

    /* Defines the base address of the memories and peripherals */

    #include "inc/hw_memmap.h"

    /* Defines the common types and macros */
    #include "inc/hw_types.h"
    #include "utils/uartstdio.h"
    #include "inc/hw_ints.h"
    /* Defines and Macros for GPIO API */
    #include "driverlib/gpio.h"
    #include "inc/hw_gpio.h"
    /* Prototypes for the system control driver */
    #include "driverlib/sysctl.h"

    /* Defines and Macros for UART API */
    #include "driverlib/uart.h"
    #include "inc/lm4f230h5qr.h"


    int main(void) {
    /*Set the clocking to run at 16Mhz using PLL from the crystal at 16MHz*/
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

    /* Make the UART pins be peripheral controlled. */
    GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);


    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);

    //Enabling PF1 as output
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
    /* Sets the configuration of a UART. */
    UARTConfigSetExpClk(UART1_BASE, 16000000, 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    while (1) {

    while (!UARTCharsAvail(UART1_BASE))
    ;
    a = UARTCharGet(UART1_BASE);
    switch (a) {
    case 87:
    UARTCharPut(UART1_BASE, 70); //F
    UARTCharPut(UART1_BASE, 79); //O
    UARTCharPut(UART1_BASE, 82); //R
    UARTCharPut(UART1_BASE, 87); //W
    UARTCharPut(UART1_BASE, 65); //A
    UARTCharPut(UART1_BASE, 82); //R
    UARTCharPut(UART1_BASE, 68); //D
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0);
    break;
    case 90:
    UARTCharPut(UART1_BASE, 66); //B
    UARTCharPut(UART1_BASE, 65); //A
    UARTCharPut(UART1_BASE, 67); //C
    UARTCharPut(UART1_BASE, 75); //K
    UARTCharPut(UART1_BASE, 87); //W
    UARTCharPut(UART1_BASE, 65); //A
    UARTCharPut(UART1_BASE, 82); //R
    UARTCharPut(UART1_BASE, 68); //D
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_PIN_2);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1);
    break;
    case 65:
    UARTCharPut(UART1_BASE, 76); //L
    UARTCharPut(UART1_BASE, 69); //E
    UARTCharPut(UART1_BASE, 70); //F
    UARTCharPut(UART1_BASE, 84); //T
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0);
    break;
    case 68:
    UARTCharPut(UART1_BASE, 82); //R
    UARTCharPut(UART1_BASE, 73); //I
    UARTCharPut(UART1_BASE, 71); //G
    UARTCharPut(UART1_BASE, 72); //H
    UARTCharPut(UART1_BASE, 84); //T
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0);
    break;


    }

    }
    return 0;

    }

  • Hello Sushil,

    The compilation error is due to missing include file "driverlib/pin_map.h"

    Is that what you meant by error in the lines for GPIOPinConfigure?

    Regards

    Amit

  • Hi Amit Sir,

    Sir but after including  "driverlib/pin_map.h" then also same compilation error showing....

    Is there anything else is missing??

  • Hello Sushil,

    Can you please paste the compilation log?

    Regards

    Amit

  • Amit Sir here is the compilation log...

  • Hello Sushil,

    By compilation log I meant the Console Output. That is the 3rd tab to the right. Please paste the entire log.

    Regards

    Amit

  • Hello Sushil,

    It seems that you are using StellarisWare and not TivaWare. if that is the case then please switch to TivaWare. If that is not the case then open the file pin_map.h in driverlib and search for PART_TM4C123GH6PM and see if the defines for GPIO_PB0_U1RX and GPIO_PB1_U1TX are there/

    Regards

    Amit

  • Amit sir....i checked GPIO_PB0_U1RX and GPIO_PB1_U1TX  these lines are declared overthere.... 

  • Hello Sushil,

    Please zip and attach the CCS project and the pin_map.h from your data base

    Regards

    Amit

  • Hello Sushil,

    I opened the file pin_map.h you sent and it clearly is the StellarisWare version. Following is line-21 from the same file

    // This is part of revision 8555 of the Stellaris Peripheral Driver Library.

    Clearly you have not migrated the code base to TivaWare. Can you please change the include paths to the TivaWare.

    Regards

    Amit

  • Hello Amit Sir,

    I dont know how exactly to migrate the code of stellarisware toTivaWare..

    Please tell me the right procedures to switch to TivaWare

    Thanks

  • Hello Sushil,

    The right process would be to import one of the example project for the correct TM4C device into CCS and then modify the content of the C file as per your requirements.

    Regards

    Amit