PIC 18F4580 CAN Filters

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

PIC 18F4580 CAN Filters

#1 Post by Dakta » 08 May 2023 13:15

Morning all,

just wondering if anyone could have a quick look at the following snippet and see if I am making any glaring errors with relation to the configuration of the canbus module on PIC 18f4580,

messages are standard length, clock is 16mhz, baud should be 500kbps as it;s for powertrain canbus - everything seems to work, interrupt triggers, valid canbus messages are received however the filters are not operative, i.e i am reading all data on the bus, where I want to specifically listen for ID's with 0x7E8

I feel my error is likely a naive/daft one but I can't see it :o

Code: Select all

CANSetOperationMode(_CAN_MODE_CONFIG, 0xFF);
//set config flags
CAN_TX_BAUD_FLAGS = _CAN_CONFIG_SAMPLE_THRICE &
       _CAN_CONFIG_PHSEG2_PRG_OFF &
       _CAN_CONFIG_STD_MSG       &
       _CAN_CONFIG_DBL_BUFFER_OFF &
       _CAN_CONFIG_LINE_FILTER_OFF;

//set baud rate
CANInitialize(1,2,1,2,4, CAN_TX_BAUD_FLAGS);
//set filters
CANSetFilter(_CAN_FILTER_B1_F1, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetFilter(_CAN_FILTER_B1_F2, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetFilter(_CAN_FILTER_B2_F1, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetFilter(_CAN_FILTER_B2_F2, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetFilter(_CAN_FILTER_B2_F3, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetFilter(_CAN_FILTER_B2_F4, 0x7E8, _CAN_CONFIG_STD_MSG);
CANSetMask(_CAN_MASK_B1, 0x1FFFFFFF, _CAN_CONFIG_STD_MSG);
CANSetMask(_CAN_MASK_B2, 0x1FFFFFFF, _CAN_CONFIG_STD_MSG);
CANSetOperationMode(_CAN_MODE_NORMal, 0xFF);
PIE3.b1 = 1; PIE3.B0 = 1;
The code above is probably not perfect but it seems to work bar the filters...

Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

Re: PIC 18F4580 CAN Filters

#2 Post by Dakta » 09 May 2023 23:00

i presume the filters implementation *looks* right?

Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

Re: PIC 18F4580 CAN Filters

#3 Post by Dakta » 16 May 2023 09:36

Haven't solved the issue - a potential workaround is that I manually check the ID of the received message in the interupt handler and drop the message if not of interest.

Seems a bit rough way of doing things though - any other ideas? I've double checked against the CANBUS guide in the help and I don't think I've got anything too wrong

Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

Re: PIC 18F4580 CAN Filters

#4 Post by Dakta » 17 May 2023 22:11

Got to be someone on here who has used the canbus library?

Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

Re: PIC 18F4580 CAN Filters

#5 Post by Dakta » 19 May 2023 14:11

I think I have sussed it!

Not sure why or how, but adding _CAN_CONFIG_VALID_STD_MSG flag to the config and filters now appear to be working!

That's one of those silly things I probably should know (but can't find a lot of info on) that has stopped me for a bit far too long!

Post Reply

Return to “mikroC PRO for PIC General”