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.

to receive data from remote sensor using xbee and glow an led in tiva c launchapad

Other Parts Discussed in Thread: TM4C123GH6PM

pls tell me where to study about uart functions to write a code i am using ccs5.5, tivaware 1.1, tiva123gh6pm.if possible give me a code for glowing led by recieving data from sensor. i wrote the code upto here

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"


void setupClocks() {
//this line of code sets system clock to 40 MHz
SysCtlClockSet(
SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
| SYSCTL_XTAL_16MHZ);
// this line will enables clock to UART0
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
// this line will enables clock to PORT_A
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


}


void setupPortsIO() {

//sets PA0 as data transmitting pin and PA1 as Data Receiving pin
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//sets PD1 as output to buzzer
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
}


//Initialises UART
void setupUart() {
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));
}


int main(void) {
setupClocks(); // clocks are enabled
setupPortsIO(); // all i/o ports are configured
setupUart(); // uart is started

while(1){

  //here i have to write code to recieve serial  data from xbee and glow the led in tiva launchpad and i know the code in arduino this is the code how to do it in tiva c launchpad

int read=0;

if(serial.available>21){

if(serial.read()==0x7E){

for(int i=0;i<19;i++){

byte discard=serial.read()}

read value=serial.read();
}
}

if(read=0){

serial.println("on");

}

else{

serial.println("off");

}

  • Hello Saikiran,

    Since you are going to use serial communication, you can initialize UART-1 for communicating and then use the UART Status register to see if a byte is recieved and read the byte using Read function from uart.c

    The initialization of the UART-1 would be similar to UART-0 except that you will have to pass the parameters for IO Configuration, UART-1 configuration.

    I would suggest you start with a basic code and I can help build it for you.

    Regards

    Amit

  • thaks for the quick response Amit actually i dont know  how to start and what to study can you pls help me in  and i have learned the below program to echo characters using UART0

    int main(void) {

    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

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

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

    while (1)
    {
    if (UARTCharsAvail(UART0_BASE)) UARTCharPut(UART0_BASE, UARTCharGet(UART0_BASE));
    }

    }

  • Hello Saikiran,

    On similar lines

    1. Enable the UART-1 peripheral by using the SysCtlPeripheralEnable

    2. Enable the GPIO corresponding to the Pins where UART-1 TX RX pins are mapped. You can get this from the data sheet chapter for UART, section Signal Description

    3. Configure the Pins, please check the pin_map.h for the actual defines to be used for GPIO_PXY_U1RX and GPIO_PXY_U1TX

    4. Configure UART-1 by using UARTConfigSetExpClk, except that UART1_BASE has to be used to address UART-1.

    5. UARTCharGet gets the data when UARTCharAvail returns a 1. Again UART1_BASE to be used.

    Please note that UART-0 is the serial print interface

    Regards

    Amit

  • actually i get these data serially from xbee  (0x7E(1st hex data),0x00(2nd hex data),0x14(3rd hex data),.......here is the 20th hex data i needed-> 0x10,....)    this is a frame of 23 bytes   so i used

    here a for loop to discard first 19 hex data and  copied 20th hex data(which i needed) to a variable readvalue and used this variable to glow led in tiva c launchpad.do i get hex value in the variable "readvalue"

    while (1)
    {
    if(UARTCharsAvail(UART1_BASE)>21){

    if(UARTCharGet(UART1_BASE)==0x7E)
    {
    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }
    }
    readvalue = UARTCharGet(UART1_BASE);  -> here how can i take hex value to variabe "readvalue'
    }

    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1 , 0x02);
    SysCtlDelay(5000000);
    }
    }
    }

  • Hello Saikiran

    UARTCharsAvail lets the program know that there is at least 1 byte in the UARTFIFO. What needs to be done if 0x7E is going to be uniquely the first byte, is to read the UART Buffer unconditionally till we get 0x7E. Once done then read the remaining 19 bytes and copy the 20th byte as you have already done,

    Regards

    Amit

  • i wrote the code as below pls check it for any mistakes thku in advance

    while (1)
    {

    if(UARTCharsAvail(UART1_BASE)){

    if(UARTCharGet(UART1_BASE)==0x7E)
    {
    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }
    }
    else{
    bufdiscard=UARTCharGet(UART1_BASE);
    continue;

    }
    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1 , 0x02);
    SysCtlDelay(5000000);
    }

    }

    }
    }

  • and i have doubt that  in the above code i have declared readvalue as integer,but i assigned its value as character using this function   int readvalue = UARTCharGet(UART1_BASE)" 

  • Hello Saikiran,

    Slight change in test code.

    while (1)
    {

    while(UARTCharGet(UART1_BASE)!=0x7E);

    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }


    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1 , 0x02);
    SysCtlDelay(5000000);
    }

    }

    Regards

    Amit

  • Im trying to read the values from an Xbee but i get the same error --define is missing its parameter'NAME[=value]' 

    can you tell me how did you resolve your problem? 

    #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 "driverlib/uart.h"
    #include "driverlib/uart.c"
    #include "driverlib/adc.h"
    #include"inc/hw_types.h"
    #include"driverlib/pin_map.h"
    #include"driverlib/sysctl.h"
    //#ifdef PART_LM4C123GH6PM;
    //#define GPIO_PB0_U0RX 0x00000001

    void setupClocks(){

    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    }
    void setupPortsIO(){
    GPIOPinConfigure(GPIO_PB0_U0RX);
    GPIOPinConfigure(GPIO_PB1_U0TX);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);

    }

    void setupUart(){
    GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART_1_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    }

    int main(void) {
    setupClocks(); // clocks are enabled
    setupPortsIO(); // all i/o ports are configured
    setupUart(); // uart is started

    while(1){

    while(UARTCharGet(UART1_BASE)!=0x7E);

    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }


    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 , 0x02);
    SysCtlDelay(5000000);
    }

    }
    }

  • Hello Enrique,

    In your CCS Project right click the project then

    "Show Build Settings" -> Build -> ARM Compiler -> Advanced Options -> Predefined Symbols

    There you can add under "Pre-define NAME" the following two defines

    PART_TM4C123GH6PM

    TARGET_IS_TM4C123_RB1

    Regards

    Amit

  • Amit:

    this is my code after a few adjustments and i still after i added "defines" i still get the error

    the weird thing is that it does not mark an erro on the code!!!!

    #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 "driverlib/uart.h"
    #include "driverlib/uart.c"
    #include "driverlib/adc.h"
    #include"inc/hw_types.h"
    #include"driverlib/pin_map.h"
    #include"driverlib/sysctl.h"
    #define GPIO_PB0_U1RX 0x00010001
    #define GPIO_PB1_U1TX 0x00010401

    void setupClocks(){

    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    }
    void setupPortsIO(){
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);

    }

    void setupUart(){
    GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART_1_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    }

    int main(void) {
    setupClocks(); // clocks are enabled
    setupPortsIO(); // all i/o ports are configured
    setupUart(); // uart is started

    while(1){

    while(UARTCharGet(UART1_BASE)!=0x7E);

    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }


    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 , 0x02);
    SysCtlDelay(5000000);
    }

    }
    }

  • Amit:

    Can you post your  complete code so i can see whats wrong with mine.

  • Amit:

    this is my code after a few adjustments and i still after i added "defines" i still get the error

    the weird thing is that it does not mark an erro on the code!!!!

    #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 "driverlib/uart.h"
    #include "driverlib/uart.c"
    #include "driverlib/adc.h"
    #include"inc/hw_types.h"
    #include"driverlib/pin_map.h"
    #include"driverlib/sysctl.h"
    #define GPIO_PB0_U1RX 0x00010001
    #define GPIO_PB1_U1TX 0x00010401

    void setupClocks(){

    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    }
    void setupPortsIO(){
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);

    }

    void setupUart(){
    GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART_1_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    }

    int main(void) {
    setupClocks(); // clocks are enabled
    setupPortsIO(); // all i/o ports are configured
    setupUart(); // uart is started

    while(1){

    while(UARTCharGet(UART1_BASE)!=0x7E);

    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }


    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 , 0x02);
    SysCtlDelay(5000000);
    }

    }
    }

  • Saikiran:

    This is my code and i have errors can you send me your code to check mine or can you tell me how did you resolve your issue

    #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 "driverlib/uart.h"
    #include "driverlib/uart.c"
    #include "driverlib/adc.h"
    #include"inc/hw_types.h"
    #include"driverlib/pin_map.h"
    #include"driverlib/sysctl.h"
    #define GPIO_PB0_U1RX 0x00010001
    #define GPIO_PB1_U1TX 0x00010401

    void setupClocks(){

    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    }
    void setupPortsIO(){
    GPIOPinConfigure(GPIO_PB0_U1RX);
    GPIOPinConfigure(GPIO_PB1_U1TX);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);

    }

    void setupUart(){
    GPIOPinTypeUART(GPIO_PORTB_BASE,GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART_1_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    }

    int main(void) {
    setupClocks(); // clocks are enabled
    setupPortsIO(); // all i/o ports are configured
    setupUart(); // uart is started

    while(1){

    while(UARTCharGet(UART1_BASE)!=0x7E);

    for(i=0;i<19;i++){

    bytediscard=UARTCharGet(UART1_BASE);
    }


    readvalue = UARTCharGet(UART1_BASE);
    if(readvalue==0)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 , 0x00);
    SysCtlDelay(5000000);
    }
    else
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 , 0x02);
    SysCtlDelay(5000000);
    }

    }
    }

  • Hello Enrique,

    There would be a space at the start of one of the defines. Please go back to the build setting path and check if there is a space on "PART_" define

    Regards

    Amit

  • Yes their a space on  "PART_" without it gives more errors but the error persists

    any more suggestions?

  • Hello Enrique

    Can you zip your project and send it across?

    Regards

    Amit

  • Hello Enrique

    Cleaned and attached

    Regards

    Amit

    http://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/908/8713.ScaleXbee.7z

  • How do i open the file?

  • Hello Enrique

    Windows 7 has a 7z unzipper. Or you can download 7z from the net.

    Regards

    Amit