Bus could be flooded due to bitrate mismatch. If only one device is sending
at a time, then the width of the shortest pulse on the bus equals to the bit
time of this sening node. Just check if it's 2us (0.5Mbps) or not.
Edward
----- Original Message -----
From: "Johannes Schmid" <
johannes.schmid@...>
To: <
68HC12@...>
Sent: Wednesday, May 06, 2009 21:33
Subject: [68HC12] MSCAN problem
> Hi everybody!
>
> I have a problem using the CAN-Bus interface of the HCS12 used in the
> MicroSquirt(tm) ECU we use on our Formula race car.
>
> Following the various data sheets I came up with the following code:
>
> void CanInit(void)
> {
> /* Set up CAN communications */
> /* Enable CAN, set Init mode so can change registers */
> CANCTL1 |= 0x80;
> CANCTL0 |= 0x01;
>
> while(!(CANCTL1 & 0x01))
> ; // make sure in init mode
>
> /* Set Can enable, use IPBusclk (24 MHz),clear rest */
> CANCTL1 = 0xC0;
> /* Set timing for .5Mbits/ sec */
> CANBTR0 = 0xC2; /* SJW=4,BR Prescaler= 3(24MHz CAN clk) */
> CANBTR1 = 0x1C; /* Set time quanta: tseg2 =2,tseg1=13
> (16 Tq total including sync seg (=1)) */
>
> CANIDAC &= ~0x30; /* no filters */
>
> /* clear init mode */
> CANCTL0 &= 0xFE;
> /* wait for synch to bus */
> while(!(CANCTL0 & 0x10));
>
> /* no xmit yet */
> CANTIER = 0x00;
> /* clear RX flag to ready for CAN recv interrupt */
> CANRFLG = 0xC3;
> /* set CAN rcv full interrupt bit */
> CANRIER = 0x01;
> return;
> }
>
> void CanSend(CAN_message* msg)
> {
> unsigned char txbuffer, i;
> static unsigned char flag = 1;
>
> if (!flag)
> return;
> flag = 0;
>
> if (!CANTFLG)
> return; // everything is more important than messages from the
> ECU, so just drop out if we cannot send
>
> CANTBSEL = CANTFLG; // Select free buffer to use
> txbuffer = CANTBSEL; // backup buffer
>
> CAN_TB0_IDR0 = (unsigned char) msg->id >> 3; // higher 8 bits of id
> CAN_TB0_IDR1 = (unsigned char) msg->id << 5; // lower 3 bits of id;
> CAN_TB0_IDR1 &= ~(0x18); // Set to standard frames (IDE = 0)
> CAN_TB0_IDR2 = 0;
> CAN_TB0_IDR3 = 0;
>
> for (i = 0; i < msg->length; i++) {
> *(&CAN_TB0_DSR0 + i) = msg->data[i];
> }
>
> CAN_TB0_DLR = msg->length; // Set length
> CAN_TB0_TBPR = 0; // priority
>
> // Send message
> CANTFLG = txbuffer;
> }
>
> However, when I send a single CAN message, MSCAN floods the CAN-Bus with
> messages (sending probably any us) and never stops. I checked on the
> osci and there is an ACK on the bus so I guess everything should be
> fine. Do I need to clear some buffer to make it stop sending messages?
>
> Thanks a lot for your help
>
> Johannes
>
>
> --
> Johannes Schmid
> High-Octane-Motorsports
> Teamleiter Elektronik
>
johannes.schmid@...
> 0179 / 1674917
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>