• AVR Freaks

Hot!UART Frame Error bit not set - PIC32MM

Author
jc999
Starting Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2017/10/08 07:23:13
  • Location: 0
  • Status: offline
2019/06/16 14:22:24 (permalink)
0

UART Frame Error bit not set - PIC32MM

Hi,
 
I am implementing DMX512A. It is simple, I have done it before on another PIC32. It uses the frame error (FERR) to indicate start condition. I seem to have a strange problem on the PIC32MM.
 
The UART error interrupt is called, but no flag bits are set.
 
I used MCC to set then manually checked pins (TRIS input, no PPS needed, no pull-up, digital) and setup bits.
 
Help is much appreciated, thank you  Smile
 
Code below:    (the forum would not allow me to post here "access denied"?)
 
post edited by jc999 - 2019/06/16 14:24:11
#1

9 Replies Related Threads

    jc999
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/08 07:23:13
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/16 14:22:41 (permalink)
    0
    UART error interrupt
    void __attribute__ ((vector(_UART1_ERR_VECTOR), interrupt(IPL1SOFT))) _UART1_ERR( void ) {
     
         // We get here when once cable is plugged in (is not firing at startup)

        /* Framing error USART - used to detect BREAK */
        if (U1STAbits.FERR == 1)
        {
            // We never get here (tested with FERR, PERR, OERR)
     
            RxData = U1RXREG; // Clear the framing error by reading
            DMX_Flags.RxBreak = 1; // Flag break occurred
            DMX_RxState = RX_WAIT_FOR_START; // Move to START state
        }

        IFS1CLR = 1 << _IFS1_U1EIF_POSITION; // Clear interrupt
    }

    #2
    jc999
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/08 07:23:13
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/16 14:22:52 (permalink)
    0
    UART initialise
    void UART1_Initialize(void)
    {
        // STSEL 1; PDSEL 9N; RTSMD disabled; OVFDIS disabled; ACTIVE disabled; RXINV disabled; WAKE disabled; BRGH enabled; IREN disabled; ON enabled; SLPEN disabled; SIDL disabled; ABAUD disabled; LPBACK disabled; UEN TX_RX; CLKSEL PBCLK; 
        // Data Bits = 9; Parity = None; Stop Bits = 1;
        U1MODE = (0x880E & ~(1<<15)); // disabling UART ON bit
        // UTXISEL TX_ONE_CHAR; UTXINV disabled; ADDR 0; MASK 0; URXEN enabled; OERR disabled; URXISEL RX_ONE_CHAR; UTXBRK disabled; UTXEN disabled; ADDEN disabled; 
        U1STA = 0x1000;
        U1TXREG = 0x00;
        U1BRG = 0x07; // BaudRate = 250000.000; Frequency = 8000000 Hz; BRG 7; 
     
        IEC1bits.U1RXIE = 1; // Enable interrupts
            
        //Make sure to set LAT bit corresponding to TxPin as high before UART initialization
        UART1_Enable(); // enabling UART ON bit

    #3
    jc999
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/08 07:23:13
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/16 15:10:43 (permalink)
    0
    I tested it with debugger, break at start of interrupt - truly OERR, FERR and PERR show 0x00
    Is this a silicon bug? PIC32MM0256GPM064
    #4
    cvm
    Super Member
    • Total Posts : 293
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/18 03:11:15 (permalink)
    0
    I created a test on my pic32mm Curiosity board-
    https://github.com/cv007/PIC32MM_Curiosity_CPP/blob/master/uart_test_break.cpp
     
    I can get FERR and OERR bits set (the above test just cycles through creating each type of error, or no error and displays the led color to show it). I am just using the rx irq, but that should make no difference. There is also a wake feature that can be put to use, that I think essentially ends up waiting until the break is done before it proceeds to look for the next start bit, however long that takes. I don't really know how it works in practice, though.
     
    I don't see where you enable the uart1 error irq (but apparently you get to the error isr) . I don't see where you set the rx pin to a digital input. I don't see the rx isr (but you have the rx irq enabled). You don't seem to be dealing with overrun errors, which can stop the rx until you clear the overrun condition (when OVFDIS=0). It becomes a little difficult to guess about things we can't see.
     
    I think its safe to say if the error bits work ok for me, yours should work also.
    #5
    jc999
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/08 07:23:13
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/18 14:29:07 (permalink)
    0
    Thank you for your reply. I looked through your code carefully to see any differences.
     
    - The UART1 error IRQ is enabled in the system initialise elsewhere. When removed, it does not trigger
    - Port settings are     TRISA = 0xFFDB;  (for RA6 = 1) which is generated by pin manager
    - The rx ISR has nothing interesting, it just clears the flag at the end
     
    My code "works" without testing the error, I wouldn't tell the difference as a user.
     
    Now I have tried this:
     

    void __attribute__ ((vector(_UART1_ERR_VECTOR), interrupt(IPL1SOFT))) _UART1_ERR( void )
    {
    /* Framing error USART - used to detect BREAK */
    if ((U1STAbits.FERR == 1) || (U1STAbits.OERR == 1) || (U1STAbits.PERR == 1))
    {
    RxData = U1RXREG; // Clear the framing error by reading
    DMX_RxState = RX_WAIT_FOR_START; // Move to START state
    }
    IFS1CLR = 1 << _IFS1_U1EIF_POSITION;
    }

     
    I get in to the interrupt but never the if statement! It works fine without checking the error source but this is not complete. What is going on here?
    #6
    ric
    Super Member
    • Total Posts : 24593
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/18 15:41:30 (permalink)
    5 (1)
    I've never used MCC, so this is just guesswork.
    Are you getting both a "receive" interrupt and an "error" interrupt together?
    Is the receive interrupt being processed first?
    If it reads U1RXREG then it will clear the framing error bit.
    If that happens before the error interrupt is executed, then you've lost the status.
     
    Maybe try checking FERR inside the normal receive interrupt as well.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    cvm
    Super Member
    • Total Posts : 293
    • Reward points : 0
    • Joined: 2011/09/16 05:16:15
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/18 16:07:43 (permalink)
    0
    Just reading the rx data register does not clear an overrun error (when OVFDIS=0). If you are getting an overrun error for some reason, then if you never clear OERR you will be stuck in a continuous uart err interrupt.
     
    In my code/driver, I take this 'drastic' measure to clear errors- I set the OERR bit, then I clear it. It ends up with a flushed rx buffer and I can deal with all error flags in the same way. Any error = flushed rx with a fresh start. I figure when things are going wrong, I'll just assume its all bad and start over. Higher levels of code using the uart can deal with corrupt data in whatever manner they want.
     
    My simple example only used the rx irq, and I'm not sure using the error irq's has any advantage. It almost seems to me it makes things more complicated than needed.
    #8
    jc999
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/08 07:23:13
    • Location: 0
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/19 10:35:28 (permalink)
    0
    Hi guys,
    Thank you all (ric!) for your input, it is solved. Fix: change interrupt priorities in MCC.
     
    This was found by looking if the flag is set in read (which it was), then changing the interrupt priorities using MCC to process the error interrupt first. Assuming MCC would prioritise the error, I missed this at the time and only had "IPL1SOFT" in the code in front of me, so no reminders. Strange one.
     
    Anyway, thanks again.
    post edited by jc999 - 2019/06/19 10:36:54
    #9
    ric
    Super Member
    • Total Posts : 24593
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: UART Frame Error bit not set - PIC32MM 2019/06/19 13:19:44 (permalink)
    0
    Ahh was a good guess then :)
    As cvm mentioned, I don't see any great benefit in having a separate error interrupt.
    It's conceptually easier just to do it the old fashioned way, with everything in the receive interrupt.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5