CAN Acceptance Filter Works !!!!!

20 Mar 2011

Hello, (Polytech Paris Sud Orsay) We resolved CAN Acceptance Filter problem. We know now how it Works.

our problem is to attach interrupt to CAN class to manage received Frames without explicit call to read in the main program.

The Attach method don't work because the ISR dont Activate IDIE bit and dont test IDI bit of the ICR register.

Just call init_AF function before entering While(1) loop.

/** Begin program **/

void init_AF( void )

int32_t address = 4;

/*off mode*/

LPC_CANAF->AFMR = 0x00000001;

/* Set explicit standard Frame*/

LPC_CANAF->SFF_sa = address;/* word 1*/

/* CAN2 IDENT FORCE1*/

LPC_CANAF_RAM->mask[1]=(0X001 << 29) | (0X400 << 16)| (1<<27)|

(0X001 << 13)| (0X500 ) | (1<<11) ;

/* Only Frame ID 0x400 and 0x500 are received in MBED.*/

address+=4;/*add 4 bytes (1 long word) to point to none used word.*/

/* Set group standard Frame*/

LPC_CANAF->SFF_GRP_sa = address;

/* Set explicit extended Frame*/

LPC_CANAF->EFF_sa = address;

/* Set group extended Frame*/

LPC_CANAF->EFF_GRP_sa = address;

/* Set End of Table */

LPC_CANAF->ENDofTable = address;

/* All have ENDofTable address means are not used.*/

/*normal mode*/

LPC_CANAF->AFMR = 0x00000000;

return;

/* end Program */

Now continue to add attach_Acceptance_Filter method to add ISR.

Good experience.

I will post CAN_ACC_FILTER program example.

14 May 2013

Hello Samir,

I have been trying to use the .attach() function of the CAN library for quite sometime, and have only recently discovered that the function does not work due to some bug. I came across your post here, but am unable to understand exactly how I can use it. Can you give an example code?

Here is my code to receive a CAN message based on an interrupt...

CAN_Attach_Test

#include "mbed.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(p30, p29);
CANMessage msg;
void rec_CAN()
{
    printf("rec_CAN()");
    printf("Message received: %d\n", msg.data[0]);
            led2 = !led2;
}

int main() 
{   
    __enable_irq();
    void (*fptr)();
    fptr=&(rec_CAN);
    can1.attach((*fptr));
    printf("main()\n");

   
    while(1) {
        printf("Waiting for CAN message\n");
        led1 =!led1;
        wait(0.2);
    }
}

This code doesn't work as the attach function does not do anything.

Can you please tell me where I am supposed to put in your code, so as to properly initialize the required registers and make attach function work?

Thank you.