dsPIC33EP512GM710 CAN bus stopped working

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

Moderator: Benj

lexicon
Flowcode v5 User
Posts: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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 8 times
dsPIC33_uart2can.hex
(26.7 KiB) Downloaded 9 times
dsPIC33_uart2can.fcfx
(25.38 KiB) Downloaded 7 times

User avatar
LeighM
Matrix Staff
Posts: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 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 6 times
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: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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 8 times
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: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 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: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 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 8 times
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: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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 8 times

lexicon
Flowcode v5 User
Posts: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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: 44
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 16 times
Been thanked: 15 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) Downloaded 10 times
DSPIC33_CAN_work.fcfx
(11.87 KiB) Downloaded 9 times

User avatar
LeighM
Matrix Staff
Posts: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Fri Aug 23, 2019 9:17 am

I've not managed to resolve this yet.
Have you tried Flowcode V8 with this?
(As I've no hardware to test it on)

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

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Fri Aug 23, 2019 9:25 am

No, not tried that - I can give it a go though...

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

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Fri Aug 23, 2019 12:04 pm

Hi Leigh,
On FC8 we're back to the device apparently resetting on a buffer send.
I tried the new CAN CAL file posted earlier, but that made no difference (are these files compatible between 7 & 8?)

Regards,
Martin.

User avatar
LeighM
Matrix Staff
Posts: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Fri Aug 23, 2019 12:09 pm

Hi Martin,
Thanks for trying.
Yes, the two CAL files are the same at the moment (apart from a little header text)
The FC8 version goes here, which is usualy a hidden folder ...
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC16BIT
These users thanked the author LeighM for the post:
lexicon (Fri Aug 23, 2019 1:49 pm)
Rating: 5.56%
 

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

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Fri Aug 23, 2019 1:22 pm

Hi Leigh,

I'd put the CAL in the wrong place - Program Files(x86)/Flowcode v8/DefaultData.
Putting it in the ProgramData path makes the CAN work, but gives the same corrupted data as FC7.

Regards,
Martin.
These users thanked the author lexicon for the post:
LeighM (Fri Aug 23, 2019 1:24 pm)
Rating: 5.56%
 

User avatar
LeighM
Matrix Staff
Posts: 1843
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 611 times
Contact:

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby LeighM » Tue Aug 27, 2019 11:34 am

Here's another variation that might be worth a try ...
Attachments
PIC16BIT_CAL_CAN.c
(68.52 KiB) Downloaded 5 times

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

Re: dsPIC33EP512GM710 CAN bus stopped working

Postby lexicon » Wed Aug 28, 2019 9:54 am

Hi Leigh,

That gave the same results (CAN output but corrupted).

It also generated these warning messages during compile:
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c: In function 'FC_CAL_Internal_CAN_Init_1':
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c:350:16: warning: cast from pointer to integer of different size
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c:351:16: warning: cast from pointer to integer of different size
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c:366:16: warning: cast from pointer to integer of different size
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c:367:16: warning: cast from pointer to integer of different size

Regards,
Martin.
These users thanked the author lexicon for the post:
LeighM (Wed Aug 28, 2019 10:32 am)
Rating: 5.56%