// select ID which can be receive
CANIDT4 = (uint8_t) (msg.id << 3);
CANIDT3 = (uint8_t) (msg.id >> 5);
CANIDT2 = (uint8_t) (msg.id >> 13);
CANIDT1 = (uint8_t) (msg.id >> 21);
// set mask in order to receive only the message with the ID
CANIDM4 = 248;
CANIDM3 = 255;
CANIDM2 = 255;
CANIDM1 = 255;
// enable extended ID
CANIDM4 |= (1<<IDEMSK);
// enable reception and
CANCDMOB=(1<<CONMOB1) | (1<<IDE);
// wait until reception is complete
while(!(CANSTMOB&(1<<RXOK)));
// reset flag
CANSTMOB &= ~(1<<RXOK);
// get data
for (unsigned char i=0; i<(CANCDMOB&0xf); i++)
msg.data = CANMSG;
//get identifier which has to be the same like ID
msg.id = 0;
msg.id |= ((unsigned long) CANIDT1<<24);
msg.id |= ((unsigned long) CANIDT2<<16);
msg.id |= ((unsigned long) CANIDT3<<8);
msg.id |= (CANIDT4&0xF8);
msg.id >>= 3;
}
// message to receive
struct MOb msg={0x1,{0,0,0,0,0,0,0,0}};
// toggle the LED on the Crumb-Board
#define toggleLED() (DDRB^=(1<<7))
int main(){
// init usart on 19200 8N1 at 16 MHz cpu clock
usart0_init(51);
// greet the world
usart0_transmit_string("Hello World\n");
// init the can interface
can_init();