dsPIC33EP512GM710 CAN bus stopped working

An area to discuss 16-bit PIC specific problems and examples

Moderator: Benj

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Thu Apr 18, 2019 10:37 am

More than a year ago I did a bit of work with CAN on the dsPIC33EP512GM710 and I had some issues with the speed configuration (see viewtopic.php?f=69&t=19843).
However I did get everything to work eventually.
Recently I began a new project using the same device which also needs CAN bus support, but I can't get it to work at all.
This lead me to go back to my first project to see where I was going wrong, and it 'appears' that some library file or similar update has stopped the CAN working.
If I use my original .hex file everything is fine, but when when I recompile it, the new .hex file is quite a bit smaller (26.6k rather than 28.7k) and the CAN appears to do nothing. No errors are produced during compilation.
The only thing I know that has changed in that time is that I have downloaded the 7.3 updates - unfortunately, I didn't have the foresight to back up the changed files first.
I have a feeling that it is possibly the PIC16BIT_CAL_CAN.c as I did once download the version given in this thread viewtopic.php?f=69&t=19898 and that stopped the CAN from working.

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Fri Aug 09, 2019 11:49 am

As per opening post, I can no longer produce working code from this CAN test program (dsPIC33_uart2can).

The original hex file (dsPIC33_uart2can.org.hex) works fine.
If I compile it now I get a smaller hex file (dsPIC33_uart2can.hex) that outputs nothing on the CAN bus (as observed on an oscilloscope).
I've messed about with it quite a bit using two host PCs and fresh Flowcode7 installation, but I can't get it to produce the working output.

Help! (please).

Regards,
Martin.
Attachments
dsPIC33_uart2can.org.hex
(28.72 KiB) Downloaded 1 time
dsPIC33_uart2can.hex
(26.7 KiB) Downloaded 1 time
dsPIC33_uart2can.fcfx
(25.38 KiB) Downloaded 1 time

User avatar
LeighM
Matrix Staff
Posts: 1793
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 422 times
Been thanked: 591 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Mon Aug 12, 2019 9:52 am

That does sound odd. Presumably the UART works, such that you know it's the CAN at fault?
I've attached a zip of older revisions of the PIC16BIT_CAL_CAN.c such that you can try them.
e.g. PIC16BIT_CAL_CAN@72.c is the oldest.
Attachments
PIC16BIT_CAL_CAN.zip
(56.92 KiB) Downloaded 1 time
These users thanked the author LeighM for the post:
lexicon (Mon Aug 12, 2019 10:42 am)
Rating: 5.56%
 

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Tue Aug 13, 2019 4:51 pm

Hi Leigh,

Thanks for the archive:
@72 and @278 both work (albeit with the incorrect speed as per the thread referenced in my opening post).

All the others, including the as-installed version, appear to reset the device (i.e the whole PIC) when performing a buffer send.
Initially I couldn't understand what was happening, but I added a counter and delay into my data send loop before the CAN transmit - with the non-functioning CAL files the sent counter value is always 1.

Prog attached for reference.

Regards,
Martin.
Attachments
dsPIC33_uart2can3.fcfx
(25.74 KiB) Downloaded 1 time
These users thanked the author lexicon for the post:
LeighM (Wed Aug 14, 2019 7:32 am)
Rating: 5.56%
 

User avatar
LeighM
Matrix Staff
Posts: 1793
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 422 times
Been thanked: 591 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Wed Aug 14, 2019 7:32 am

Hi Martin,
Thanks for the information - I will look into it
Leigh

User avatar
LeighM
Matrix Staff
Posts: 1793
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 422 times
Been thanked: 591 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Wed Aug 14, 2019 9:22 am

Hi Martin,
Could you please try the attached?
Thanks
Leigh
Attachments
PIC16BIT_CAL_CAN.c
(68.53 KiB) Downloaded 1 time
These users thanked the author LeighM for the post:
lexicon (Wed Aug 14, 2019 10:08 am)
Rating: 5.56%
 

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Wed Aug 14, 2019 11:06 am

Hi Leigh,

Yes, that works - thank you.

If I add my post-init config (attached) as before, the speed is correct too @ 500kbps instead of 420.
Could a fix for that also be included?

Regards,
Martin.
Attachments
DSPIC33_CAN_speed_set.txt
(1.01 KiB) Downloaded 1 time

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Thu Aug 15, 2019 2:17 pm

So, here's an odd thing - depending on other code in the program, the transmitted CAN values may not be correct.
I've not really got to grips with the details yet, but if I have a simple loop that outputs an incrementing counter in the 8 CAN message bytes it works fine.
If I implement that same method in a larger program, the first two bytes are fixed values (in this case FC & 1F) but the other six count as expected.
There's quite a bit going on in the bigger program (several ADCs, PWMs and 2 SPI outputs) so I don't yet know if any specific component is responsible for this conflict/issue...

lexicon
Flowcode v5 User
Posts: 40
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 15 times
Been thanked: 13 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Fri Aug 16, 2019 3:21 pm

Following on from the above, the attached CAN test program (DSPIC33_CAN_work) produces the expected cycling output in all 8 bytes of the CAN message.
However, 'DSPIC33_CAN_fail' always outputs the first 2 bytes as 08 00 while the other six are correct.
The only difference between the two is the UINT variable 'knacker'. This variable is not actually used, merely defined.
Other variable types that I'm using (boolean, byte & byte array) don't seem to have this affect.

During testing the results vary depending on exactly what's defined, sometimes the leading two bytes might be different or the whole 8 bytes might be incorrect, but so far always seem to be a variation on a mix of 00, 08, 1F & FC.

Edited to add: This looks similar to what was happening in this thread?
viewtopic.php?f=69&t=19898&start=25

Regards,
Martin.
Attachments
DSPIC33_CAN_fail.fcfx
(12.05 KiB) Not downloaded yet
DSPIC33_CAN_work.fcfx
(11.87 KiB) Not downloaded yet