Hi!
I would like to use bluetooth in my project . So I have to use UART1 but I can't do it. Please help me...
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.
Hi!
I would like to use bluetooth in my project . So I have to use UART1 but I can't do it. Please help me...
Hello Emre,
What is the issue? Can you refer to the UART_ECHO example and modify it for UART-1
The changes that need to be done
1. UART0_BASE to be replaced with UART1_BASE
2. UART-1 IO to be configured for RX and TX instead of UART-0. Please do refer to the Signal Description table of the data sheet and the pin_map.h for the actual define to be used?
Regards
Amit
Hello Amit;
I can send data with UART0 to serial port. There is no problem here. But I can't do it with UART1 . I modify for port B0 and port B1 Rx-Tx but it does not work. Where is my fault? İstehere anything extra to send data with bluetooth..
Hello Emre,
A code post would be useful as it is working with UART0 and not UART1
Regards
Amit
Hello Amit,
I've simple UART0 code. I changed it to UART1 but it does not work for my bluetooth. Must I do extra things for it. Can you help me about this. This is my code....
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "string.h"
#include "driverlib/adc.h"
#include "uartstdio.h"
#include "lm4f120h5qr.h"
#include "driverlib/qei.h"
#define GPIO_PA0_U0RX 0x00000001
#define GPIO_PA1_U0TX 0x00000401
#define GPIO_PB0_T2CCP0 0x00010007
#define GPIO_PB1_T2CCP1 0x00010407
#define GPIO_O_LOCK 0x00000520 // GPIO Lock
#define GPIO_LOCK_KEY_DD 0x4C4F434B
#define GPIO_O_CR 0x00000524
unsigned long ulPeriod;
char i;
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
void delay (unsigned long int id){
while(id--);
}
void UARTIntHandler(void)
{
unsigned long ulStatus;
//
// Get the interrrupt status.
//
ulStatus = UARTIntStatus(UART0_BASE, true);
//
// Clear the asserted interrupts.
//
UARTIntClear(UART0_BASE, ulStatus);
//
// Loop while there are characters in the receive FIFO.
//
while(UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
i=UARTCharGetNonBlocking(UART0_BASE);
//
// Blink the LED to show a character transfer is occuring.
//
if(i=='k')
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
else if(i=='y')
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_3);
//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(SysCtlClockGet() / (1000 * 3));
//
// Turn off the LED
//
}
}
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
}
}
int main(void)
{
FPUEnable();
FPULazyStackingEnable();
ulPeriod = 64000;
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
// turn weak pull-ups on
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntEnable(INT_UART0);
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
UARTStdioInit(0);
IntMasterEnable();
UARTSend((unsigned char *)"\033[2JEnter text: ", 16);
//
// Loop forever echoing data through the UART.
//
while(1)
{
}
UARTprintf("emre\n");
// while(1)
// {
// if(!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)){
// GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
//
// }
// else
// {
// GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//
// }
// }
}
And this is the UART1 code..
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "string.h"
#include "driverlib/adc.h"
#include "uartstdio.h"
#include "lm4f120h5qr.h"
#include "driverlib/qei.h"
#define GPIO_PB0_U1RX 0x00010001
#define GPIO_PB1_U1TX 0x00010401
// #define GPIO_PB0_T2CCP0 0x00010007
// #define GPIO_PB1_T2CCP1 0x00010407
#define GPIO_O_LOCK 0x00000520 // GPIO Lock
#define GPIO_LOCK_KEY_DD 0x4C4F434B
#define GPIO_O_CR 0x00000524
unsigned long ulPeriod;
char i;
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
void delay (unsigned long int id){
while(id--);
}
void UARTIntHandler(void)
{
unsigned long ulStatus;
//
// Get the interrrupt status.
//
ulStatus = UARTIntStatus(UART1_BASE, true);
//
// Clear the asserted interrupts.
//
UARTIntClear(UART1_BASE, ulStatus);
//
// Loop while there are characters in the receive FIFO.
//
while(UARTCharsAvail(UART1_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
i=UARTCharGetNonBlocking(UART1_BASE);
//
// Blink the LED to show a character transfer is occuring.
//
if(i=='k')
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
else if(i=='y')
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_3);
//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(SysCtlClockGet() / (1000 * 3));
//
// Turn off the LED
//
}
}
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
//
UARTCharPutNonBlocking(UART1_BASE, *pucBuffer++);
}
}
int main(void)
{
FPUEnable();
FPULazyStackingEnable();
ulPeriod = 64000;
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
// turn weak pull-ups on
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntEnable(INT_UART1);
UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
UARTStdioInit(1);
IntMasterEnable();
// UARTprintf("emre\n");
UARTSend((unsigned char *)"\033[2JEnter text: ", 16);
//
// Loop forever echoing data through the UART.
//
// UARTprintf("emre\n");
// while(1)
// {
// if(!GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)){
// GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
//
// }
// else
// {
// GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//
// }
// }
}
As you see, I changed the baud rate for bluetooth to 9600 and ı set up PERO B0-1 pin for bluetooth. Please help me...
Hello Emre,
Couple of observation and comments
1. is the Bluetooth IC expecting a Baud rate of 9600?
2. I hope you know that PF0 is a locked pin in TM4C123 and needs to be unlocked to be made as a GPIO
3. The SysCtlClockGet in TIVAWare 2.1.0 will not return the correct system clock frequency. So if you are using TIVAWare 2.1.0 then you would need to mention 80000000 instead of SysCtlClockGet
Regards
Amit
Hello Amit,
I use HC-06 bluetooth module. it needs 9600 baudrate. I would like to ask you how ı will import my bluetooth module into my stellarıs. I put bluetooth 3.3 v,gnd and PORT B0 as rX and PORT B 1 as tX but ı can't send AT command for bluetooth. I guess my problem is that bluetooth does not receive the command. How will I do tih connection between bluetooth and lm4f120 and computer....
Hello Emre,
I had another question as well. Are you using TIVWare 2.1.0? The reason I am asking the same is becuase SysCtlClockGet function does not return the correct frequency which can mess up the Baud Rate for UART.
Other than that I do not see any issue as such on UART1. I will give it a shot on my TM4V123 LaunchPad.
Regards
Amit