dspic33ep128gm604 CAN BUS Problems

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

Moderator: Benj

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Wed Oct 03, 2018 11:14 am

Hello,

I´m working with a dsPIC33EP128GM604 and I have Problems with the CAN BUS component (CAN Internal 1 and CAN INternal 2).

Internal CAN 1 sends correct Data and correct ID when the Data and the ID in the Component "set tx data" are fix. But when i use variables for the data and the ID, then the received data on my CANalyzer are wrong.


Internal CAN 2
always sends wrong Data and wrong ID.
For example:
ID 0xa8
Data 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa
=> should be send (with component "set tx data")

=> but i recieve:
ID 0x00
DLC = 0
(see picture in atachments)
Attachments
dsPIC33_CAN_test.fcfx
(19.87 KiB) Downloaded 168 times
CANalyzer.JPG
CANalyzer.JPG (29.78 KiB) Viewed 5994 times

User avatar
Benj
Matrix Staff
Posts: 13980
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4244 times
Been thanked: 4006 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Benj » Wed Oct 03, 2018 12:02 pm

Hello,

Many thanks for letting us know.

We are aware of a problem with Internal CAN channel 2. I'm investigating it but currently there is a lot on my plate.

viewtopic.php?f=63&t=20406&p=90469

How urgent is the project for you. I can jump back on this later today if it's urgent.

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Wed Oct 03, 2018 1:11 pm

Hello Benj,

thanks for your answer.
It would be great if there was a solution to this problem soon, as I am under some time pressure and have not progressed for a few days. :|

In my project, i have to manipulate data in a CAN network, so the 2nd CAN channel is necessary for me.


Thanks for your help in forward

Best regards
Daniel

User avatar
Benj
Matrix Staff
Posts: 13980
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4244 times
Been thanked: 4006 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Benj » Wed Oct 03, 2018 1:40 pm

Thanks Daniel,

I'll have an investigation for you this afternoon and see where I get.

Edit: I have now done a bit of testing and it looks like both internal CAN channels are transmitting data ok. The problem seems to be to do with receiving.

Here I have CH1 sending ID1 with Data bytes all 1s and CH2 sending ID2 with Data bytes all 2s.

CANTest.jpg
CANTest.jpg (106.94 KiB) Viewed 5980 times

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Wed Oct 03, 2018 4:09 pm

Hello Benj,

ok, can you send me your current CAL_CAN file?

With the CAL_CAN file from your post in the other chat is transmitting with Ch1 ok, Ch2 sends wrong data and 2 different ID`s and I send only one ID.

The ID I want to send is 0xa7...but with the CANalyzer I see ID 0x280 and 0xFC3FC0x...
Attachments
CANalyzer_v2.JPG
CANalyzer_v2.JPG (24.51 KiB) Viewed 5975 times
dsPIC33_CAN_test.fcfx
(19.85 KiB) Downloaded 169 times

User avatar
Benj
Matrix Staff
Posts: 13980
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4244 times
Been thanked: 4006 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Benj » Wed Oct 03, 2018 5:04 pm

Hello,

Here's the current CAL file.

PIC16BIT_CAL_CAN.c
(68.31 KiB) Downloaded 184 times
These users thanked the author Benj for the post:
Chip7882 (Thu Oct 11, 2018 1:30 pm)
Rating: 5.88%
 

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1080
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 333 times
Been thanked: 539 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby QMESAR » Wed Oct 03, 2018 5:29 pm

Hi All,

Just my 2 cents from a past problem very similar to this is that if you look at your CANalyser you will notice you see 1 extended messgage ID with a DLC (Data length code )of 15 this is a PC CANalyser Driver issue specially if you use win 8 or 10 ,There is no way the PIC can send a DLC of 15
I had this issue and it drove me nuts until I found the correct driver(this was with PeakCAN though :D
I not saying this is the issue however the DLC of 15 is suspicious .
P1.jpg
P1.jpg (56.67 KiB) Viewed 5964 times

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Wed Oct 03, 2018 5:55 pm

Hi QMESAR,

thanks for your help. You`re right, dlc 15 can not be, but i think the CANalyzer shows this because the data from the pic are not plausible.
(i`m using Vector CANalyzer)

With the last CAL_CAN file from benj is transmitting ok now. The Problem now is the receive part...

Best regards
Daniel

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Thu Oct 04, 2018 12:38 pm

Hello Benj,

do you have any news about the receiving?

regards
Daniel

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Fri Oct 05, 2018 1:02 pm

Hello Benj,

when do you think you will have a solution for this issue?


Best regards
Daniel

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Fri Oct 05, 2018 2:33 pm

Hi
Can I suggest that for the receive buffer you try the property setting of "Use Mask and Filter" and set the Mask and Filter values manually.
I suspect that the "Accept All" does not work.

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Fri Oct 05, 2018 2:43 pm

Hi LeighM,

thanks for your answer. Ok i will test it and give feedback.

Best regards
Daniel

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Sat Oct 06, 2018 10:09 am

Hi LeighM,

you`re right, it works when i set the mask and filter values manually. :)

The next problem is the ID type setting in CAN 2.
When "standard & extended ID" is set, i can not compile (see attachment).
=> Some ")" were missing in the CAL_CAN file.
I fixed this, but the funktion is still not working correctly. There is a issue when I receive standard and extended ID`s on CAN 1 and want to send this ID`s on CAN 2.

Could you help me again please?

Thanks and regards
Daniel
Attachments
comp.JPG
comp.JPG (35.63 KiB) Viewed 5876 times

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Mon Oct 08, 2018 8:55 am

Thanks for the spot.
Can you try this fixed CAL file, it should now compile OK.

What function is not working?
Could you send the program that demonstrates the issue?
Attachments
PIC16BIT_CAL_CAN.c
(68.31 KiB) Downloaded 161 times

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Mon Oct 08, 2018 12:10 pm

Hi LeighM,

thanks, compile is ok now.

In the atachement is a simple the program to demonstrate. CAN 1 should receive some messages (extended and also standard IDs) and send this on CAN 2.



regards
Daniel
Attachments
dsPIC33_CAN_test.fcfx
(115.93 KiB) Downloaded 158 times

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Mon Oct 08, 2018 12:29 pm

Hi Daniel,
What works, and what does not work?
Do you receive OK?
Leigh

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Mon Oct 08, 2018 5:42 pm

Hello Leigh,

with your CAL_CAN file, i can´t send any message with CAN2. Benj has already fixed this Problem and has sent me a new Version (in his post in this chat). In this file i added the missing ")". => see the atachement
Here is receiving and sending with both CAN ok, but only for standard ID`S and setting "only standard" ID type.
When the ID type is set to "standard and extended" for both Channels and I send with my CANalyzer a standard ID message on CAN 1, than the receiving is not ok. In my program i want to send the received message on CAN2. CAN2 sends then an extended ID (see atachement)

regards
Daniel
Attachments
CANalyzer.JPG
CANalyzer.JPG (23.45 KiB) Viewed 5837 times
PIC16BIT_CAL_CAN.c
(68.31 KiB) Downloaded 141 times

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Tue Oct 09, 2018 9:09 am

Hi Daniel,
The component code is currently written such that the CAN channel either works in base frame format (11 bit ID), or extended frame format (29 bit ID) mode. Are you expecting both types on the same bus?

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Tue Oct 09, 2018 9:56 am

Hello Leigh,

yes i´m expecting both ID types on the same bus and have to send both types on CAN2.

That means I can´t do this with the current component?
Do you plan to change this?

regards
Daniel

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Tue Oct 09, 2018 2:09 pm

Hi Daniel,

Having looked at the CAL code it looks like a channel set to "standard & extended" should receive a standard ID message OK,
as the MIDE flag is set to 0. Although the GetRxIdent will most likely not return the expected ID.
Changing the code to support mixed receiving and sending will be quite a task, but we might be able to push it along,
it depends on what does actually work and how much more you need.

So, can we just summarize what you have so far...
Set both channels Id type to "standard": Receive standard id message on channel 1 and send standard id message on channel 2: OK
Set both channels Id type to "standard & extended": Receive extended id message on channel 1 and send extended id message on channel 2: OK ?
Set both channels Id type to "standard & extended": Receive standard id message on channel 1? Does CheckRx return true?

Do you need to receive and send on both channels? And does that work with standard IDs, if not extended IDs?

Leigh

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Tue Oct 09, 2018 3:40 pm

Hi Daniel,

I've got hold of some hardware (nicked off Ben :) and I've been testing sending and receiving between channel 1 and channel 2
All seems to be well as far as I can see.
I've successfully sent a standard ID message from one channel (set to "standard") and received it OK on the other channel set to "standard & extended"

I've fixed the GetRxIdent such that it uses the IDE flag from the received ID (rather than the component property mode)
So if you use the attached updated CAL file you will get the correct received message ID

The only thing we cannot do at present is dynamically change the transmit ID mode of a channel,
that's something I could have a look into, depending upon if you need it?

You made a comment earlier that you need to receive "standard" and "standard & extended" ID messages,
but send them on channel 2 as "standard & extended",
is that correct?

Leigh
Attachments
PIC16BIT_CAL_CAN.c
(68.25 KiB) Downloaded 163 times

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Tue Oct 09, 2018 7:11 pm

Hi Leigh,

many thanks for your help. :D
i have tested it, it works the way you say.


"The only thing we cannot do at present is dynamically change the transmit ID mode of a channel,
that's something I could have a look into, depending upon if you need it?"

=> That would be awesome :D

I`ve many projects with CAN networks in cars and often have to modify data from a control unit which receive the rest of the car. I seperate the bus for this, thats why i have to put through many messages (with standard IDs and also extended IDs) to the other channel.
In short I have to receive standard ID and extended ID on both Channels and send them as i received on the respective other channel. (CAN to CAN gateway)
I hope I could explain it reasonably well with my bad english :lol:

Many thanks in advance
Daniel

User avatar
LeighM
Matrix Staff
Posts: 1766
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 417 times
Been thanked: 582 times
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby LeighM » Wed Oct 10, 2018 10:34 am

Hi Daniel,

You could force the sending of a standard ID with the following C code, used instead of the SetTxIdent

can_std.jpg
can_std.jpg (31.41 KiB) Viewed 5756 times

Code: Select all

MX_MEMBUF_2[0][0] = (FCV_CAN_1_RX_ID_B0) << 2;
These users thanked the author LeighM for the post:
Chip7882 (Wed Oct 10, 2018 6:20 pm)
Rating: 5.88%
 

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Wed Oct 10, 2018 6:20 pm

Hi Leigh,

everything works perfectly now! :D :D

i did the same with "MX_MEMBUF_1[0][0]" for sending on CAN 1.
And when ID > 0x7FF => i use the component "SetTxIdent"

Thank you very much for the your great support 8)

regards
Daniel
These users thanked the author Chip7882 for the post:
Benj (Thu Oct 11, 2018 12:11 pm)
Rating: 5.88%
 

Chip7882
Posts: 17
Joined: Tue Oct 02, 2018 7:23 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: dspic33ep128gm604 CAN BUS Problems

Postby Chip7882 » Fri Jul 12, 2019 10:37 am

Hello Leigh and Ben,

i have another Problem with the CAN BUS. In my project i have a CAN to CAN gateway. so i have to send on CAN 2 all messages which i recieved on CAN 1, and the same from CAN 2 to CAN 1.
If there are many messages on the BUS sometimes messages get lost. I use "RX Buffer 1". Do you think the Buffer size is to small or what do you think is the Problem? Do you have an idea?

best regards
Daniel