• AVR Freaks

Hot!PIC32-HMZ144 UART2 Problem

Author
hellsmoke
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2019/07/22 03:13:05
  • Location: 0
  • Status: offline
2019/09/02 01:53:35 (permalink)
0

PIC32-HMZ144 UART2 Problem

Hi all

I use two PIC32-HMZ144 Rev.C boards.
I wanted to use the UART2 with 115200 baud on the UEXT connector (3 RE8/U2TX and 4 RE9/U2RX).
Connected with an USB FTDI PI Cable (TX, RX, GND) to the PC.
But I get only rubbish on the RX ISR and rubbish on the TX wire.

The source code is from scratch.

#pragma config FPLLIDIV = DIV_3         // 25MHz crystal / 3 = 8MHz
#pragma config FPLLRNG = RANGE_5_10_MHZ 
#pragma config FPLLICLK = PLL_POSC      // crystal input
#pragma config FPLLMULT = MUL_50        // 8MHz x 50 = 400MHz
#pragma config FPLLODIV = DIV_2         // 400MHz / 2 = 200MHz SPLL
#pragma config FNOSC = SPLL             // Selection SPLL 200MHz


Initialization code:

    PPSUnLock();
   
    // PBCLK2: PMP, I2C, UART, SPI
    while (PB2DIVbits.PBDIVRDY == 0);
    PB2DIVbits.PBDIV = 1; // div 2 = 100MHz
    PB2DIVbits.ON = 1;

    // PBCLK3: Timer1
    while (PB3DIVbits.PBDIVRDY == 0);
    PB3DIVbits.PBDIV = 1; // div 2 = 100MHz
    PB3DIVbits.ON = 1;

    // PBCLK4: Ports
    while (PB4DIVbits.PBDIVRDY == 0);
    PB4DIVbits.PBDIV = 1; // div 2 = 100MHz
    PB4DIVbits.ON = 1;

    ANSELEbits.ANSE9 = 0;  // RE9 as digital port
    ANSELEbits.ANSE8 = 0;  // RE8 as digital port
    TRISEbits.TRISE9 = 1;  // RE9 input
    TRISEbits.TRISE8 = 0;  // RE8 ouptut
   
    U2RXRbits.U2RXR = 0xD; // rx pin RPE9
    RPE8Rbits.RPE8R = 0x2; // tx pin RPE8


    U2MODEbits.ON = 0;
    __builtin_disable_interrupts();

    U2MODEbits.SIDL = 0;
    U2MODEbits.IREN = 0;
    U2MODEbits.RTSMD = 0;
    U2MODEbits.UEN = 0;    // TX and RX pins enabled
    U2MODEbits.WAKE = 1;
    U2MODEbits.LPBACK = 0;
    U2MODEbits.ABAUD = 0;
    U2MODEbits.RXINV = 1;
    U2MODEbits.BRGH = 0;
    U2MODEbits.PDSEL = 0;  // 8bit no parity
    U2MODEbits.STSEL = 0;  // 1 stop bit
   
    U2STAbits.ADM_EN = 0;
    U2STAbits.UTXISEL = 0;
    U2STAbits.UTXINV = 1;
    U2STAbits.UTXBRK = 0;
    U2STAbits.URXISEL = 0;
    U2STAbits.ADDEN = 0;
    U2STAbits.OERR = 0;

    IPC36bits.U2RXIP = 7;   // Set priority level = 1
    IPC36bits.U2RXIS = 1;   // Set sub-priority level = 1
   
    IEC4bits.U2RXIE = 1;     // Enable RX interrupt
   
    U2BRG = 53;   // 100MHz / 16 / 115200 - 1 (Baud rate)
   
    U2STAbits.UTXEN = 1;   // TX enable
    U2STAbits.URXEN = 1;   // RX enable

    PPSLock();

    IFS4bits.U2RXIF = 0;     // Clear Interrupt flag
    INTCONbits.MVEC = 1; // Multi vectored interrupts
    __builtin_enable_interrupts();
    U2MODEbits.ON = 1;


ISR:

void __attribute__((vector(_UART2_RX_VECTOR), interrupt(IPL7AUTO), nomips16)) Uart2RxIrqHandler(void)
{
    //....

    IFS4bits.U2RXIF = 0;
}

How I said. Something happens. I get some useless data on RX and TX.
I changed the oscillator inputs to FRC and changed the baud rates. Nothing helped.
It looks like it's always the same wrong.

The cable and the PC software are fine. I use them for many other evaluation boards with 115200 baud.
I tried it with both boards and got the same errors.


Does anybody have an advise?

Regards
Michael
#1

2 Replies Related Threads

    hellsmoke
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2019/07/22 03:13:05
    • Location: 0
    • Status: offline
    Re: PIC32-HMZ144 UART2 Problem 2019/09/06 00:40:46 (permalink)
    0
    Hi all
    UART2 is working correctly with 115200 after about 10 seconds! Then it seems everything is stable.
    There are some pullups...
     
    Regards
    Michael
     
     
    #2
    hellsmoke
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2019/07/22 03:13:05
    • Location: 0
    • Status: offline
    Re: PIC32-HMZ144 UART2 Problem 2019/09/20 02:34:28 (permalink)
    0
    Hi all
    I solved the problem after some blood sweat and tears:
     
    // Set these bits
    U2RXRbits.U2RXR = 0xD; // rx pin RPE9
    RPE8Rbits.RPE8R = 0x2; // tx pin RPE8
     
    // BEFORE these
    TRISEbits.TRISE9 = 1;  // RE9 input
    TRISEbits.TRISE8 = 0;  // RE8 output
     
    Regards
    Michael
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5