• AVR Freaks

Hot!dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions

Author
dspic
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2008/09/08 18:10:10
  • Location: 0
  • Status: offline
2020/05/12 03:55:42 (permalink)
0

dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions

The data sheet says < Four UART modules (15 Mbps) >,In fact, when I setting the Baud rate to 460800 doesn't work properly. The phenomenon is to connect UART to the computer through RS232-USB conversion adapter, test OK, but if I connect two PCB boards welded 33EP512MU814 chip together will lead to confusion, Communication is incorrect,When the Baud rate drops to 9600, the communication is correct.The source code is as follows:
 
#define FCY 40000000
//#define BAUDRATE 9600
#define BAUDRATE 460800
//#define BRGVAL ((FCY/BAUDRATE)/16)-1
#define BRGVAL ((FCY/BAUDRATE)/4)-1
unsigned int i;
int main(void)
{
       // Configure oscillator to operate the device at 40 MHz
       // Fosc = Fin * M/(N1 * N2), FCY = Fosc/2
       // Fosc = 8M*40(2*2) = 80 MHz for 8M input clock
        PLLFBD = 38; // M = 40
        CLKDIVbits.PLLPOST = 0; // N1 = 2
        CLKDIVbits.PLLPRE = 0; // N2 = 2
        OSCTUN = 0; // Tune FRC oscillator, if FRC is used
        RCONbits.SWDTEN = 0; // Disable Watchdog Timer
        while(OSCCONbits.LOCK! = 1) {}; // Wait for PLL to lock
        U1MODEbits.STSEL = 0; // 1-Stop bit
        U1MODEbits.PDSEL = 0; // No Parity, 8-Data bits
        U1MODEbits.ABAUD = 0; // Auto-Baud disabled
        //U1MODEbits.BRGH = 0; // Low-Speed mode
        U1MODEbits.BRGH = 1; // High-Speed mode
        U1BRG = BRGVAL; // Baud Rate setting for 9600
        U1STAbits.UTXISEL0 = 0; // Interrupt after one TX character is transmitted
        U1STAbits.UTXISEL1 = 0;
        IEC0bits.U1TXIE = 1; // Enable UART TX interrupt
        U1MODEbits.UARTEN = 1; // Enable UART
        U1STAbits.UTXEN = 1; // Enable UART TX
 

       /* Wait at least 104 microseconds (1/9600) before sending first char */
       for(i = 0; i < 4160; i++)
       {
            Nop();
       }
       U1TXREG = 'a'; // Transmit one character
       while(1);

}
 
I hope your warm friends help me analyze the reasons.Thanks!
 
post edited by dspic - 2020/05/12 05:47:13
#1

15 Replies Related Threads

    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 04:12:46 (permalink)
    5 (1)
    Hi,
    I have used the MU810 in the past @115.2kbps without issues and I'm quite sure they can operate above this speed.
    There are a couple of errata on the UART. You may want to check if you are affected and implement workaround if needed.
    Regards
     
    #2
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 04:17:32 (permalink)
    0
    You only showed test code for the Master.
    You did not mention what "Communication is incorrect" actually means.
     
    The effective way to ask for help is not to make your own conclusions. Just show exactly how you tested, and what you observed.
     

    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
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: online
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 04:42:40 (permalink)
    0
    Please post code with code tags.
    Please start threads in the appropriate sections of the forum.
     
    You don't mention the clock source for both pics, at high speed it's critical that they are accurate (i.e: not the FRC)
    And if that's the code, that's NOT how you set up the oscillator (you have to switch to a non-pll source, set up the pll and only then switch to a pll source.)
    #4
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 04:53:12 (permalink)
    5 (1)
    Oh and by the way
            IEC0bits.U1TXIE = 1; // Enable UART TX interrupt

    Do NOT enable interrupts when you don't have an interrupt service routine!

    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
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 05:27:53 (permalink)
    4 (1)
    ric
    Oh and by the way
            IEC0bits.U1TXIE = 1; // Enable UART TX interrupt

    Do NOT enable interrupts when you don't have an interrupt service routine!


    Hi,ric:
    The interrupt program is there, I didn't put it in my post, in my code 115200, 9600 are OK.
    #6
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 05:30:07 (permalink)
    0
    RISC
    Hi,
    I have used the MU810 in the past @115.2kbps without issues and I'm quite sure they can operate above this speed.
    There are a couple of errata on the UART. You may want to check if you are affected and implement workaround if needed.
    Regards
     


    Hi,RISC:
    yes,115200,9600 are OK,Only in High_speed is NG.
    #7
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 05:42:06 (permalink)
    0
    Jack_M
    Please post code with code tags.
    Please start threads in the appropriate sections of the forum.
     
    You don't mention the clock source for both pics, at high speed it's critical that they are accurate (i.e: not the FRC)
    And if that's the code, that's NOT how you set up the oscillator (you have to switch to a non-pll source, set up the pll and only then switch to a pll source.)


    Hi,JPortici:
    Thanks for the guidance.I will try to improve the quality of my posts.
    I'm using an external 8MHz clock source,not the FRC.The clock is configured like this:
        

        PLLFBD = 38; // M = 40
        CLKDIVbits.PLLPOST = 0; // N1 = 2
        CLKDIVbits.PLLPRE = 0; // N2 = 2
        OSCTUN = 0;
        __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary Oscillator with PLL
        __builtin_write_OSCCONL(0x01);
        while (OSCCONbits.COSC != 0b011);
        while (OSCCONbits.LOCK != 1); // Wait for PLL to lock
        CORCONbits.SATA = 0; // Turn saturation on to insure that overflows will be handled smoothly.
        RCONbits.SWDTEN = 0; // Disable Watch Dog Timer

    Is it correct?
    post edited by dspic - 2020/05/12 05:48:06
    #8
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 06:23:42 (permalink)
    4 (1)
    Hi,
    Just made a test @ 460kbits/s using BRGH = 1 & internal clock between EXPLORER1632 and PC based on an old Masters class using DMA on MU810.
    I sent a file from PC and the file is bounced back to the PC and displayed. there was no error.
    Did you also succeed @ 460kbits/s with the PC ?
    Regards
     
    #9
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 13:01:59 (permalink)
    0
    Hi,
     
    I found an old Masters class which used DMA transfers on dsPIC33EP512MU810 to transfer back what it receives from a PC. I pushed speed @460800 kbps.
    As you said you have issues transfering data between 2 x dsPIC33EP512MU814, I expanded the code to use 2 on-board uarts (UART1 and UART2).
    So the attached working project is doing the following :
    PC (teraterm) => UART1 RX => UART1TX => UART2 RX => UART2 TX => PC (teraterm)
    The project uses DMA and ping-pong buffers. I sent a text file using TERA TERM it is inside the project) and it came back correctly into TERA TERM without any error @460800 kbpsp and using the internal 7.37MHz oscillator.
    To achieve smallest baudrate error, I selected : N1=2, M=74 and N2=2 for the PLL which gives Fosc = 136.345MHz (68.172MIPS).
    @460800 bps this gives 0.038% error
     
    Please check my initialization against your code
    Regards
     
    post edited by RISC - 2020/05/12 18:10:40

    Attached Image(s)

    #10
    NorthGuy
    Super Member
    • Total Posts : 6228
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 15:09:26 (permalink)
    4 (1)
    The best way to validate the baud rate id to transmit something and measure the baud rate on the TX pin with a scope or logic analyzer.
     
    Usually UART works very reliable up to about 6 MBaud as long as you keep your baud rate withing 2% of what you want. Above this, the rise and fall times decrease the margin.  The faster you go the more accurate clock you need.
     
     
    It is better to use baud rates which are multiples of the CPU frequency. Otherwise you get rounding errors. For example, if you use 460800, the divider is 21*4 = 84. This gives baud rate 476191, which has 3% error - generally too much of an error for UART. If you use proper rounding while calculating baud rates you get 22*4 = 88 divider, your baud rate will be 454545, which has only 1.5% error - not great, but acceptable. If you used 500000 baud rate, there would be no rounding error (the only source of errors is the accuracy of your crystal, which you cannot remove), so your chance of getting a good transmission would be much better.
     
    Of course if you use two PICs with the same divider, as RISC did, the rounding error goes away because both PICs use the same divider, but the rounding error will come back when you talk to something different.
    #11
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/12 18:17:36 (permalink)
    0
    Hi Northguy,
    I uploaded an updated project in my previous post with the smallest baudrate error using internal oscillator (7.37MHz). By carefully selecting M (74),N1 (2) and N2 (2), which gives Fosc = 136.345 MHz (Fcy = 68.17 MIPS) it is possible to achieve a very small baudrate error (0.038% error).
    It is possible to use dsPIC33EP512MU810/814 up to 70 MIPS for -40 to +85C temepratre range.
    With these parameters it gives 460625 bauds (0.038% error) for UxBRG=21. Internal oscillator is garanted @+/-2% so it could indeed be outside the +/-2% max error (max total error = 2.038% ) required by UART protocole .
    Regards
     
    post edited by RISC - 2020/05/13 08:39:08
    #12
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/13 07:51:29 (permalink)
    0
    RISC
    Hi,
    Just made a test @ 460kbits/s using BRGH = 1 & internal clock between EXPLORER1632 and PC based on an old Masters class using DMA on MU810.
    I sent a file from PC and the file is bounced back to the PC and displayed. there was no error.
    Did you also succeed @ 460kbits/s with the PC ?
    Regards
     


    Hi,RISC
    I'm succeed @ 460kbits/s with the PC.Only NG between two board with  33EP512MU814.
    #13
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/13 08:11:59 (permalink)
    0
    RISC
    Hi,
     
    I found an old Masters class which used DMA transfers on dsPIC33EP512MU810 to transfer back what it receives from a PC. I pushed speed @460800 kbps.
    As you said you have issues transfering data between 2 x dsPIC33EP512MU814, I expanded the code to use 2 on-board uarts (UART1 and UART2).
    So the attached working project is doing the following :
    PC (teraterm) => UART1 RX => UART1TX => UART2 RX => UART2 TX => PC (teraterm)
    The project uses DMA and ping-pong buffers. I sent a text file using TERA TERM it is inside the project) and it came back correctly into TERA TERM without any error @460800 kbpsp and using the internal 7.37MHz oscillator.
    To achieve smallest baudrate error, I selected : N1=2, M=74 and N2=2 for the PLL which gives Fosc = 136.345MHz (68.172MIPS).
    @460800 bps this gives 0.038% error
     
    Please check my initialization against your code
    Regards
     


    RISC
    Hi,
     
    I found an old Masters class which used DMA transfers on dsPIC33EP512MU810 to transfer back what it receives from a PC. I pushed speed @460800 kbps.
    As you said you have issues transfering data between 2 x dsPIC33EP512MU814, I expanded the code to use 2 on-board uarts (UART1 and UART2).
    So the attached working project is doing the following :
    PC (teraterm) => UART1 RX => UART1TX => UART2 RX => UART2 TX => PC (teraterm)
    The project uses DMA and ping-pong buffers. I sent a text file using TERA TERM it is inside the project) and it came back correctly into TERA TERM without any error @460800 kbpsp and using the internal 7.37MHz oscillator.
    To achieve smallest baudrate error, I selected : N1=2, M=74 and N2=2 for the PLL which gives Fosc = 136.345MHz (68.172MIPS).
    @460800 bps this gives 0.038% error
     
    Please check my initialization against your code
    Regards
     


    Hi,RISC
    Thank you for your reply,I'll try it your way.
     
    #14
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/13 09:33:41 (permalink)
    0
    Hi,
    I found many years ago an excellent excel spreadsheet which computed UART baudrates for PIC18.
    You can enter the maximum error you want (generally 2%, and it will show what are the best combinations)
    I adapted it to support PIC24, dsPIC33FJ (@40 & 50MIPS), dsPIC33EP (@60 and 70MIPS).
    For dsPIC it is a little more tricky because you need to supply M,N1 and N2 to see what is the best.
    I have put many columns for standard XTAL frequencies and the standard internal oscillator frequency (generally 7.37MHz for dsPIC).
    For BRGH wou'll see a special macro in my project to decide to use low or high depending on the baudrate
    I need to update this spreadsheet to support the dsPIC33CH and CK as the PLL have changed again
    you may find this tool useful everytime you deal with UARTs....
    Regards
    (Nb : remove .txt from filename)
    post edited by RISC - 2020/05/13 09:34:42
    #15
    dspic
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/09/08 18:10:10
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814 UART Can't work well under high Communications Baud Rate conditions 2020/05/13 17:10:48 (permalink)
    0
    RISC
    Hi,
    I found many years ago an excellent excel spreadsheet which computed UART baudrates for PIC18.
    You can enter the maximum error you want (generally 2%, and it will show what are the best combinations)
    I adapted it to support PIC24, dsPIC33FJ (@40 & 50MIPS), dsPIC33EP (@60 and 70MIPS).
    For dsPIC it is a little more tricky because you need to supply M,N1 and N2 to see what is the best.
    I have put many columns for standard XTAL frequencies and the standard internal oscillator frequency (generally 7.37MHz for dsPIC).
    For BRGH wou'll see a special macro in my project to decide to use low or high depending on the baudrate
    I need to update this spreadsheet to support the dsPIC33CH and CK as the PLL have changed again
    you may find this tool useful everytime you deal with UARTs....
    Regards
    (Nb : remove .txt from filename)


    Hi,RISC
    Thank you for your guidance and sharing.
    #16
    Jump to:
    © 2020 APG vNext Commercial Version 4.5