• AVR Freaks

Helpful ReplyHot!HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions?

Author
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
2019/12/04 12:53:31 (permalink)
0

HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions?

Just starting with CAN for my PIC32MZ board.
 
From the posts it looks like CAN Bus is very difficult to do with HarmonyV2.06?
- Driver Blocks in init if bus not connected? (any fix?)
- Demos not well documented?
- MHC Generated code undocumented?
- MHC settings confusing/undocumented?
 
So, what is the latest experience & recommendations of those people working with CAN and PIC32?
- use Harmony, its reliable... just watch these notes...
- avoid Harmony Driver, use PLIB functions directly, see these notes/examples...
- something else?
- any sample minimal projects that work?
- echo_send: seems to get stuck in init
- can_display: haven't tried as I don't have matching demo, If someone tells me this works then I'll try rewriting it with UART diagnostic output and post it here (would be nice if could use as a CAN bus analyser)
 
Any recommended tools? 
- ‎APGDT002‎ SYSTEM DEV CAN BUS ANALYZER, Is it worth the cost? (CAD$142)
- ‎114991193‎ USB-CAN ANALYZER, Seeed Technology, Is this good enough for development or a waste of effort? (CAD$36)
- other?
  
Paul
#1
NKurzman
A Guy on the Net
  • Total Posts : 18180
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/04 15:55:18 (permalink)
0
I avoided The Harmony Drivers for UART, SPI, and I2C.
In V 1.XX where I started they where poorly conceived and executed.
I never Tried the CAN Driver.
Check for Demos and see what they are doing.
Note the Migration Guide for V3.XX says you can not Migrate PLIB calls from 2.XX to V 3.XX
 
Microchips Dongle has some issues and is poorly supported.  Check the Date on the last release.
Search the Forum.  But it does work.
Years ago i used the Peak-CAN Dongle, it worked very well.
 
#2
lelsteph
Super Member
  • Total Posts : 405
  • Reward points : 0
  • Joined: 2008/09/17 05:10:00
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/04 23:16:10 (permalink)
0
Hello
 
I am also trying to use the CAN Bus.
v2.06 library is poor. If you try v3.0, it is better.
As of now, I took the code of v3.0 and I am using it in v2.06. I will start from it and most probably create my own library.
 
Steph
 
 
#3
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 06:05:47 (permalink)
0
Steph,
Willing to share or collaborate on CAN in HarmonyV206?
 
I'm staying with HarmonyV2.06 till HarmonyV3 is much more stable for the chips I'm using, according to what I see on this forum for Hv3. I don't have time right now for the major overhall of switching to Hv3.
 
Paul
 
 
 
 
#4
lelsteph
Super Member
  • Total Posts : 405
  • Reward points : 0
  • Joined: 2008/09/17 05:10:00
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 11:36:09 (permalink)
0
@Paul: I have no dedicated time, this is part of my hobbies so I am not sure I can be good to collaborate. v3 is also forcing to use RTOS, this is a big change when willing to migrate if RTOS was not used.
 
Stephane.
#5
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 12:09:52 (permalink)
0
Stephane,
Does Hv3 seem to use the same PLIB libraries as Hv206?
I haven't even looked at Hv3.
If you can share the CAN module you copied from Hv3 to V2.06 that would be great, if not that's life.
 
I'm thinking to work directly with PLIB CAN, first step would be a non-blocking init ...
 
Paul
 
#6
lelsteph
Super Member
  • Total Posts : 405
  • Reward points : 0
  • Joined: 2008/09/17 05:10:00
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 12:30:04 (permalink) ☄ Helpfulby Paul PortSol 2019/12/06 05:43:12
0
HI Paul
 
Not sure what PIC you are using but with mine PIC32MZ2048EFH064, most of the stuff is managed by the Hardware which is fabulous and very well designed.
To me, and actually for CAN, v3 does not use PLIB anymore.
Files are attached.
 
Stephane.
 
#7
mjolhe01
Starting Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/28 08:00:56
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 12:56:45 (permalink)
0
I am actually just working on this for a new project. My project is based around Harmony V3, which I think is very useful, but there have been some painful bugs that I have had to hammer through. I was able to get the transmit part of CAN bus working with both V2 and V3 with a some simple app code. 
 
We are using our own hardware at this point with a PIC32MZ2064DAH176 chip. I am using the microchip CAN bus analyzer tool (APGDT002‎) and it works great for what I needed to do (the GUI is not super intuitive, but decent). I haven't used other tools so I can't speak on if it's worth the money. This is for a business so at those price points it doesn't really matter.  
 
 
 
#8
mjolhe01
Starting Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/28 08:00:56
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 12:57:52 (permalink)
0
The CAN module was not originally available for V3 so I created a V2 project to get the CAN bus up and running. I would have to go back and check, but from what I recall the process of generating the framework from the configuration tool was pretty straightforward. 
 
V3 is somewhat the same, but it was not giving me the same configuration parameters and was not working originally. It doesn't automatically calculate the baud rate generate bits for you, so you more or less have to do it manually (I just used the values V2 gave me). It also gave me different values for some of the other timing bits, which I also just used from V2. The method of setting these bits looks quite a bit different. 
 
    //   /* Set the Bitrate to 100 Kbps FROM HARMONY V3*/
//    C1CFG = ((39 << _C1CFG_BRP_POSITION) & _C1CFG_BRP_MASK)
//                            | ((3 << _C1CFG_SJW_POSITION) & _C1CFG_SJW_MASK)
//                            | ((6 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
//                            | ((7 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
//                            | ((0 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)
//                            | _C1CFG_SEG2PHTS_MASK;
   
        /* Set the Bitrate to 100 Kbps FROM HARMONY V2 */
     C1CFG = ((49 << _C1CFG_BRP_POSITION) & _C1CFG_BRP_MASK)
                            | ((0 << _C1CFG_SJW_POSITION) & _C1CFG_SJW_MASK)
                            | ((3 << _C1CFG_SEG2PH_POSITION) & _C1CFG_SEG2PH_MASK)
                            | ((3 << _C1CFG_SEG1PH_POSITION) & _C1CFG_SEG1PH_MASK)
                            | ((0 << _C1CFG_PRSEG_POSITION) & _C1CFG_PRSEG_MASK)
                            | _C1CFG_SEG2PHTS_MASK;
 
 
#9
mjolhe01
Starting Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/28 08:00:56
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 12:59:08 (permalink)
0
IN CLOCK INITIALIZATION
 
    /* Peripheral Bus 5 is by default enabled, set its divisor */
    //FROM HARMONY V3
    //PB5DIVbits.PBDIV = 0;
    //FROM HARMONY V2
    PB5DIVbits.PBDIV = 1;
 
One other issue I ran into that I should mention. When I was switching back and forth eventually the hardware got hung up with the V2 project. What I determined from reading these boards was that there was an issue where the ports need to be initialized before before the CAN module. 

 
/* Initialize System Services */
SYS_PORTS_Initialize();

/* Initialize CAN Driver 0 */
DRV_CAN0_Initialize();
 
 
#10
mjolhe01
Starting Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/28 08:00:56
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/05 13:01:15 (permalink) ☄ Helpfulby Paul PortSol 2019/12/06 05:44:40
0
uint8_t TestMessage[4]; //Test message to transmit on CAN
 
TestMessage[0] = 0x11;
TestMessage[1] = 0x22;
TestMessage[2] = 0x33;
TestMessage[3] = 0x44;
 
//Harmony V2
while(DRV_CAN0_ChannelMessageTransmit(CAN_CHANNEL0, 300, 4, TestMessage) == false);
 
//Harmony V3
while(CAN1_MessageTransmit(300, 4, TestMessage, 0, CAN_MSG_TX_DATA_FRAME) == false);

 
Let me know if you have any additional questions and I can try to assist. 
#11
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/06 05:42:52 (permalink)
0
Stephane,
I'm also using PIC32MZ2048EF so this is a great help
Thank you
Paul
#12
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/06 05:44:31 (permalink)
0
mjolhe01,
Thank you for all the samples and warnings, very helpful
Paul
#13
laffelt
Super Member
  • Total Posts : 159
  • Reward points : 0
  • Joined: 2008/05/08 18:05:53
  • Location: 0
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/09 10:10:16 (permalink)
0
Paul,
 
I had very little success using the CAN on Harmony 1.06 so I would up reading the spec and writing my own. The V1.09 would constantly tell me that I had messages in the RX FIFO which was not the case. Tried a few other things but finally surrendered and write a drive from scratch. Hopefully the later version of Harmony perform better.
 
Let me know if you need help!
#14
Paul PortSol
Super Member
  • Total Posts : 552
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: HarmonyV2.06 - Use CAN Bus Driver, or write own? Tools? Suggestions? 2019/12/09 10:53:18 (permalink)
0
Thank you all.
I'm going to see what I can do, and then hopefully post a working simple Hv206 CAN project, hopefully...
Paul
#15
Jump to:
© 2020 APG vNext Commercial Version 4.5