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.

UART1 enabling issue.

Other Parts Discussed in Thread: MAX3232, MAX232

Hello,

I have just initialized UART1 but it is not working there might be something missing out so  I am posting my code so if any one can help me  where is my initialization wrong?

#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 a,b;
int main(void)
{
//Setting Clock
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

//Enabling UART1

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);

GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//Configuring UART

UARTConfigSetExpClk(UART1_BASE,16000000, 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
while(1)
{
UARTprintf("welcome\n");
// UARTCharPut(UART1_BASE,'d');
}

}

  • I have used some extra headers just because I have to use those in my further application. But after UART Initialization I am unable to print "welcome" in my terminal window.

  • Hi Mitesh,

         Are you using Tiva Launchpad? Have you set your PC serial settings correctly?

    -kel

  • Hello Markel,

    Yea I am using Tiva Launchpad. Andyes I have did all my setting in my PC correctly i.e. setting up a baudrate to 9600.

  • Hi Mitesh,

         If you enter debug mode - run it - then stop code execution, does it go to any faults?

    -kel

  • I got a point i might have missed with clock source to UART and configuring UARTStdio settings.

    So I also added

    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(1, 9600, 16000000);

    but it still did not worked. And amazingly if I do with UART0 my code is working fine and just making a change to UART1, it is not working at all. As i am using launchpad I can not use UART0 because PA0 and PA1 pins are not taken out from launchpad.

    Ans to your question after stopping debug session it is not showing any error.

     

  • Hi Mitesh,

    Mitesh Sirodaria said:
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);

         

         Since you set your clock using Main Oscillator, remove the line above, and try again using UART1. Still use UARTStdioConfig.

         There are post here that have successfully used UART1, with similar initialization.

    -kel

  • Hello, 

    I tried that after removing 

    "UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);" but it still dint worked.

    If I remove above line it does not work with UART0 also. 

    Is there any thing which we need to add while working with UART1 to UART7? because it is only working on UART0 and not on any other UART.

  • Hi,

    Did you used an level translator like MAX3232 with UART1? Only in this case "will work" while sending to PC; UART0 works by default without since it is managed by ICDI and sent through USB. No way to do otherwise.

    Petrei.

  • Hello Petrie,

    Thanks and got your point that I cannot connect directly to PC. But I have also tried with USB to Serial connector. I connected RX to TX , TX to RX and Ground to Ground. Also I selected com number of USB to Serial connector but then too I did not got any value or output and terminal window was blank.

    If you can tell me a otherway to check my UART communication to check my data.

    Thanx.

  • It is great that Petrei is helping you now. He will provide you good guidance on how to solve your problem.

    For the orderliness of the forum just stick to one post. I see you have posted this problem in other posts.

    -kel

  • Hello Markel,

    Yea I posted just because the issue was very much similar and from now will take care of using a single post.

    Thanks for your guidance.

  • Mitesh,

    You just cannot do that! Only with level translator. UART0 signals are sent to the ICDI chip and converted to USB packets, and inside the driver on PC re-converted to serial information. 

    Petrei

  • Hello Mitesh

    Can you post the final code you are using along with the connections on the LaunchPad and I can check if it is working or not and help you out

    Regards

    Amit

  • Hello  Amit,

    I have to make a code using UART which should transmit some data so at initial stage I have just written code to check character 'A' is being transmitted continously or not. If it is being transmitted I can directly use it for my further application.

    At my connection I have connected my launchpad to RS232 DB9 connector to USB. I connected RX of DB9 connector port to PB1 of launchpad, TX of DB9 to PB0 of launchpad and ground to ground.

    If you can just verify it and let me know it would be really great. Below I am pasting my code.

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


    while(1)
    {
    UARTCharPut(UART1_BASE,'A');
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_PIN_2);
    SysCtlDelay(SysCtlClockGet() / 30);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0);
    SysCtlDelay(SysCtlClockGet() / 30);
    }
    }

    Thanks,

    Mitesh

  • Hello Mitesh,

    Since I do not have the DB9 HW, so I  made a small change to the code as follows (so that I can connect PB0 and PB1 to PA0 and PA1 respectively on the TM4C123 LaunchPad)

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    Added

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_0);

    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_1);

    Instead of

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

    replaced it with

    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);

    UARTConfigSetExpClk(UART1_BASE,16000000, 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    It prints "A" and the Blue LED Blinks.


    Regards

    Amit

  • Hi Amit,

    Even if I make similar change and if I connect other hardware to port B1 and port B0, will that work?

    Also if I don't make any changes my  PB1 and PB2 should transmit 'A' continously? I was already getting BLUE LED blinking but was not sure of my data being transmitted or not.

    If you can just paste your code  so that I can properly verify changes you have done.

    Thank You,

    Mitesh 

  • Hello Mitesh,

    Attached is the code and yes it will work as I have tested it on my side. Make sure you connect PB0 to PA0 and PB1 to PA1 (PA0 and PA1 are available on the launchpad as probe points)

    #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_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //initialize UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_0);
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_1);
    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);
    
    
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
    UARTConfigSetExpClk(UART1_BASE,16000000, 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    
    
    while(1)
    {
    UARTCharPut(UART1_BASE,'A');
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_PIN_2);
    SysCtlDelay(SysCtlClockGet() / 30);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0);
    SysCtlDelay(SysCtlClockGet() / 30);
    }
    }
    

    Regards

    Amit

  • Thanks Amit for testing and it is being transmitted properly.

    Hope you dont mind asking 1 more querry on similar thing.

    I am able to transmit all characters and also able to view it on hyperterminal properly but now if I connect RS232 DB9 device to pc and to my TIVA Launchpad I am receiving data but that data is not with what characters I am sending.

    Like an example If I send character '0' it shows me " "(blank space). If I send char '1'(one) I receive 'g'(alphabet g) and for "A' I get '_'(underscroll).  Lastly I also checked the hex value with what I was receiving with char '1' it showed me 0x67 (which is ascii value of ('g')).

    Hope you got my point...In short data  receiving data is completely different with what is being transmitted. Can you help me in this aswell?

    Thanks Mitesh

  • I also tried with UART Echo example it is transmitted properly but on receiving end it is showing "rR³­]¤QÓ£»Tzt´ì".

  • Mitesh Sirodaria said:
    but now if I connect RS232 DB9 device to pc and to my TIVA Launchpad

    Petrei, already mentioned in this post that you cannot just connect your Tiva Launchpad to your PC. You, need a RS232 transceiver circuitry. If you are not familiar with this circuitry, search in the internet for interfacing RS232 to microcontroller.

    -kel

  • I tried to read data coming from launchpad to arduino. but my arduino is not receiving any data I also tried to receive data on another launchpad but still it is unable to receive do I need MAX232 IC for controller to controller communication?

  • Hello Mitesh,

    For connecting one TIVA LaunchPad to another TIVA LaunchPad, you do not need to use a MAX232 IC. But to connect it to a PC or an Arduino kit (it may have IO voltage of 5V) you do need a MAX232 IC.

    Now coming back to the TIVA-to-TIVA not working, did you make sure that PB0 is connected to PB1 (TX to RX)? On connecting a LA/Scope probe, do you see one TIVA sending any data?

    Regards

    Amit

  • Hi Amit,

    I tried using MAX232 and it worked fine with PC with exact data.

    Then I connected Arduino to MAX232 it started giving me values which it was giving to me while i connected TIVA launchpad to PC without MAX232.

    Also if I connect Launchpad to launchpad with MAX232 it gives me data which I was getting while I connected launchpad to PC without MAX232.

    If I dont use MAX 232 in between launchpad to arduino or launchpad to launchpad no data is being received although my launchpad is transmitting data.

    Regards,

    Mitesh

  • Hello Mitesh,

    Please note that MAX232 is a level translator for UART. So when interfacing the uC to PC it is required but not for 2 uC which have the same IO Voltage Levels.

    I tried doing the same with 2 LauncPads (TM4C123) where one sends a character every second and other receives it and displays it on UART-0 and it worked fine.

    Regards

    Amit

  • Thank you Amit, will try it out.