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 Data register problem

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

I am working on a class project with TM4C123GH6PM Arm processor on CCS v5.4, I am using an interrupt to receive messages from RS232, My interrupt should be called everytime I write a value to my UART1 data register, but the value in the register remains 0x00000500, even if I try with different values. I tried resetting my processor but the problem remains the same. I tried using the other UART ports, the same problem remains in all the ports, does this mean that my hardware failed? I would be very much glad if you could help me with this.

  • Hello Aish,

    Thanks for the content of the Data Register. In the value 0x500 the lower byte is the data and the upper nobble showing 0x5 is indicative that there is a Break and Framing Error. In case of a framing error the data shall not be written as the UART reciever is not sure of the frame itself.

    Please check the baud rate settings, number of stop, parity bits and if possible put it on the scope or LA to see how back-2-back transfers are being done by the UART source to the TM4C123.

    Regards

    Amit

  • Hi Amit,

    // Configure UART1 to 38400 baud, 8N1 format (must be 3 clocks from clock enable and config writes)
    UART1_CTL_R = 0; // turn-off UART1 to allow safe programming
    UART1_CC_R = UART_CC_CS_SYSCLK; // use system clock (40 MHz)
    UART1_IBRD_R = 65; // r = 40 MHz / (38400), set floor(r)=21, where N=16
    UART1_FBRD_R = 7; // round(fract(r)*64)=7 // 64 coz fractional data
    UART1_LCRH_R = UART_LCRH_WLEN_8; // configure for 8N1 w/o FIFO
    UART1_CTL_R = UART_CTL_TXE | UART_CTL_RXE | UART_CTL_UARTEN; // enable TX, RX, and module
    UART1_IM_R = UART_IM_RXIM;
    NVIC_EN0_R = 1<<6;//(22-16);

    This is how I configured my UART1, and I am sending 9 bit data, including the parity bit, 1 start bit and 1 stop bit,

    my IBRD is 65, but in the IBRD register it is 41.

    I have no clue how the register is reading something else :(

  • Hello Aish,

    I am sure by now you would have realized that you are writing 65 in decimal while the read of the register is in hex. 41 hex = 65 dec.

    Secondly you mention that you are sending 9 bits including the parity but the configuration of the LCRH register is maximum of 8 bits in a UART word. So is the format 1 Start Bit+8 Data Bits+1 Parity Bit+1 Stop bit or not? Also is the same configured on the Transmitter side?

    Lastly, please avoid using Direct Macro Access as shown in the code, but develop on TivaWare.

    Regards

    Amit

  • Amit,

    Yes, the format is the same as you said and it is the same in the transmitter side.I finally figured out the issue, I realized my PCB circuit which I built for the class project might be a problem, I tried using a different board from my friend. And I finally got the output. And I would definitely follow your advice. Thanks a lot !

  • Hello Aish,

    I am not tolally convinced even though it started working. The reason is that having a parity bit in the format implies that that the Parity enable has to be set in the LCRH register. In the original code you sent that is missing,

    Regards

    Amit

  • Amit,

    I am setting EPS bit in this part of my program, I have attached that snippet for your reference,

    void sendAddress(uint16_t data){
    UART1_LCRH_R=0;
    UART1_LCRH_R = UART_LCRH_WLEN_8 | UART_LCRH_SPS | UART_LCRH_PEN;
    while(UART1_FR_R & UART_FR_TXFF);

    UART1_DR_R =data;
    puts("in send address");
    waitMicrosecond(10000);
    checksum = checksum + data;
    cnt++;
    }
    void sendData(uint16_t data)
    {
    UART1_LCRH_R = UART_LCRH_WLEN_8 | UART_LCRH_SPS | UART_LCRH_PEN | UART_LCRH_EPS;
    while(UART1_FR_R & UART_FR_TXFF);

    UART1_DR_R = data;
    puts("in send data");
    waitMicrosecond(10000);
    checksum += data;
    cnt++;
    }
    void send485(uint16_t dest_addr,uint16_t cmd, uint16_t channel, uint16_t size, uint16_t data)
    {
    DEN = 1;
    puts("in send485");
    sendAddress(dest_addr);
    //waitMicrosecond(10000);
    sendData(0);
    sendData(txseqid);
    //waitMicrosecond(1000);
    sendData(cmd);
    sendData(channel);
    sendData(size);
    if(size==1){
    sendData(data);
    }
    sendData(checksum);
    while(UART1_FR_R & UART_FR_TXFF);
    DEN = 0;
    }

    and I am declaring the variables globally.

  • Hello Aish,

    Now that convinces me as the first code post did not have it.

    BTW, what was the HW problem on the PCB, have you figured that out.

    Regards

    Amit

  • Amit,

    No, I am yet to go to the lab to check the connectivity. I would post here as soon as I correct it.

    Regards,

    Aishu

  • Along w/pcb & parity issues - what fun awaits this fellow when he must (manually) fill out multiple Gov't forms - each demanding his (full) name.  (duly noted was Amit's (friendly) "u-less" abbreviation)   (antidisestablishmenttarianism  anyone?)

    Can only imagine teacher/instructor's (grade book) Excel "column width" - struggling to accommodate...