RS232 comms - need help with datasheet


Closed Thread
Results 1 to 14 of 14
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default RS232 comms - need help with datasheet

    Been searching for a previous thread where this was raised but couldn't find it so I'll start a new one.

    As part of the development of my current project the original code was written for a 16F877A with a 20mhz crystal. RS232 comms between the EasyPic5 board and the PIC was fine using 115200 baud etc and using hyperterminal data could be exchanged.

    Due to advancements of the code I ported this to an 18F4580, and found that the RS232 comms simply filled the hyperterminal window with blocks of hieroglyphics. At the time I shelved this as I wanted to get other functionality working, but now I would like to resolve this issue.

    I've read (can say I fully understand) the section of the datasheet for the 18F4580 (http://ww1.microchip.com/downloads/e...Doc/39637c.pdf) and it appears that the UART side of things is more complicated than the 16F877A.

    From memory of the previous discussion the consensus is that it's a timing issue. Here are the current register settings:

    Code:
    DEFINE HSER_BAUD    115200                      ' Hser baud rate 
    DEFINE HSER_RCSTA   90h                         ' Hser receive status init 
    DEFINE HSER_TXSTA   24h                         ' Hser transmit status init 
    DEFINE HSER_SPBRG   25  
    DEFINE HSER_CLROERR 1                           ' Hser clear overflow automatically 
    ColumnWidth CON 10
    I'm running the 18F4580 with a 20Mhz crystal, with an DEFINE OSC 48

    I've tried entering various settings into Mister_E's calc program which seem to change just the SPBRG register value, which results in nothing at all or different sets of hieroglyphics gradually filling the hyperterminal window depending on what value is entered.

    I've also tried replacing the 20Mhz crystal with a 10Mhz one, and changing the DEFINE OSC to 20 and still get the hieroglyphics.

    I'm sure there is probably some additional register with the 18F chip that sets up the UART(s) on the PIC, but I can't figure it out.

    I'm open to (constructive) suggestions as to how I can get RS232 comms working on the 18F4580 with a 20Mhz crystal.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can we see your configs?

    If I am not mistaken 40MHz is the fastest the chip will go and that is with a 10 external. the PLL is a x4.

    So if a 20 external is all you have try
    _OSC_HS_1H
    in the configs and
    DEFINE 20 OSC
    in the code.
    Last edited by mackrackit; - 6th August 2010 at 13:15.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Malc

    There's an error somewhere on your side ...

    - OR your Xtal is 20 Mhz and you run the HS Osc ... and you have to declare 20 Mhz as a define

    - OR your Xtal is a 12 Mhz and you run the HS PLL Osc ... then you get real 48 Mhz as a clock frequency

    a 20 Mhz Xtal with HS PLL would give 80 Mhz ... if the clock could run those frequencies ( I only reached 64 Mhz ... but hardly !!! )

    (so, I do hope it's just a typo from yours ...)

    Just try

    - a 12Mhz Xtal in HS PLL mode with 48 Mhz as a DEFINE
    OR
    - a 10 Mhz Xtal .... With 40 Mhz as a DEFINE.

    of course, the UART values have to be set accordingly to the DEFINEd freq. ...

    looks Mr E's calculator does not agree with you ...

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 25  ' 115200 Baud @ 48MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    OR
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 86  ' 115200 Baud @ 40MHz, -0.22%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    Aheum ....

    Alain
    Last edited by Acetronics2; - 6th August 2010 at 13:26. Reason: PBP Defines ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    ( I only reached 64 Mhz ... but hardly !!! )
    Were things stable at that? Problems? Could be handy if all went well...
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Were things stable at that? Problems? Could be handy if all went well...
    Hi, Dave

    Operation was stable with a perfectly stable and decoupled supply and virtually "no" load at the outputs ( all pins carefully buffered ) ...
    also @ room temp ( did not test it in the fridge ! )

    but I wouldn' try it aboard my model planes ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    but I wouldn' try it aboard my model planes ...
    Then I will leave it alone
    Thanks
    Dave
    Always wear safety glasses while programming.

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Guys thanks very much for your quick input

    I have a hardware file which is then included in the main program. The config settings are
    Code:
    ASM  
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    DEFINE  OSC 48
    'DEFINE  OSC 20  ; config settings 18F4580, 10mhz crystal
    ADCON1 = $0F
    I don't have a 12 Mhz crystal at the moment, but have tried with a 10Mhz one and the slowness is causing other issues with timings of the PID loops etc, I also don't get any hieroglyphics, but I only get a blank screen with a flashing cursor. So I'll pop down and get a few 12Mhz xtals from a local component suppliers and see what that does, as I really need to run this PIC as fast as it goes, and would like to resolve the comms issue.

    Thanks once again for your input,

    Sorry noticed I hadn't changed the OSC value

    OK tried this with a 10Mhz xtal, but still no joy - and is seems as slow
    Code:
    ASM  
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    'DEFINE  OSC 48
    DEFINE  OSC 40  ; config settings 18F4580, 10mhz crystal
    ADCON1 = $0F
    Will try the 12mhz xtal when I get one
    Last edited by malc-c; - 6th August 2010 at 14:19. Reason: noticed an error in the def osc

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I've had no luck with the local electronics store, so have had to order online. Whilst waiting I noticed that the data sheet mentions
    RS-232 operation using internal oscillator
    block (no external crystal required)
    I can't figure out if this is possible irrespective of using an external crystal. If it is possible to use an internal 32mhz internal oscillator for the comms and the external to run the PIC then could someone advise me how to configure the comms definition bits and registers.

    Thanks

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This in the config will set the internal OSC to on with I/O on RA6 and RA&
    _OSC_IRCIO67_1H

    Set the internal to 8MHz
    OSCCON = %01110000 '8 Mhz

    PLL the internal
    OSCTUNE = %01000000

    Then
    DEFINE OSC 32
    Dave
    Always wear safety glasses while programming.

  10. #10
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Dave,

    As always, thanks for the quick reply. I'll give it a go and see how it performs

  11. #11
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default 12Mhz xtals arrived

    Quote Originally Posted by Acetronics View Post
    Hi, Malc



    Just try

    - a 12Mhz Xtal in HS PLL mode with 48 Mhz as a DEFINE



    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 25  ' 115200 Baud @ 48MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator


    Alain
    Guys,

    12 Mhz crystals arrived today, and using the above now have RS232 coms. Compared to the prototype running with a 20Mhz crystal and the HS_PLL setting, the PIC seems to run a little slower (didn't think you could actually overclock these PICs ) - but I can live with that. I much rather have the option of communicating with a PC over a little bit of speed.

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by malc-c View Post
    Guys,

    12 Mhz crystals arrived today, and using the above now have RS232 coms. Compared to the prototype running with a 20Mhz crystal and the HS_PLL setting, the PIC seems to run a little slower (didn't think you could actually overclock these PICs ) - but I can live with that. I much rather have the option of communicating with a PC over a little bit of speed.
    Hi, Malc

    Good settings always work fine ...

    BTW you also could have ordred some 16 Mhz Xtals ... just to test the behaviour.

    AND ... using analogic sensors could have permitted to try some " exotic " frequencies ( in the 12 -16 Mhz range, but not corresponding to a PBP define )

    [Humour ON]
    Or you could have rewritten your program for a compiler the same origin as your testboard ... ( Xtal frequency can be freely chosen )
    [Humour OFF]

    Glad it works fine ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  13. #13
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Stumped !!!! - Murphys (sods!) law strikes again

    Uhmmm... this was working fine, disconnected the comms lead from the EasyPIC5 board, now nothing is displayed in hyperterminal when the cable is re-connected. - Errr

    Have re-compiled and re-loaded the version of code I was working on, have even opened an earlier version and corrected the definds in that, compiled and tried again.... still no joy.

    Either cable is damaged, com port on the PC damaged, or max chip on the Easy PIC is damaged. - To disprove that I installed the old 16F877A which still contained the development code (prior to porting to the 18F chips) and 20Mhz xtal - hyperterm displayed the data correctly - so cable, ports and max chip obviously works.

    So with the power off I removed the 16F877A and installed the 18F4580, swapped the xtal back to the 12Mhz and then powered on (with hyperterm still "connected") and presto - works fine.......

    Stumped !!!!!!!!

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    4580 and code is good.
    PC and cable is good.

    Maybe hyperteminal is acting up? Try the Serial Communicator in MCS?
    Maybe the dev board has something loose? Try bread board?
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts