Example how we use hardware CAN Acceptance Mask capability on LPC1768. Documentation is not clear !!!!! Polytech PAris SUd Orsay France
Diff: main.cpp
- Revision:
- 0:01ac4cd13c69
- Child:
- 1:168415f9f4f0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Mar 20 20:41:53 2011 +0000 @@ -0,0 +1,69 @@ +#include "mbed.h" +#include "CAN.h" + +// We use can on mbed pins 29(CAN_TXD) and 30(CAN_RXD). +CAN can2(p30, p29); +Serial pc(USBTX, USBRX); // tx, rx + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +void init_AF( void ) +{ +uint32_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; +} + +// ISR to read frame but don't work beacause no interrupts +CANMessage can_MsgRx; +bool recmess; + +void lecture(void){ + can2.read(can_MsgRx); + pc.printf("REC %u\n\r",can_MsgRx.id); + recmess=1; +} + +// Main program +int main() { + // 500kbit + can2.frequency(500000); + // Prepare MASK + init_AF(); + + while (1) { + pc.printf("%8x %8x ",LPC_CAN2->RFS,LPC_CANAF->LUTerr); + pc.printf("%8x %8x %8x %8x\n\r", LPC_CANAF->LUTerrAd,LPC_CAN2->ICR,LPC_CAN2->IER,LPC_CAN2->GSR); + wait(0.5); + if(recmess){ + led4=!led4; + recmess=0; + } + if(can2.read(can_MsgRx)){ + pc.printf("REC %x\n\r",can_MsgRx.id); + } + } +}