• AVR Freaks

Hot!Harmony 3 and CAN bus

Author
ematicon
Junior Member
  • Total Posts : 55
  • Reward points : 0
  • Status: offline
2020/03/12 06:36:33 (permalink)
0

Harmony 3 and CAN bus

Am trying Harmony 3 for SAMC21. Can not find CAN driver/peripheral in Harmony Configurator. Is CAN functionality supported by Harmony 3? Does anybody knows? 
Or it is much better to install Atmel Studio?
#1

7 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 636
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: online
    Re: Harmony 3 and CAN bus 2020/03/12 07:05:44 (permalink)
    5 (1)
    I tried Harmony3 with CAN on PIC32MZ. Had some issues with error in baudrate, but did manage to make the it work in a bit of test code.
     
    Sorry, but no idea about SAMC21. Maybe check the latest Harmony3 release notes?
     
    Paul
     
    #2
    arpananand
    Super Member
    • Total Posts : 498
    • Reward points : 0
    • Joined: 2009/11/18 04:35:42
    • Location: 0
    • Status: offline
    Re: Harmony 3 and CAN bus 2020/03/12 07:14:37 (permalink)
    5 (1)
    ematicon
    Am trying Harmony 3 for SAMC21. Can not find CAN driver/peripheral in Harmony Configurator. Is CAN functionality supported by Harmony 3? Does anybody knows? 
    Or it is much better to install Atmel Studio?





    CAN0 and CAN1 both the instances are supported for SAMC21 device in H3, see attachment.
     

    Attached Image(s)

    #3
    ematicon
    Junior Member
    • Total Posts : 55
    • Reward points : 0
    • Status: offline
    Re: Harmony 3 and CAN bus 2020/03/12 07:49:39 (permalink)
    5 (1)
    arpananand
     
    CAN0 and CAN1 both the instances are supported for SAMC21 device in H3, see attachment.

    Did not have CAN item in this list.
    Thank you very much! I needed to know that there is something I can find.
    After several attempts of launching of Harmony Configurator with refinement of different checkbox and finally after pressing "Reconfigure Paths" I got it.
    #4
    ematicon
    Junior Member
    • Total Posts : 55
    • Reward points : 0
    • Status: offline
    Re: Harmony 3 and CAN bus 2020/03/12 07:56:02 (permalink)
    0
    Paul PortSol
    I tried Harmony3 with CAN on PIC32MZ. Had some issues with error in baudrate, but did manage to make the it work in a bit of test code.

    I used Harmony 1 for PIC32MX project years ago. Now do not remember what was a problem with library function, but I made can bitrate configuration from scratch to make it work.
    #5
    domble
    Super Member
    • Total Posts : 169
    • Reward points : 0
    • Joined: 2007/01/25 04:11:53
    • Location: UK
    • Status: online
    Re: Harmony 3 and CAN bus 2020/08/07 08:19:05 (permalink)
    0
    Harmony 3, PIC32MX795F512H
    Couldn't get the baudrate right with Harmony's settings; set to 125kHz in Harmony but meaured 135kHz on scope.
    Eventually set the numbers by editing the generated code and re-checking on the scope.  Got the 125kHz, but the numbers don't make sense... (plib_can1.c line 114)
    /* Set the Bitrate to 125 Kbps */
        C1CFG = ((20 << _C1CFG_BRP_POSITION) & _C1CFG_BRP_MASK)
                                | ((3 << _C1CFG_SJW_POSITION) & _C1CFG_SJW_MASK)
                                | ((6 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
                                | ((12 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
                                | ((1 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)
                                | _C1CFG_SEG2PHTS_MASK;

     
    I think that should give a bitrate of 80M (clock) / 20 (BRP) / 2 (built in postscaler)
      / ( 1 (PRSEG) + 12 (SEG1PH) + 6 (SEG2PH)
    or 2MHz / (19) = 105kHz. 
    But it gives 125kHz bit times on scope.
     
    Harmony's original numbers were
              | ((3 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
                                | ((7 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
                                | ((0 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)

     
    Which I think should give 2MHz / (3 + 7 + 0) = 200kHz. But actually gives about 136kHz on the scope.
    Which seems more wrong.
     
    Don't know if it makes any difference, but I'm sending data onto a canbus of two Microchip MCP2515DM-BM demo boards (and also monitoring with Microchip's Can Bus Analyzer) and seems to be fine when the bitrate is correct.
     
    I've clearly missed an important point somewhere, can anyone enlighten me?
     
    Ta!
    Dom.
     
    Edit:
    Obviously, just after I post... numbers are only 0-7 so my 6, 12, 1 was actually 6,4,1.   So 3,7,1 also works properly.
    Looks like Harmony did get most of the numbers right, except PRSEG set to 0 instead of 1.   Also, BRP rate divider should be 19 to divide by 20.  And I'm still clearly calculating the numbers wrongly.  4 'time quanta' out somewhere.
     
    Edit 2: - yes, I missed one time quanta of Sync Seg, plus the other segments are specified as (quanta - 1) - so the sum I should have been doing is 2M / (1 + 2 + 8 + 5) = 125kHz.
     
     
    post edited by domble - 2020/08/07 09:31:04
    #6
    m_snaeem@hotmail.com
    Junior Member
    • Total Posts : 105
    • Reward points : 0
    • Joined: 2020/07/10 10:54:03
    • Location: 0
    • Status: offline
    Re: Harmony 3 and CAN bus 2020/10/26 13:32:13 (permalink)
    0
    @domble i am also using CAN bus on PIC32MX795F512H using harmony. But there is no data on CANH CANL. both are high. I have used code that is given on the Microchip Harmony GitHub page but could not succeed. Can you share a simple receive and transmit code, please.
    #7
    domble
    Super Member
    • Total Posts : 169
    • Reward points : 0
    • Joined: 2007/01/25 04:11:53
    • Location: UK
    • Status: online
    Re: Harmony 3 and CAN bus 2020/10/30 05:12:40 (permalink)
    0
    Was a while ago... setup by Harmony 3, and just using
     
    CAN1_MessageTransmit(CANbusID, 8, candata, 0, CAN_MSG_TX_DATA_FRAME) ;

    where CANbusID is an unsigned int, candata is an array [ 8 ] of unsigned char.
     
    And it was talking to an active CANbus built of Microchip's CAN bus analyser, and a pair of CAN Bus Demo Board MCP2515DM-BM.
     
    Receive code is similar, but I think I've not actually tested that yet so probably best not to share.  I'll have copied the code from Microchip somewhere anyway.
     
    p.s. forum really didn't want me to post this.  u i n t 8_ t    c a n d a t a [ 8 ]   or   u i n t 32 _ t  breaking it?
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5