• AVR Freaks

AnsweredEnabling CAN bus module kills Harmony

Author
NicholasLee
Junior Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/11/11 09:40:37
  • Location: 0
  • Status: offline
2017/05/19 10:05:50 (permalink)
5 (1)

Enabling CAN bus module kills Harmony

If I use the MPLAB IDE v3.61 with Harmony configurator (Installed version: 1.0.10.0 ), to add a CAN Driver to my hardware design, the resulting code runs but never exits the SYS_Initialise function.
 
If I use breakpoints to drill down inside SYS_Initialise, I find that it is the function DRV_CAN0_Initialize() that is blocking.
 
Inside DRV_CAN0_Initialize(), in the file drv_can_static, I find that the following line of code never returns...
 
while(PLIB_CAN_OperationModeGet(CAN_ID_1) != CAN_NORMAL_MODE);
 
This would tend to indicate that the preceding code line hasn't worked properly for some reason.
/* Switch the CAN module to Normal mode. Wait until the switch is complete */
PLIB_CAN_OperationModeSelect(CAN_ID_1, CAN_NORMAL_MODE);
 
Can anyone tell me how to get this Harmony-generated code working, so it doesn't get stuck forever.
 
I will, for reference, try and attach a screen-grab of the CAN configuration settings.
 
Thank you
 
PS: I am using a PIC32MZ2040EFM100, and this is a production board, not an evaluation kit.

Attached Image(s)

#1
MicroDawg
Go for a walk!?
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2015/12/04 15:06:27
  • Location: Chandler, AZ
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/19 11:14:47 (permalink) ☄ Helpfulby NicholasLee 2017/05/19 11:23:53
3 (1)
I tried to duplicate your problem, but the code works ok for me on a dev board with the echo_send CAN example code.
#2
NicholasLee
Junior Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/11/11 09:40:37
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/19 11:23:28 (permalink)
0
Thanks for trying.
 
If you turn off the BSP support in your project (so it looks like a generic chip on a board), does it still act the same way?
 
I only have Harmony generated code in my project, with a new installation of MPLAB, so it has to be a configuration issue, revealing a bug in Harmony.
#3
nigelwright7557
Super Member
  • Total Posts : 308
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/20 19:20:39 (permalink) ☄ Helpfulby NicholasLee 2017/05/22 06:57:53
3 (1)
I cant help with the Harmony problem but:
The CAN bus tries to change mode but cant do it immediately therefore the code you give waits for the CAN bus to change mode.
The CAN bus might be in the middle of sending something so cant just stop straight away.
You should see the code for setting the CAN command register to normal mode then you see the code you give that waits for it to change mode.
#4
NicholasLee
Junior Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/11/11 09:40:37
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/20 19:39:50 (permalink)
0
Thanks, Bear in mind that I haven't added any of my own code to the project yet, this is all Microchip's generated code. I have just created a blank Harmony project and added a CAN module. Adding the CAN module is enough to stall the system initialisation.
Any idea why the CAN bus would transmitting anything at all and/or unable to change mode purely based on Microchip's auto-generated code?
 
NB: If I remove the CAN module from the Harmony configuration then SYS_Init works fine, and operation continues through to run the app code state machine as it should.
 
I will do some more digging into Microchip's (undocumented) CAN software.
#5
Sobottech
Super Member
  • Total Posts : 257
  • Reward points : 0
  • Joined: 2015/12/02 03:32:17
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/21 17:22:26 (permalink) ☄ Helpfulby NicholasLee 2017/05/22 06:57:26
4 (2)
Is the transceiver connected to a CAN-Bus?
 
http://www.microchip.com/forums/m788918.aspx
#6
NicholasLee
Junior Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/11/11 09:40:37
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/22 05:44:49 (permalink)
3 (1)
The PIC isn't connected to anything at the moment, not even the CAN transceiver chip.
The isolated CAN bus transceiver circuit is on a separate module which isn't currently plugged into the PCB, so the PIC's CAN Tx and Rx lines are completely unconnected.
I'm not sure how this affects things like CAN mode selection in the SYS initialisation?
 
#7
nigelwright7557
Super Member
  • Total Posts : 308
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/22 06:43:11 (permalink) ☼ Best Answerby NicholasLee 2017/05/22 06:57:08
4.67 (3)
The PIC will get stuck in the CAN bus setup routine if there is no CAN IC connected.
#8
NicholasLee
Junior Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2014/11/11 09:40:37
  • Location: 0
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/22 06:55:49 (permalink)
4.5 (2)
Thank for the hints, I think I we have solved this now.
 
Ref: PIC32 Family Reference Manual, Section 34. Controller Area Network (CAN); 34.5.2 Normal Operation Mode
"Note: If the CAN module is not connected to the bus or a transceiver, the CAN module will not enter Normal Operation mode. This is because, the CAN module will always detect a dominant state at its receive pin."
 
i.e. Because my MCP2561 CAN Transceiver chip isn't connected to the PIC chip yet, the CAN module in the PIC cannot enter into Normal mode. The blocking check on mode-change inside the SYS init function never exits, so it never continues on to run the main app.

I "think" that a weak pull-up resistor on the CAN RX input pin on the PIC will simulate the presence of an MCP2561 in "Bus recessive mode" when it is not included on the PCB, and thereby allow the PIC to change to normal mode.
Otherwise, we would need two types of firmware, one for when the CAN circuitry is included, and one for when the CAN circuitry is not populated.
#9
Jim Nickerson
User 452
  • Total Posts : 6328
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Enabling CAN bus module kills Harmony 2017/05/22 07:02:43 (permalink)
0
Maybe the software could test for the recessive mode before calling the "DRV_CAN0_Initialize()" routine.
#10
Jump to:
© 2019 APG vNext Commercial Version 4.5