• AVR Freaks

Helpful ReplyHot!CAN Driver Code from Harmony 2.06

Author
DSimkin
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2019/05/22 06:30:03
  • Location: 0
  • Status: offline
2019/05/24 06:29:11 (permalink)
0

CAN Driver Code from Harmony 2.06

I have zero experience with Microchip microcontrollers and my background is mainly in desktop software development. I am developing for a PIC32MZ1024EFF100 on a custom board. I am trying to use the MPLAB Harmony Configurator (v2.06) to generate boilerplate CAN Bus code. I have tried this once and I see CAN driver code, but it's not what I expect.
 

1) Is DRV_CAN0_ChannelMessageTransmit blocking code? If so, what happens if an interrupt for some other peripheral occurs while this is blocking? Will the CAN message be lost or garbled?
 
2) Is it possible to change Harmony Configurator input parameters to generate CAN Bus code that uses interrupts? Or should I poll by repeatedly calling DRV_CAN0_ChannelMessageReceive?
 
3) DRV_CAN0_ChannelMessageTransmit calls PLIB_CAN_TransmitBufferGet. Does the buffer returned by PLIB_CAN_TransmitBufferGet require an offset? If I change DRV_CAN0_ChannelMessageTransmit to use the same buffer twice in a row before flushing, will I lose the previous message I tried to transmit? Or is this safe if I call PLIB_CAN_ChannelUpdate in between?
 
4) How large does the buffer passed to PLIB_CAN_MemoryBufferAssign need to be? The comment in generated driver code above this call says it allows for 8 message buffers, but the actual buffer passed (can_message_buffer0) has an array size of 2*2*16. If there are separate buffers for transmit and receive (2x) and there are two channels (2x), then shouldn't the array size be 2*2*8? Also, how does this relate to the channel size (1) passed to PLIB_CAN_ChannelForTransmitSet? Shouldn't channel size be the same as the number of message buffers?
#1
TS9
Super Member
  • Total Posts : 793
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
Re: CAN Driver Code from Harmony 2.06 2019/05/24 10:41:38 (permalink)
5 (1)
Hi...
 
Welcome to Microchip Forum !!!
Have you looked as below path ?
C:\microchip\harmony\v2_06\apps\examples\peripheral\can
 
..
TS9
#2
DSimkin
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2019/05/22 06:30:03
  • Location: 0
  • Status: offline
Re: CAN Driver Code from Harmony 2.06 2019/05/24 10:51:08 (permalink)
0
Yes, I have looked at the "echo_send" example. It was somewhat helpful. It shows how the driver code can be used, but it does not explain why it should be used this way, nor does explain my specific questions.
#3
Paul PortSol
Super Member
  • Total Posts : 512
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: online
Re: CAN Driver Code from Harmony 2.06 2019/05/27 04:57:17 (permalink) ☄ Helpfulby DSimkin 2019/05/28 05:06:54
4 (1)
From experience you'll probably need to do a few experiments to figure what is best for you.
I haven't done can yet, but I will have to in next phase of our project. This all based on my experience with many other Harmony Modules.
 
a) **Read the Harmony Release notes for you version, checking modules you use for any warnings or issues.
 
b) **Read the PIC Errata for the chip you use for any issues with modules in chip you use (Errata on website near datasheet)
 
c) Start a fresh project and in MHC use:Application Configuration->Generate App Code-Drivers-CAN.
This will generate example CAN code matched to both Your version of Harmony and Your Chosen PIC, without the overhead of BSP and the like.
** Be Careful: Some MHC Settings automatically enable BSP and you need to disable BSP before doing MHC Generate else you may not be able to undo all the resulting changes to the project's code. Sometimes I have to start several fresh projects while learning how a new MHC configured module works.
 
d) Some notes for working without BSP:  MHC_CreatingProjectWithoutBSP_v00PR.txt
  
e) If you get something basic working with CAN please post all you learned here for those of us who will be running into it, especially anything to be careful of or bugs in the way MHC or generated CAN code works.
 
Paul 
 
 
#4
vicoET
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2019/09/06 06:56:01
  • Location: 0
  • Status: offline
Re: CAN Driver Code from Harmony 2.06 2019/09/12 07:15:26 (permalink)
0
hi,
i see your post on CAN "echo_send".
I'm just like you now: no experience with PIC32 (PIC32MZ2048EFH064 is my board, by Olimex) but good programming knowledge.
I'm struggling with sending a simple CAN message using the example code, but still didn't have success.
It seems it gets stuck on
while(DRV_CAN0_ChannelMessageTransmit(CAN_CHANNEL0, 0x12c, 0, TestMessage) == false){
Do you you have some basic example or code that you can share?
any other help or suggestion would be very appreciated.
thank you
Vico
#5
DSimkin
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2019/05/22 06:30:03
  • Location: 0
  • Status: offline
Re: CAN Driver Code from Harmony 2.06 2019/09/17 13:14:16 (permalink)
0
I am not sure, but I think DRV_CAN0_ChannelMessageTransmit may hang if the CAN bus connected to the chip is not wired correctly (right terminating resistors etc).

In answer to my original questions:
 
1) DRV_CAN0_ChannelMessageTransmit is not normally blocking code (dedicated hardware on the microcontroller handles the actual transmission, this call just stores the message being sent in a hardware buffer).
 
3 PLIB_CAN_TransmitBufferGet does not require an offset. I believe it returns a pointer to the correct location in the buffer defined by a previous call to PLIB_CAN_MemoryBufferAssign.
#6
Jump to:
© 2019 APG vNext Commercial Version 4.5