• AVR Freaks

Hot!UART communication - Frame error when sending characters from dspic to PC

Author
namnh
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2021/01/05 07:58:15
  • Location: 0
  • Status: offline
2021/01/07 07:43:53 (permalink)
0

UART communication - Frame error when sending characters from dspic to PC

Hello all,
I created model for UART communication between dspic30f4011 and PC (Hercules terminal).
The baud rate is 9600.
 
However, text (characters) send from dspic30f4011 to PC always broken.
 
I used:
* Windows 10
* MATLAB/Simulink R2020b
* MPLAB Devide blcock version 3.49
* Pickit 3
 
I attached my model for code generation, please check it.
 
Note 1: Blink led example already run when I generate code from model to dspic.

Note 2: I download test code (only hex file, unknown source code) from manufacture of my board (for all board test),
my board is successfully send characters to PC (Hercules terminal).
=> I think there will be no problem for hardware part.
 
Note 3: Already try for UART 1 & UART 2, still error as below configuration:
UART1 (dspic) <-> MAX232 <-> RS232-USB cable <-> PC <----------- This one successfully send characters used hex from from manufacter of my board
UART2 (dspic) <-> usb-to-com-pl2303 <-> PC
 
Thank you very much for your support.
I took 4 night for debugging, but could not determine issue.
 
In addition, could you suggest me a website for examples for each block in toolbox ?
Since current examples of toolbox used multiple blocks & some blocks does not have corresponding examples.
In addition, I could not found Help document of each block.

Attached Image(s)

#1

9 Replies Related Threads

    Lubin
    Moderator
    • Total Posts : 470
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/07 13:48:45 (permalink)
    0
    Hi,
     
    Are you using the blockset v3.48 ? (3.49 is not out)
     
     
    Note 1: Blink led example already run when I generate code from model to dspic.
    Does your led blink with the expected frequency ?
     
      
    However, text (characters) send from dspic30f4011 to PC always broken.
    Could you share the text your are receiving ?
     
    Model peripheral seeting seems Ok.
     
    Model logic is a bit cumbersome but you should get twice "Hello Word", then "Hello Nam" repeated once per second until system us switch off.
    I do not have a test board with this old chip ready to use for quick testing. Please provide further input with the problem description.
     
    Lubin
     
     
     
    #2
    namnh
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2021/01/05 07:58:15
    • Location: 0
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/07 17:36:32 (permalink)
    0
    Thank you very much for your answer.
     

    Are you using the blockset v3.48 ? (3.49 is not out)

    Yes, I used blockset v3.48.
    I'm sorry. I made typos in previous post.
     

    Does your led blink with the expected frequency ?

    I just checked, LED seem not blink with the expected frequency.
    I expected 0.5s frequency,
    but actually (I checked by timer in my phone), it seem 1.5s frequency.
     

    Could you share the text your are receiving ?

    Please check below:
     
    Startup text (received when power on):
    {FF}
     
    Below received texts for "Hello Word": (2 times)

    {00}{70}{9C}{E0}{1C}{7C}{80}{7C}{FC}{7C}{00}{60}{FC}{9C}{7C}{60}{1C}{7C}{80}{F0}{9C}{00}{E0}
    {00}{60}{9C}{E0}{1C}{7C}{80}{7C}{FC}{7C}{00}{60}{FC}{8C}{7C}{60}{0C}{7C}{80}{E0}{9C}{00}{E0}
     
    Below received texts for "Hello Nam": (repeatedly send, below is one)
    {00}{60}{9C}{E0}{1C}{7C}{80}{7C}{FC}{7C}{00}{60}{60}{1C}{9C}{7C}{9C}{00}{E0}
     
    Since you do not have board,
    please suggest for testing & I could try it.
     
    I attached pictures of terminal.
    Thank you.

    Attached Image(s)

    #3
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/07 17:48:00 (permalink)
    4 (1)
    namnh
    ...

    Does your led blink with the expected frequency ?

    I just checked, LED seem not blink with the expected frequency.
    I expected 0.5s frequency,
    but actually (I checked by timer in my phone), it seem 1.5s frequency.

    That would imply the chip is not running at the expected speed, throwing out the baud rate calculations.
    Check your oscillator selection.
     

    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!
    #4
    namnh
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2021/01/05 07:58:15
    • Location: 0
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/08 00:49:06 (permalink)
    0
    Thank you, ric.
     
    ric
    That would imply the chip is not running at the expected speed, throwing out the baud rate calculations.
    Check your oscillator selection.

    I'm sorry, could you check the attached images if I correctly configured model OR not ?
    Since I am new to this blockset.
     
    HW board: Used 20Mhz crystal -> Attached in #1
    Model: Captured -> Attached in this #, Model_Configuration_1/2.PNG
     
    NOTE: I would like to note that UART communication for this (HW board, communication cable, PC) is success when downloaded for manufacture hex file (I could not get the code).
     
    NOTE 2: I try to used MATLAB R2015b -> same error (same compiler xc16-v1.61)
     
    NOTE 3: I borrowed another same & new board, I will test it today.
     
    NOTE 4: If you has model for usage of internal crystal (but already tested/work with other board), please provide me. I may re-configure for my dspic, then try to run.
     
    NOTE 5: Already increase step model from 0.001 to 0.05 -> still not work.
     
    Thank you very much.

    Attached Image(s)

    #5
    namnh
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2021/01/05 07:58:15
    • Location: 0
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/09 08:36:06 (permalink)
    0
    Hello all,
     
    After much of my effort, I found after add only 1 line to generated code from Simulink, it is WORK.
     
    #pragma config FOS = PRI
     
    I do not know if this issue comes from my default configuration (MATLAB/Simulink or MPLAB ?), or from toolbox.
    Please be aware of this issue.
     
    Thanks.
    #6
    RISC
    Super Member
    • Total Posts : 5960
    • Reward points : 0
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/09 14:39:29 (permalink)
    0
    Hi,
    there is no way for SIMULINK to know your hardware....
    e.g. Does your board have an external XTAL or use the dsPIC internal oscillator ?
    #pragma config FOSC = PRI   tells the dsPIC that you use an external oscillator / external clock (you should also check carefully the other configuration bits because you must tell the dsPIC if it is an external clock (EC) or an external XTAL (XT or HS)  XT or HS depends upon the XTAL frequency (check electrical parameters)
    Regards
      

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #7
    namnh
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2021/01/05 07:58:15
    • Location: 0
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/09 20:05:31 (permalink)
    0
    Hi RISC,
     
    Thank you for your explanation.
     
    RISC
    there is no way for SIMULINK to know your hardware....
    e.g. Does your board have an external XTAL or use the dsPIC internal oscillator ?
    #pragma config FOSC = PRI   tells the dsPIC that you use an external oscillator / external clock (you should also check carefully the other configuration bits because you must tell the dsPIC if it is an external clock (EC) or an external XTAL (XT or HS)  XT or HS depends upon the XTAL frequency (check electrical parameters)



    Actually I understand all above, since I have some year experience on Simulink blockset for several hardware (STM, Toshiba MCU, Arduino, TI) .
    But this is my 1st time on MPLAB Device block toolbox (Microchip).
     
    My concerned that this toolbox may miss for code generation about "#pragma config FOSC = PRI",
    or I missed on configure this parameter somewhere.
     
    If you know where I could configure it, please tell me.
    Because now I always need to add this line by manual, before program to HW.
     
    Thanks so much.
    post edited by namnh - 2021/01/09 20:07:06
    #8
    Mysil
    Super Member
    • Total Posts : 4111
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/10 03:55:26 (permalink)
    0
    Hi,
    When creating Example code, then it is more common to select Internal FRC oscillator,
    and let it run with hardware default frequency, or set internal oscillator to run with it's highest frequency.
    There is No way the author of example code can know wether there is a Crystal resonator on your board,
    nor what frequency the eventual crystal is trimmed to.
     
    So when you have a 20 MHz crystal on the board you are using, and want to use that, then you have to set that yourself.
     
    In Screen capture above, there is Crystal Oscillator Source selected. 
    There is something confusing or misleading: Field description say valid input range is within [0.2 - 25]
    with unit: MHz.    but input field is filled in with: 20E6   without specification of unit.
    Taken literally, this means: 20 million MHz, which is 20 * 10E12 Hz, and is out of range.
    I do not know whether MATLAB/Simulink can take a unit specifier in the input field.
     
    There may be an error in specification of crystal frequency, or in it's interpretation in  the blockset.
     
        Mysil   
    #9
    Lubin
    Moderator
    • Total Posts : 470
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: UART communication - Frame error when sending characters from dspic to PC 2021/01/19 09:29:27 (permalink)
    0
    Hi,
     
    You can add custom code (fuse setting here) through the Simulink model properties.
    See the image attached. 
    Please give this a try.
     
    The 30F chips are not the hot topic. It seems that the issue you mentionned were introduced and not detected. The blockset v3.49 just released should fix the issue. The blockset try to keep the code short ans simple by not setting fuse setting when default value is used. The assumption that FOSC was set to PRI by default (all bits set) is false on this chip.
    Please give a try to the blockset v3.49 available at https://fr.mathworks.com/matlabcentral/fileexchange/71892-mplab-device-blocks-for-simulink-dspic-pic32-and-sam-mcu

    Attached Image(s)

    #10
    Jump to:
    © 2021 APG vNext Commercial Version 4.5