Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
I bought a EVB board (motorola starter kit) I want to use MSCAN interface in extended mode (29 bits for ID) Has Somebody a little software to test this interface (transmit one frame and receive one in polling mode). Best regards Arnaud ___________________________________________________________ |
|
|
|
try this to start, remember that you need at least one other CAN node on the network for anything to work. Steve Automated lighting systems at www.brightan.com Embedded micro-controllers and CAN interfaces at www.zanthic.com // This file may be freely distributed as long as this header remains // intact in order to encourage you to visit our web site at www.zanthic.com // This simple program was written as a quick and easy // example of initializing and testing the msCAN port // on an HC912BC32 processor. // This program was written as a single file for // simplicity and only some of the registers are included. // Written by Steve Letkeman Feb 2001 // compiled using the ICC12 compiler from imagecraft (www.imagecraft.com) // and tested on the CME-12BC32 development board from Axiom (www.axman.com) #include <hc12.h> //#include "vectors.c" void CANInit(void); #define _CAN_BASE 0x0100 // CAN Base Address #define _CP(off) *(unsigned char volatile *)(_CAN_BASE + off) #define CMCR0 _CP(0) // Control Register 0 #define CMCR1 _CP(1) // Control Register 1 #define CBTR0 _CP(2) // Bus Timing Register 0 #define CBTR1 _CP(3) // Bus Timing Register 1 #define CRFLG _CP(4) // Receiver Flag Register #define CRIER _CP(5) // Receiver Interrupt Enable Register #define CTFLG _CP(6) // Transmitter Flag Register #define CTCR _CP(7) // Transmitter Control Register #define CIDAC _CP(8) // Identifier Acceptance Control Register #define CRXERR _CP(0x0E) // Receive Error Counter #define CTXERR _CP(0x0F) // Transmitter Error Counter #define CIDAR0 _CP(0x10) // Acceptance Register 0 #define CIDAR1 _CP(0x11) // Acceptance Register 1 #define CIDAR2 _CP(0x12) // Acceptance Register 2 #define CIDAR3 _CP(0x13) // Acceptance Register 3 #define CIDMR0 _CP(0x14) // Identifier Mask Register 0 #define CIDMR1 _CP(0x15) // Identifier Mask Register 1 #define CIDMR2 _CP(0x16) // Identifier Mask Register 2 #define CIDMR3 _CP(0x17) // Identifier Mask Register 3 #define CIDAR4 _CP(0x18) // Acceptance Register 4 #define CIDAR5 _CP(0x19) // Acceptance Register 5 #define CIDAR6 _CP(0x1A) // Acceptance Register 6 #define CIDAR7 _CP(0x1B) // Acceptance Register 7 #define CIDMR4 _CP(0x1C) // Identifier Mask Register 4 #define CIDMR5 _CP(0x1D) // Identifier Mask Register 5 #define CIDMR6 _CP(0x1E) // Identifier Mask Register 6 #define CIDMR7 _CP(0x1F) // Identifier Mask Register 7 #define PCTLCAN _CP(0x3D) // Control Register #define PORTCAN _CP(0x3E) // Data Register #define DDRCAN _CP(0x3F) // Data Direction Register // from page 129 68HC912BC32.pdf #define RXIDR0 _CP(0x40) // first byte of ID for the receive buffer #define RXIDR1 _CP(0x41) // 2nd byte of ID for the receive buffer #define RXIDR2 _CP(0x42) // 3rd byte of ID for the receive buffer #define RXIDR3 _CP(0x43) // 4th byte of ID for the receive buffer #define RXDSR0 _CP(0x44) // first byte of data for the receive buffer #define RXDLR _CP(0x4C) // Data Length (number of bytes received) // create defines for the first transmit message object. The // other 2 are not defined #define TX0IDR0 _CP(0x50) // first byte of ID for the transmit buffer 0 #define TX0IDR1 _CP(0x51) // second byte of ID for the transmit buffer 0 #define TX0IDR2 _CP(0x52) // third byte of ID for the transmit buffer 0 #define TX0IDR3 _CP(0x53) // fourth byte of ID for the transmit buffer 0 #define TX0DSR0 _CP(0x54) // first byte of data #define TX0DSR1 _CP(0x55) // second byte of data...3-8 are left to you #define TX0DLR _CP(0x5C) // Data Length Register #define TX0PRI _CP(0x5D) // Priority #define TBPR _CP(0xBD) // Transmit Buffer Priority Registers void main() { unsigned char x; setbaud(BAUD9600); // initialize serial port for text output printf("CAN Test Program\n"); COPCTL=0; // turn off watchdog CANInit(); // initial CAN port printf("transmitting a message\n"); TX0IDR0=0xAA; // 29 bit ID with 1010 pattern for all 29 bits TX0IDR1=0xAA; // 29 bit is defined by setting bit 3 TX0IDR2=0xAA; TX0IDR3=0xAA; TX0DSR0=0x55; // first byte of data TX0DSR1=0x66; // second byte of data TX0DLR=0x02; // set to send 2 bytes of data while(!(CTFLG & 1)); //wait until Tx buffer is available CTFLG = 1; //transmit printf("Message transmitted\n"); printf("Transmit error counter =%d\n",CTXERR); // check for errors while(1) { printf("\nwaiting for incoming CAN message\n"); while(!(CRFLG & 1)); //wait for CAN incoming CAN message printf("Received a message!\n"); printf("ID Registers=%X-%X-%X-%X\n",RXIDR0,RXIDR1,RXIDR2,RXIDR3); if (RXIDR1 & 8) printf("This was a 29 bit message"); else printf("This was an 11 bit message"); printf(" with %d bytes of data\n",RXDLR & 0x0F); printf("Data="); for (x=0;x<(RXDLR&0x0F);x++) // loop through data printf("%X ",RXDSR0+x); printf("\n"); CRFLG |=1; // clear rec flag // transmit the initial message again while(!(CTFLG & 1)); //wait until Tx buffer is available CTFLG=1; } } void CANInit(void) { // the following two lines only apply to the Axiom HC12 board DDRCAN |=4; // turn on bit 2 which is connected to pin 8 of 82C250 PORTCAN &=~4; // clear bit to enable CMCR0 |=1; // set SFTRES to place CAN module in reset // here's one example of setting up the bit timing // set prescaler to divide by 8 (value=7) // with 16MHz crystal, after /8, tq=500ns CBTR0=0x07; // set SAMP=0, TSEG2=3 for 4tq and TSEG1=2 for 3tq // with sync segment this makes 8 tq per bit with sample point at 5/8=63% CBTR1=0x32; // for a CAN Baud of 250kbps at 16Mhz crystal //eg. 16Mhz/8/8=250k // here's another example of setting up the bit timing // set prescaler to divide by 8 (value=7) with Synch jump width=4 tq (0xC0) // with 16MHz crystal, after /8, tq=500ns //CBTR0=0xC7; // set SAMP=0, TSEG2=4 for 5tq and TSEG1=9 for 10tq // with sync segment this makes 16 tq per bit with sample point at 11/16=69% //CBTR1=0x49; // for a CAN Baud of 125kbps at 16Mhz crystal // 16Mhz/8/16=125K // CTCR will default to 0 // CIDAC will default to 0 which sets it to "Two 32 bit acceptance filters" CIDMR0=0xFF; // set filters to receive all messages regardless of acceptance CIDMR1=0xFF; // filters CIDMR2=0xFF; CIDMR3=0xFF; CMCR0 &=~1; // clear SFTRES to take CAN out of reset while (!(CMCR0 & 0x10)); // synch to CAN bus } ----- Original Message ----- From: arnaud thery To: Sent: Wednesday, January 22, 2003 4:37 PM Subject: [68HC12] MSCAN on EVB board I bought a EVB board (motorola starter kit) I want to use MSCAN interface in extended mode (29 bits for ID) Has Somebody a little software to test this interface (transmit one frame and receive one in polling mode). Best regards Arnaud ___________________________________________________________ To unsubscribe from this group, send an email to: To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu [Non-text portions of this message have been removed] |