cancel
Showing results for 
Search instead for 
Did you mean: 

can message acceptance filtering

smart
Associate II
Posted on September 04, 2009 at 14:44

can message acceptance filtering

3 REPLIES 3
smart
Associate II
Posted on May 17, 2011 at 13:22

can anybody help me in setting up the message filtering for CAN

I want to receive CAN message which are meant for me

I have running slave devices and I want to get interrupted when I receive the message for that particular ID

For example In my hardware I read the switch address lets say it is 5.

Now I want to recive interrupt only when I receive the message the CAN message for node ID 5.

Can anybody provide me some example code.

Thanks

ahnniu
Associate II
Posted on May 17, 2011 at 13:22

hi smart.avr,

The following section of code may be helpful, using older versions of STLIB.

Code:

void can_filter_config(void)

{

CAN_FilterInitTypeDef CAN_FilterInitStructure;

/* CAN filter init */

CAN_FilterInitStructure.CAN_FilterNumber=0;

CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;

CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

// Set the node ID that you want to receive

CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;

CAN_FilterInitStructure.CAN_FilterIdLow=0x0005;

// Mask the high 16 bits,if you don't use the extern mode

CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;

CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xFFFF;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;

// enable the filter

CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);

}

Good Luck!

-------------------

There is a

http://www.coocox.org/CoOS.htm

on

http://www.coocox.org/

smart
Associate II
Posted on May 17, 2011 at 13:22

thanks for your reply

but still my I am not able to receive CAN packet with ID 5

I been using CAN interrupt and canopen from last one year and I am getting interrupt for every CAN packets but when I use filtering I dont get Interrupts for that particular ID, I dont know whats wrong with the STM32 CAN filtering please help me.

my code is given below:

This is the CAN packet that I am sending..

ID length D0 D1 D2 D3 D4 D5 D6 D7

0005 8 11 22 44 66 77 88 66 55

________________________________________________________________________

/* CAN filter init */

CAN_FilterInitStructure.CAN_FilterNumber=0;

CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;

CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;

CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; ;

CAN_FilterInitStructure.CAN_FilterIdLow=0x0005 ; ;

CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000 ; ;

CAN_FilterInitStructure.CAN_FilterMaskIdLow=0xFFFF;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0 ;

CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);

/* CAN FIFO0 message pending interrupt enable */

CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

**********CAN interrupt code*****************************

void USB_LP_CAN1_RX0_IRQHandler(void)

{

CanRxMsg RxMessage;

static Message m = Message_Initializer;

CAN_Receive(CAN1,CAN_FIFO0, &RxMessage);

m.cob_id = RxMessage.StdId;

m.len = RxMessage.DLC;

m.rtr = 0;

m.data[0] = RxMessage.Data[0];

m.data[1] = RxMessage.Data[1];

m.data[2] = RxMessage.Data[2];

m.data[3] = RxMessage.Data[3];

m.data[4] = RxMessage.Data[4];

m.data[5] = RxMessage.Data[5];

m.data[6] = RxMessage.Data[6];

m.data[7] = RxMessage.Data[7];