CARME-M4 BSP
V1.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
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
>
CARME_CAN_ACCEPTANCE_FILTER
af;
/* initialize the Array with accepted IDs */
uint8_t acceptedId[] = {
0x10,
0x20,
0x30
};
int
main(
void
) {
uint8_t arrayIndex;
/* initialize the SJA1000 chip */
CARME_CAN_Init
(
CARME_CAN_BAUD_250K
,
CARME_CAN_DF_RESET
);
/*
* 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 */
CARME_CAN_SetAcceptaceFilter
(&af);
/* set the SJA1000 chip in running mode */
CARME_CAN_SetMode
(
CARME_CAN_DF_NORMAL
);
while
(1) {
}
return
0;
}
Generated on Fri Aug 12 2016 17:42:38 for CARME-M4 BSP by
1.8.10