• AVR Freaks

Hot!U2BRG seemingly ignored. Wrong UART transmit baud rate.

Author
StevePye
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2012/12/28 21:55:59
  • Location: 0
  • Status: offline
2019/12/06 17:31:18 (permalink)
0

U2BRG seemingly ignored. Wrong UART transmit baud rate.

I'm trying to debug a specific piece of code so I'm implementing some blocking polled UART transmit functionality that ensures that a debug string has completely transmitted before the next line of code is executed.  Unfortunately I can't seem to be able to get the U2BRG register to do what I want.  I have a logic analyzer on the transmit line and I see my debug characters formatted as if U2BRG was set to 0.  My code sets it to 25, and using a PICkit 4, MPLABx tells me that the value is 25, but the transmitted bytes appear as if the UART peripheral is using 0.  I changed the BRGH value from 1 to 0 and noticed a 4-times increase in my character times (4 times baud rate decrease) so some part of my initialization code is doing something.  Can anybody spot anything that I'm overlooking?  FYI, using a 24MHz clock; UART peripheral clocked at 12MHz, and I'm aiming for 115200.  Thank you.
 
At 115200, 8-bit character plus 1 start-bit should be about 78us; I'm seeing 3us on the logic analyzer.
 
void blDebugInit(/*uint16_t brgVal, uint8_t brgHval*/void)
{
  int i;
  U2MODE = 0;
  U2MODEbits.BRGH = 1; // high baud rate
  U2BRG = 25; // BAUD Rate Setting
  U2MODEbits.RTSMD = 1; // No flow control mode
  U2MODEbits.UARTEN = 1; // UART is Enabled
  U2STAbits.UTXEN = 1; // transmit is enabled
  for (i = 0; i < 5000; i++)
  {
    Nop();
  }
}
 
#1

5 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18850
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: U2BRG seemingly ignored. Wrong UART transmit baud rate. 2019/12/06 17:50:30 (permalink)
    4 (1)
    Any Particular PIC?
    #2
    StevePye
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2012/12/28 21:55:59
    • Location: 0
    • Status: offline
    Re: U2BRG seemingly ignored. Wrong UART transmit baud rate. 2019/12/06 18:51:41 (permalink)
    0
    PIC24HJ256GP610A.
    #3
    NorthGuy
    Super Member
    • Total Posts : 6219
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: U2BRG seemingly ignored. Wrong UART transmit baud rate. 2019/12/06 19:14:12 (permalink)
    5 (1)
    Perhaps you overwrite it somehow. Try to produce a small example without the rest of your code.
     
    There's a small possibility that the address is wrong. Look at disassembly. U2BRG is at 0x0238.
    #4
    Aussie Susan
    Super Member
    • Total Posts : 3735
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: U2BRG seemingly ignored. Wrong UART transmit baud rate. 2019/12/08 18:16:58 (permalink)
    0
    It would also help to see the code that sends the character, sets up the oscillator and the config settings.
    Susan
    #5
    StevePye
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2012/12/28 21:55:59
    • Location: 0
    • Status: offline
    Re: U2BRG seemingly ignored. Wrong UART transmit baud rate. 2019/12/09 10:24:18 (permalink)
    0
    Thanks.  It must have been something like that.  I did some minor code re-arrangement and things are working now.
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5