• AVR Freaks

Hot!UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION

Author
dnd
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2008/09/08 23:21:20
  • Location: 0
  • Status: offline
2019/12/11 22:18:17 (permalink)
0

UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION

Dear All,
 
I am using XC 16 compiler ver 1.34 with dongle license. Currently I made optimization level to 1 from 0 because of code 
reduction.In this I am using two uarts i.e. UART 1 and UART 2 via interrupt for serial data reception.
I have defined ISR as follows
 
void __attribute__((__interrupt__, __shadow__,__auto_psv__)) _U1RXInterrupt(void)
{
ByteReceived = U2RXREG;
IFS1bits.U2RXIF=0;
byte_received_flag = TRUE;
}
void __attribute__((__interrupt__, __shadow__,__auto_psv__)) _U2RXInterrupt(void)
{
ByteReceived = U2RXREG;
IFS1bits.U2RXIF=0;
byte_received_flag = TRUE;
}
 
When  I use optimization level 0 data receives in both U1RXREG and U2RXREG correctly.
But for optimization level 1, only U2RXREG receives correct data but U1RXREG garbage data.Rest  of code is same for optimization 0 and 1.
 
Please help.
 
Regards
Niraj (Futura DND)
#1

9 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18141
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/11 22:27:36 (permalink)
    0
    How many sets of shadow registers does your PIC have.
    #2
    ric
    Super Member
    • Total Posts : 25101
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/11 23:12:06 (permalink)
    +1 (1)
    Is that your real code?
    Why does the _U1RXInterrupt also access the U2RX registers?
     

    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!
    #3
    dnd
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2008/09/08 23:21:20
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/12 00:24:13 (permalink)
    0
    Dear all,
     
    ric:s that your real code?
    Why does the _U1RXInterrupt also access the U2RX registers?
    Answer: Sorry that was posting error. here is original code.
    //-------------------------------------------------------------//
    void __attribute__((__interrupt__, __shadow__,__auto_psv__)) _U2RXInterrupt(void)
    {
       ByteReceived = U2RXREG;
       IFS1bits.U2RXIF=0;
       byte_received_flag = TRUE;
    }
    void __attribute__((__interrupt__, __shadow__,__auto_psv__)) _U1RXInterrupt(void)
    {
       ByteReceived = U1RXREG;
       IFS0bits.U1RXIF=0;
      byte_received_flag = TRUE;
    }
    //-------------------------------------------------------------//
    NKurzman: How many sets of shadow registers does your PIC have.
    Answer:I am using : dspic30f6014A
    thanks
    Niraj
    #4
    ric
    Super Member
    • Total Posts : 25101
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/12 00:52:42 (permalink)
    +2 (2)
    Why are the two interrupt routines writing to the same scratch?
    Can you be absolutely sure that only one or the other will ever be triggered?
    Are those two scratch locations declared with a "volatile" qualifier? (They should be).
     
    NKurzman: How many sets of shadow registers does your PIC have.
    Answer:I am using : dspic30f6014A

    You did not answer the actual question that NKurzman asked.
    Determining the answer yourself should tell you why he asked it.
     
     

    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!
    #5
    cawilkie
    Administrator
    • Total Posts : 1996
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/12 07:32:49 (permalink)
    +2 (2)
    If U1RXInterrupt and U2RXInterrupt are the same priority; then they can be both marked as __shadow__.  If the are different, or there is a higher priority interrupt also using __shadow__, then this truly is a concern.
     
    If I were a gambling man, then my money would be on an absent volatile keyword.
     
    Regards
    Calum
     
    NB, its probably a good thing, in these receive routines, to acquire as much buffered data from UART as possible to save time thrashing between mainline and ISR... I think these have a 4-deep buffer, but without a data sheet in front of me I can't be sure.
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18141
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/12 08:55:40 (permalink)
    0
    Calum  Lots of "Possible" issues.
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3510
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/12 10:31:32 (permalink)
    0
     
     
    Probably a good idea to make the variables indepentant.
    Received data can be buffered then checked later when eol.
     
    BytesReceived1[bsize1++] = U1RXREG;
    BytesReceived2[bsize2++] = U2RXREG;
     
    if(0xd == U1RXREG) {
       flag |= EOL1_MASK;
       BytesReceived1[bsize1 - 1] = 0;
    }
     
    Is the buffer full?, receive errors?
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    dnd
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2008/09/08 23:21:20
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/13 03:47:16 (permalink)
    0
    @ric
    Why are the two interrupt routines writing to the same scratch?
    Can you be absolutely sure that only one or the other will ever be triggered?
    Are those two scratch locations declared with a "volatile" qualifier? (They should be).
     
    Answer: I have tried with different variables in both interrupt with all volatile keyword but still dose not work.
     
    @cawilkie
    f U1RXInterrupt and U2RXInterrupt are the same priority; then they can be both marked as __shadow__.  If the are different, or there is a higher priority interrupt also using __shadow__, then this truly is a concern.
     
    If I were a gambling man, then my money would be on an absent volatile keyword.
    Answer: I have tried with shadow and without shadow and volatle also but still dosent work.
     
    Regards
    Niraj
     
     
    #9
    dnd
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2008/09/08 23:21:20
    • Location: 0
    • Status: offline
    Re: UART BUFFER RECEIVES GARBAGE DATA AFTER OPTIMIZATION 2019/12/14 00:10:35 (permalink)
    +1 (1)
    Dear All,
     
    Problem is solved.
    there was hard ware issue found in dspic IC itself. When replace with newer one it worked well.
    There were twi changes done simultaneously optimization and hardware change. Thats why I fumbled.
    Thanks for all your replies..
     
    Regards
    Niraj
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5