CARME-M4 BSP  V1.5
can_acceptancefilter.c

Explains how to set a acceptance filter on the CAN transceiver.

/*
* This example shows how to set a acceptance filter on the SJA100 CAN
* transceiver.
*/
#include <stm32f4xx.h>
#include <carme.h>
#include <can.h>
/* initialize the Array with accepted IDs */
uint8_t acceptedId[] = {
0x10,
0x20,
0x30
};
int main(void) {
uint8_t arrayIndex;
/* initialize the SJA1000 chip */
/*
* Initializing of the Acceptance Filter. This Code initializes the filter
* to 0xXZX where X is don't care and Z is the value in the acceptedId
* array.
*/
af.afm = MODE_SINGLE; /* Single filter */
/* unmask the important bits by setting them to Zero */
af.amr[0] = 0xe1; /* unmask bit 4 - 8 */
af.amr[1] = 0xff; /* the lower 4 bit should always be masked */
af.amr[2] = 0xff; /* don't care in Mode with normal id length */
af.amr[3] = 0xff; /* don't care in Mode with normal id length */
/* set the bits which have to be high */
af.acr[0] = acceptedId[arrayIndex] >> 3; /* set the accepted bits 4 - 8 */
af.acr[1] = 0x00;
af.acr[2] = 0x00; /* don't care in Mode with normal id length */
af.acr[3] = 0x00; /* don't care in Mode with normal id length */
/* set the AF */
/* set the SJA1000 chip in running mode */
while (1) {
}
return 0;
}