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);
}
}