• AVR Freaks

U1TXREG wont change value

Author
firstgenesis
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2010/01/26 16:52:10
  • Location: 0
  • Status: offline
2010/01/26 17:14:09 (permalink)
0

U1TXREG wont change value

Ladies and Gentlemen of the Forum,
Thank you for taking a minute to help me with a problem.  I have a PIC32360F512L.  I am using the PIC32 Starter kit to do programming and debugging.  I have tried to enable the UART1 for communication but when I hook my oscilloscope up I cant read any output data.  In addition when I put in break points in my code to read the value of U1TXREG, its value never changes.  Here is the init/test code I am using...

/*
* Initialize UART 1
*     - SPEED: 57,600 Baud
*    - No Hardware Control
*    - No Software Control
*/
void uart1Initialize()
{
   U1STA = 0;
   U1MODE = 0;
   U1BRG = BAUDRATE;
   U1MODEbits.PDSEL = 0; // 8 bits data, 0 bits parity
   U1MODEbits.STSEL = 0; // 1 stop bit
   U1MODEbits.BRGH = 1; // PeriphFreq/4
   U1STAbits.UTXEN = 1; // Turn on Transmitter
   U1MODESET = 0x00008000;
  
   U1TXREG = 0x00000041; // 'A'
}


I have commented out all the rest of my code, so that only this is run and then a while(true) loop.  My processor is running at (8 Mhz crystal / Input PLL Divider 2) * PLL Multiplier 18 * PLL Output Divider 1.  That yields a 72Mhz Fosc.  I am not dividing down the Peripheral Bus, so it is also running at 72Mhz.  The Constant "BAUDRATE" is set to 311.  That "should" (if I understand what I am doing, but it isnt working so maybe I dont) give me a UART Speed of 57,600 baud +.16% error. 

When I run this code, the U1TXREG does not change value from the Power On Reset.  It starts off at 0x00000000, and when I use break points to see its value during the process, it is still 0x00000000 immediately after assigning the value and never changes as far as I have had patience to watch.  The other Registers change.  For example, U1MODE and U1STA both get set to the correct value.  Any help would be greatly appreciated.  Thank you in advance.

Dustin Frantz
S.P.E. Advanced Robotics
post edited by firstgenesis - 2010/01/26 17:19:32
#1

7 Replies Related Threads

    c.pergiel
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2009/12/31 12:07:19
    • Location: 0
    • Status: offline
    RE: U1TXREG wont change value 2010/01/26 21:10:01 (permalink)
    0
    There is also a UART enable bit (called ON) in some places. It needs to be set. Also I think the transmitter has a FIFO, so whatever you write to the transmit buffer may disappear into the FIFO, never to be seen in a register again. But that's just a guess.
    #2
    c.pergiel
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2009/12/31 12:07:19
    • Location: 0
    • Status: offline
    RE: U1TXREG wont change value 2010/01/26 21:12:19 (permalink)
    0
    You're running at 57K baud, and looking for a single character on a scope? A better approach might be to set up a loop to repeatedly send the same character. That should give you something to look at on the scope.
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11251
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    RE: U1TXREG wont change value 2010/01/26 21:33:08 (permalink)
    0
    Looking at a very old and possibly incorrect pre-release PIC32 data sheet, UxTXREG is write-only.
    #4
    firstgenesis
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2010/01/26 16:52:10
    • Location: 0
    • Status: offline
    RE: U1TXREG wont change value 2010/01/27 09:10:38 (permalink)
    0
    c.pergiel and jtemples,

    Thank you for replying to my message. 

    c.pergiel:
      Unless I am mistaken, the "ON" bit should be set by the U1MODESET = 0x00008000; line of code.  I have seen this bit getting set.  I placed a break-point in my code on the next line and in MP LAB I used the "watch" screen and added U1MODE as a register to watch.  Sure enough the bit did in fact get updated.
      Also, I believe that the the PIC32MX360F512L has a four buffer deep FIFO for the UART.  So I tried U1TXREG = 0x00000041; 5 times in a row, one right after the other.  With the chip running at 72Mhz, it should be able to fill the FIFO and then have 1 more character in the U1TXREG before the first character gets flushed entirely from the TSR.  Using break-points again, I added U1TXREG to my "watch" window and the value never changed.

    jtemples:
      I am aware that the U1TXREG is "write only."  Does that mean that if I use break-points in my code and the "watch" window in MP LAB with U1TXREG as one of the registers, will I not be able to see its value change?

    Thank you again for your help.  
    #5
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11251
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    RE: U1TXREG wont change value 2010/01/27 11:37:24 (permalink)
    0

    ORIGINAL: firstgenesis

    Does that mean that if I use break-points in my code and the "watch" window in MP LAB with U1TXREG as one of the registers, will I not be able to see its value change?

    I would assume that's how it behaves, but I can't verify that.
    #6
    Chekri
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2011/03/17 09:29:46
    • Location: 0
    • Status: offline
    Re: RE: U1TXREG wont change value 2011/03/17 09:32:28 (permalink)
    0
    I have the same problem, but with PIC24F. If you have found a solution can you please help me out. I have tried everything. But it wont change..
    #7
    jjmontero9
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2011/05/11 11:26:07
    • Location: 0
    • Status: offline
    RE: U1TXREG wont change value 2011/05/11 18:11:38 (permalink)
    0
    firstgenesis
    I am aware that the U1TXREG is "write only."  Does that mean that if I use break-points in my code and the "watch" window in MP LAB with U1TXREG as one of the registers, will I not be able to see its value change?


    I am currently working with the UART module (PIC24) but I had the same problem: I wrote different values to the U1TXREG and watched for the register -actually tried to debug with a Pickit 3. But the register stayed as 0x0000 no matter how many times I wrote values in there. After reading this post I found that the U1TXREG is write-only. I guess this is because when you write to this register, data is automatically transferred to the TSR (Transmit Shift Register). The U1TXREG is just a name used to pass data to the shift register, but it can't be read at all, or at least I can't read it.

    But it is not so important to read the current value: the trouble is getting the U1TX signal out. My PIC24 has 15 remappable ports from RP0 to RP14. So I configured port RP8 as the U1TX signal and used an oscilloscope here to test if signals were getting out of my PIC. When I looked at the U1STA register I noticed that the TRMT bit was changing correctly, as if the signals were generated and sent, but I measured the actual RP8 pin on the IC and had no output.

    I changed the U1TX signal to another remappable pin and that solved my problem: when using the RP4 the UART signal was correctly displayed on the oscilloscope. I guess that port RP8 had conflicts with another peripheral but I don't really know. As I'm writing this post, I solved the problem using another pin and that was all.

    Here is some of my code, it may be helpful.


    void InitUART(void)
    {
        RPOR2bits.RP4R = 3;     // Set pin RP4 as U1TX
        U1MODE = 0x0000;        // Configure basic operation
        U1STA=0x0000;           // Configure basic operation
        U1BRG = 103;            // baud rate 2400
        IFS0bits.U1TXIF = 0;    // Clear the Transmit Interrupt Flag
        IEC0bits.U1TXIE = 1;    // Enable Transmit Interrupts
        U1MODEbits.UARTEN = 1;  // Turn the peripheral on
        U1STAbits.UTXEN = 1;
    }

    And after the initialization, this function is useful for transmitting data:

    void putuart(char data){
        while(U1STAbits.UTXBF == 1);
        U1TXREG = data;
    }


    Regards,
    Juan
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5