Hello I'm trying to initialize the CAN controller on the DS80C400 but I cant set the bit SWINT (C0C.0) to 0 (so the CAN controller never starts up). I wrote some valid values to C0BT1 (TSEG1 and TSEG2 other than zero). C0BT1 is locatet at the CAN data memory (and if the values TSEG1 and/or TSEG2 are zero --> SWINT will never go to 0). Now I suppose that I write the wrong memory location (access problem ? I use FVAR to acces the CAN data mem). Here's the c-code from my initCAN routine:
void initCAN() { printf("DEBUG_0: C0C: %bx \r\n", C0C); printf("DEBUG_1: C0S: %bx \r\n", C0S); while((C0C&0x08)==0x08) //while CRST == 1 (I don't know why, but if I dont do this (just try one time)--> CRST wont go to 0 { TA = 0xAA; //get write access to protected bits.. TA = 0x55; //..got acces for 3 machine cycles C0C = 0x01; //set software initialisation bit (SWINT = 1 --> disable CAN Controller) } printf("DEBUG_3: C0C: %bx \r\n", C0C); P5CNT |= 0x08; //P5CNT.3 =1; enable CAN0 pins 5.0 / 5.1 printf("DEBUG_5: C0C: %bx \r\n", C0C); //baudrate TSEG ... //set C0BT0 = 0x42; FVAR(unsigned char, 0xFFDB04) = 0x42; //SJW1-0 = 1; BPR5-0 = 0x02 printf("DEBUG_6: C0BT0: %bx \r\n", FVAR(unsigned char, 0xFFDB04)); printf("DEBUG_7: C0BT0_adr: %lx \r\n", &FVAR(unsigned char, 0xFFDB04)); // not shure if this works.. COR &= 0xE7; //C0BPR7-6 = 0; (Prescaler C0BPR0-7 is set to 2) //set C0BT0 = 0x56; FVAR(unsigned char, 0xFFDB05) = 0x56; //TSEG1 = 6, TSEG2 =5, SMP = 0 -->0x56 printf("DEBUG_8: C0BT1: %bx \r\n", FVAR(unsigned char, 0xFFDB05)); printf("DEBUG_9: C0BT1_adr: %lx \r\n", &FVAR(unsigned char, 0xFFDB05)); // not shure if this works.. //DBYTE[0xFFDB00+4] = 0x42; //reg C0BT0: BR Prescaler = 2; SJW1-0 = 1; printf("DEBUG_10: C0C: %bx \r\n", C0C); //enable message center 1 //register C0M1AR0 - C0M1AR3 FVAR(unsigned char, 0xFFDB12) = 0x00; //Extended ID = 0.. FVAR(unsigned char, 0xFFDB13) = 0x00; //.. FVAR(unsigned char, 0xFFDB14) = 0x00; //.. FVAR(unsigned char, 0xFFDB15) = 0x00; //.. + WTOE = 0; (no overwrite enable on recieve) //register C0M1F FVAR(unsigned char, 0xFFDB16) = 0x88; // 8 databytes, transmit, 11bit id, no message identification mask (recv.), // no media identification mask //enable interrups EA = 1; C0IE = 1; C0M1C = 0xC1; //message center 1 ready, enable transmit interrupt TA = 0xAA; //get write access to protected bits.. TA = 0x55; //..got acces for 3 machine cycles C0C = 0x00; //clear software initialisation bit (SWINT = 0 --> enable CAN Controller) printf("DEBUG_11: C0C: %bx \r\n", C0C); }
Hi you didn't actually manage to set CMA=1. CMA was 1 all the time, I verified this in the startup code and with the debugger... But anyway, I've got the CAN-controller running now. While debugging, I noticed that r/w from/to absolute addresses above 0x7FFFFF doesn't work. So I did set CMA to 0 (CAN mem now @ 0x00DBxx) and access the mem like this:
unsigned char far *can; ... //set C0BT0 = 0x42; can = &FVAR(unsigned char, 0x00DB04); *can = 0x42;