Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Problems with initialising msCAN hcs12 I got still some problems with the mscan. Yesterday I was told to set the CAN1IDAR-registers too (my mcu has no identifer-number at this time, how could it be possible that my test-message can pass the identifer-filter?). When I run the program in LOOP-mode on my board, only the error registers were set. There is also another problem with the bit-timing. When sending my test-message from the board to a windows can-testing-program the message could not be detected. Maybe the baudrate is not 125kbps. (16Mhz OscFreq) Regards Sebastian #include <hidef.h> /* common defines and macros */ #include <6812dp256b.h> /* derivative information */ #include "my_vectors.h" static int cnt; static int mycnt; static struct daten { char IDR0; char IDR1; char IDR2; char IDR3; char DSR[8]; char DLR; char TBPR; char TSRH; char TSRL; }; void caninit(void) { CAN1CTL1_CANE=1; //msCAN-Enable CAN1CTL0_INITRQ=1; //CAN-Modul im Resetzustand //CANxTIDR0_IDE CAN1CTL1_CLKSRC=1; //Clock=Busclock CAN1IDMR0=0xFF; CAN1IDMR1=0xFF; CAN1IDMR2=0xFF; CAN1IDMR3=0xFF; CAN1IDMR4=0xFF; CAN1IDMR5=0xFF; CAN1IDMR6=0xFF; CAN1IDMR7=0xFF; CAN1IDAR0=0xFF; CAN1IDAR1=0xFF; CAN1IDAR2=0xFF; CAN1IDAR3=0xFF; CAN1IDAR4=0xFF; CAN1IDAR5=0xFF; CAN1IDAR6=0xFF; CAN1IDAR7=0xFF; CAN1CTL1=0xc7; CAN1BTR0=0x47; //Bittiming nach eigener Brechnung CAN1BTR1=0x98; /*CAN1BTR0_SJW1=1; //beide sind: 4 Tq CAN1BTR0_SJW0=1; CAN1BTR0_BRP5=0; //Einstellung nur im INITRQ=1-Mod möglich CAN1BTR0_BRP4=0; //Prescaler-Werte Ftq=16Mhz/Presc CAN1BTR0_BRP3=0; CAN1BTR0_BRP2=0; CAN1BTR0_BRP1=1; //Presc=4 CAN1BTR0_BRP0=1; CAN1BTR1_TSEG22=0; CAN1BTR1_TSEG21=1; CAN1BTR1_TSEG20=0; CAN1BTR1_TSEG12=1; CAN1BTR1_TSEG12=0; CAN1BTR1_TSEG11=0; CAN1BTR1_TSEG10=0;*/ CAN1IDAC_IDAM1=1; //Filtereinstellung auf zwei 32 Acceptance Filter CAN1IDAC_IDAM0=1; CAN1CTL0_INITRQ=0; //Resetzustand aus MODE=0x80; //Enter Normal Single Chip Mode CAN1CTL0_WUPE=1; CAN1CTL1_LOOPB=1; //Loop Back Self Test Mode CAN1CTL0_TIME=1; //CAN-Timer enable DDRB=0xFF; PORTB=0; } void senddata(struct daten) { //Daten können nur gesendet werden, wenn die TXEx-Flags 1 und damit die Sende-Puffer leer sind if(CAN1TFLG_TXE2==1) { //zum Puffern bereit CAN1TBSEL=0x04;//Puffer TX2 ist ausgwählt (durch einen Pointer) CAN1TXIDR0=daten.IDR0; /* MSCAN Identifier Register 0 */ CAN1TXIDR1=daten.IDR1; /* MSCAN Identifier Register 1 */ CAN1TXIDR2=daten.IDR2; /* MSCAN Identifier Register 2 */ CAN1TXIDR3=daten.IDR3; /* MSCAN Identifier Register 0 */ CAN1TXDSR0=daten.DSR[0]; /* MSCAN Data Segment Register 0 */ CAN1TXDSR1=daten.DSR[1]; /* MSCAN Data Segment Register 1 */ CAN1TXDSR2=daten.DSR[2]; /* MSCAN Data Segment Register 2 */ CAN1TXDSR3=daten.DSR[3]; /* MSCAN Data Segment Register 3 */ CAN1TXDSR4=daten.DSR[4]; /* MSCAN Data Segment Register 4 */ CAN1TXDSR5=daten.DSR[5]; /* MSCAN Data Segment Register 5 */ CAN1TXDSR6=daten.DSR[6]; /* MSCAN Data Segment Register 6 */ CAN1TXDSR7=daten.DSR[7]; /* MSCAN Data Segment Register 7 */ CAN1TXDLR =daten.DLR; //Datenlängenregister CAN1TXTBPR=daten.TBPR; //Sendepufferpriorität CAN1TFLG_TXE2=1; //Löschen des Flag durch Einschreiben einer 1 für Sendebereitschaft } } void main(void) { /* put your own code here */ caninit(); struct daten message1 ={ 0,0,0,0, 55, 55, 55, 55, 55, 55, 55, 55, 16,1,0,0};//1 statt 0 senddata(message1); for(;;) { cnt++; if(CAN1CTL0_SYNCH==1) { PORTB=0x55; } } } |
|
|
|
I could solve the problem on my own. The mistake was, that I changed the canclk from osc-clk to busclk, but still thinking that the canclk uses the osc-clk. CAN1CTL1_CLKSRC=0; //Clock=Osc. --- In , "Sebastian Schuster" <schusti@w...> wrote: > Problems with initialising msCAN hcs12 > > I got still some problems with the mscan. Yesterday I was told to set > the CAN1IDAR-registers too (my mcu has no identifer-number at this > time, how could it be possible that my test-message can pass the > identifer-filter?). When I run the program in LOOP-mode on my board, > only the error registers were set. > There is also another problem with the bit-timing. When sending my > test-message from the board to a windows can-testing-program the > message could not be detected. Maybe the baudrate is not 125kbps. > (16Mhz OscFreq) > > Regards > > Sebastian |
|
So what is this msCAN? It seems that I recall a prohibitively expensive third party CAN program being available from Motorola. Is this it? The ms part makes one think it is a Microsoft offering. Thanks, Bob White ----- Original Message ----- From: "Sebastian Schuster" <> To: <> Sent: Tuesday, April 20, 2004 12:18 AM Subject: [68HC12] Re: Problems with initialising msCAN I could solve the problem on my own. The mistake was, that I changed the canclk from osc-clk to busclk, but still thinking that the canclk uses the osc-clk. CAN1CTL1_CLKSRC=0; //Clock=Osc. --- In , "Sebastian Schuster" <schusti@w...> wrote: > Problems with initialising msCAN hcs12 > > I got still some problems with the mscan. Yesterday I was told to set > the CAN1IDAR-registers too (my mcu has no identifer-number at this > time, how could it be possible that my test-message can pass the > identifer-filter?). When I run the program in LOOP-mode on my board, > only the error registers were set. > There is also another problem with the bit-timing. When sending my > test-message from the board to a windows can-testing-program the > message could not be detected. Maybe the baudrate is not 125kbps. > (16Mhz OscFreq) > > Regards > > Sebastian --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Links |
|
|
|
The msCAN is a hardware-FullCAN-Controller in the hcs12.
-----Ursprüngliche Nachricht----- Von: Bob White [mailto:] Gesendet: Dienstag, 20. April 2004 14:51 An: Betreff: Re: [68HC12] Re: Problems with initialising msCAN So what is this msCAN? It seems that I recall a prohibitively expensive third party CAN program being available from Motorola. Is this it? The ms part makes one think it is a Microsoft offering. Thanks, Bob White ----- Original Message ----- From: "Sebastian Schuster" <> To: <> Sent: Tuesday, April 20, 2004 12:18 AM Subject: [68HC12] Re: Problems with initialising msCAN I could solve the problem on my own. The mistake was, that I changed the canclk from osc-clk to busclk, but still thinking that the canclk uses the osc-clk. CAN1CTL1_CLKSRC=0; //Clock=Osc. --- In , "Sebastian Schuster" <schusti@w...> wrote: > Problems with initialising msCAN hcs12 > > I got still some problems with the mscan. Yesterday I was told to set > the CAN1IDAR-registers too (my mcu has no identifer-number at this > time, how could it be possible that my test-message can pass the > identifer-filter?). When I run the program in LOOP-mode on my board, > only the error registers were set. > There is also another problem with the bit-timing. When sending my > test-message from the board to a windows can-testing-program the > message could not be detected. Maybe the baudrate is not 125kbps. > (16Mhz OscFreq) > > Regards > > Sebastian --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Links --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu Yahoo! Groups Links |
|
If you are running in loop back mode, you have no timing problems to worry about since you are not communicating via the CAN bus. Set your filters to accept all messages and get the rest working first. Actually, in loop back mode I'll bet you are also circumventing the filtering mechanism since you are bypassing the background receive buffer. Sydney ----- Original Message ----- From: Sebastian Schuster To: Sent: Tuesday, April 20, 2004 2:43 AM Subject: [68HC12] Problems with initialising msCAN Problems with initialising msCAN hcs12 I got still some problems with the mscan. Yesterday I was told to set the CAN1IDAR-registers too (my mcu has no identifer-number at this time, how could it be possible that my test-message can pass the identifer-filter?). When I run the program in LOOP-mode on my board, only the error registers were set. There is also another problem with the bit-timing. When sending my test-message from the board to a windows can-testing-program the message could not be detected. Maybe the baudrate is not 125kbps. (16Mhz OscFreq) Regards Sebastian #include <hidef.h> /* common defines and macros */ #include <6812dp256b.h> /* derivative information */ #include "my_vectors.h" static int cnt; static int mycnt; static struct daten { char IDR0; char IDR1; char IDR2; char IDR3; char DSR[8]; char DLR; char TBPR; char TSRH; char TSRL; }; void caninit(void) { CAN1CTL1_CANE=1; //msCAN-Enable CAN1CTL0_INITRQ=1; //CAN-Modul im Resetzustand //CANxTIDR0_IDE CAN1CTL1_CLKSRC=1; //Clock=Busclock CAN1IDMR0=0xFF; CAN1IDMR1=0xFF; CAN1IDMR2=0xFF; CAN1IDMR3=0xFF; CAN1IDMR4=0xFF; CAN1IDMR5=0xFF; CAN1IDMR6=0xFF; CAN1IDMR7=0xFF; CAN1IDAR0=0xFF; CAN1IDAR1=0xFF; CAN1IDAR2=0xFF; CAN1IDAR3=0xFF; CAN1IDAR4=0xFF; CAN1IDAR5=0xFF; CAN1IDAR6=0xFF; CAN1IDAR7=0xFF; CAN1CTL1=0xc7; CAN1BTR0=0x47; //Bittiming nach eigener Brechnung CAN1BTR1=0x98; /*CAN1BTR0_SJW1=1; //beide sind: 4 Tq CAN1BTR0_SJW0=1; CAN1BTR0_BRP5=0; //Einstellung nur im INITRQ=1-Mod möglich CAN1BTR0_BRP4=0; //Prescaler-Werte Ftq=16Mhz/Presc CAN1BTR0_BRP3=0; CAN1BTR0_BRP2=0; CAN1BTR0_BRP1=1; //Presc=4 CAN1BTR0_BRP0=1; CAN1BTR1_TSEG22=0; CAN1BTR1_TSEG21=1; CAN1BTR1_TSEG20=0; CAN1BTR1_TSEG12=1; CAN1BTR1_TSEG12=0; CAN1BTR1_TSEG11=0; CAN1BTR1_TSEG10=0;*/ CAN1IDAC_IDAM1=1; //Filtereinstellung auf zwei 32 Acceptance Filter CAN1IDAC_IDAM0=1; CAN1CTL0_INITRQ=0; //Resetzustand aus MODE=0x80; //Enter Normal Single Chip Mode CAN1CTL0_WUPE=1; CAN1CTL1_LOOPB=1; //Loop Back Self Test Mode CAN1CTL0_TIME=1; //CAN-Timer enable DDRB=0xFF; PORTB=0; } void senddata(struct daten) { //Daten können nur gesendet werden, wenn die TXEx-Flags 1 und damit die Sende-Puffer leer sind if(CAN1TFLG_TXE2==1) { //zum Puffern bereit CAN1TBSEL=0x04;//Puffer TX2 ist ausgwählt (durch einen Pointer) CAN1TXIDR0=daten.IDR0; /* MSCAN Identifier Register 0 */ CAN1TXIDR1=daten.IDR1; /* MSCAN Identifier Register 1 */ CAN1TXIDR2=daten.IDR2; /* MSCAN Identifier Register 2 */ CAN1TXIDR3=daten.IDR3; /* MSCAN Identifier Register 0 */ CAN1TXDSR0=daten.DSR[0]; /* MSCAN Data Segment Register 0 */ CAN1TXDSR1=daten.DSR[1]; /* MSCAN Data Segment Register 1 */ CAN1TXDSR2=daten.DSR[2]; /* MSCAN Data Segment Register 2 */ CAN1TXDSR3=daten.DSR[3]; /* MSCAN Data Segment Register 3 */ CAN1TXDSR4=daten.DSR[4]; /* MSCAN Data Segment Register 4 */ CAN1TXDSR5=daten.DSR[5]; /* MSCAN Data Segment Register 5 */ CAN1TXDSR6=daten.DSR[6]; /* MSCAN Data Segment Register 6 */ CAN1TXDSR7=daten.DSR[7]; /* MSCAN Data Segment Register 7 */ CAN1TXDLR =daten.DLR; //Datenlängenregister CAN1TXTBPR=daten.TBPR; //Sendepufferpriorität CAN1TFLG_TXE2=1; //Löschen des Flag durch Einschreiben einer 1 für Sendebereitschaft } } void main(void) { /* put your own code here */ caninit(); struct daten message1 ={ 0,0,0,0, 55, 55, 55, 55, 55, 55, 55, 55, 16,1,0,0};//1 statt 0 senddata(message1); for(;;) { cnt++; if(CAN1CTL0_SYNCH==1) { PORTB=0x55; } } } --------------------------------------------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu ---------------------------------------------------------------------------- -- Yahoo! Groups Links a.. To [Non-text portions of this message have been removed] |