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.

Tiva C Launchpad:: Using UART1 on PB1-PB0

Hi,

I have used UART0 on the launchpad and i am able to view the results on HyperTerminal, and also in simulation by opening the UART#1 window . But when I use UART1 (PB1-PB0), I am not able to view the result in simulation on any of the three windows (UART#1,UART#2,UART#3). When I select Debug->Run, the program runs without throwing any errors. But like I said eariler, is there any way to view result in simulation/real board?

Thanks in advance

Edit: I even tried measuring the voltage at PB1(Tx of UART1), but it just reads 0v. Are PB1-PB0 one of those locked pins? Because, when in debug mode, Port B appeared to be locked. I posted a pic below.

Edit:This is my configuration for uart1 on port b. I know the names mightbe slightly different, but you should still understand them.

#define UART1_DR_R              (*((volatile unsigned long *)0x4000D000))
#define UART1_FR_R              (*((volatile unsigned long *)0x4000D018))
#define UART1_IBRD_R            (*((volatile unsigned long *)0x4000D024))
#define UART1_FBRD_R            (*((volatile unsigned long *)0x4000D028))
#define UART1_LCRH_R            (*((volatile unsigned long *)0x4000D02C))
#define UART1_CTL_R             (*((volatile unsigned long *)0x4000D030))
#define UART_FR_TXFF            0x00000020  // UART Transmit FIFO Full
#define UART_FR_RXFE            0x00000010  // UART Receive FIFO Empty
#define UART_LCRH_WLEN_8        0x00000060  // 8 bit word length
#define UART_LCRH_FEN           0x00000010  // UART Enable FIFOs
#define UART_CTL_UARTEN         0x00000001  // UART Enable
#define SYSCTL_RCGC1_R          (*((volatile unsigned long *)0x400FE104))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC1_UART1      0x00000002  // UART0/1 Clock Gating Control
#define SYSCTL_RCGC2_GPIOB      0x00000002  // port A/B Clock Gating Control


void UART_Init(void){
  SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART1; // activate UART1
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; // activate port B
  UART1_CTL_R &= ~UART_CTL_UARTEN;      // disable UART
  UART1_IBRD_R = 26;                    // IBRD = int(16,000,000 / (16 * 38400)) = int(26.041)
  UART1_FBRD_R = 3;                     // FBRD = int(0.1267 * 64 + 0.5) = 8
                                        // 8 bit word length (no parity bits, one stop bit, FIFOs)
  UART1_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN);
  UART1_CTL_R |= UART_CTL_UARTEN;       // enable UART
  GPIO_PORTB_AFSEL_R |= 0x03;           // enable alt funct on PB1-0
  GPIO_PORTB_DEN_R |= 0x03;             // enable digital I/O on PB1-0
                                        // configure PB1-0 as UART
  GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0xFFFFFF00)+0x00000022;
  GPIO_PORTB_AMSEL_R &= ~0x03;          // disable analog functionality on PB
}

  • Hello Madhumitha

    On the board UART-0 is hardwired for Hyperterminal. So switching it to UART-1 may not be the simple. What you would need to do is configure UART-0 Pins as GPIO Inputs and then re-wire PB0 and PB1 to the ICDI UART pins

    Regards

    Amit

  • Thank you.

    But you see, I am not planning to use PB1-PB0 to communicate with HyperTerminal. I am going to connect it to the Txr and Rxr pins of a HC05 bluetooth module and use it to communicate with my android phone! 

    So you can understand that though I have a good,working code for UART0, I need UART1 or one of the other UARTs in this case.

    The code I have posted above is a modified version of the code for UART0, which could be why there is still some problem with it.

    Please help, to the best of your knowledge.

    Thank you.

  • Hello Madhumita,

    Thanks for the clarification. Now what is missing in the code is the UARTCTL register bits TXE and RXE being set.

    Regards

    Amit

  • I deal with them in later part of code :

    unsigned char UART_InChar(void)
    { while((UART1_FR_R&UART_FR_RXFE) != 0); return((unsigned char)(UART1_DR_R&0xFF)); } void UART_OutChar(unsigned char data)
    { while((UART1_FR_R&UART_FR_TXFF) != 0); UART1_DR_R = data; }

    I have observed(in simulation) that the right values get written to UART1 DATA register. But my problems, like I said above are

    1) Port B appears to be locked (as shown in screenshot)

    2)No output appears in the serial windows in debug mode.

    3)When I upload code onto launchpad, the txr pin always stays at 0V.

    But on the other hand,

    1)Code compiles perfectly.

    2)In debug mode, the right values do get written to the UART1 data register.

    Possibly PortB is not configured correctly as UART1 for its alternate function???

    Thanks.

  • Hello Madhumitha

    The Two bits in the UARTCTL register enabled the RX and TX function. You need to set them both before setting UARTEN bit.

    Regards

    Amit

  • I followed your advice added this line to the initialization ::

    UART1_CTL_R|=0x00000300;

    Is it right?

    But I still don't see anything on the serial windows!

  • Hello Madhumitha,

    I have a simpler program to do the same and it does take care of both GPIO and UART configuration

        SysCtlPeripheralReset(SYSCTL_PERIPH_UART1);
        SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
        
        GPIOPinConfigure(GPIO_PB0_U1RX);
        GPIOPinConfigure(GPIO_PB1_U1TX);

        GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

        UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    Regards

    Amit

  • Noticed a big mistake just now, I had set PCTL values to be 0002 but the datasheet says 0011 is the right choice!!

  • Just one last question : Am I even supposed to see output on Keil Serial window from UART1, or is it just for UART0?

  • Hello Madhumitha

    It should be possible in the simulation window. However I have never used the simulation window

    Regards

    Amit

  • All right. I will keep trying.

    Thanks a lot for your help!! I really appreciate it!