Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | MSCAN problem

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

MSCAN problem - Johannes Schmid - May 6 14:34:33 2009

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
j...@octanes.de
0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: MSCAN problem - Steve Letkeman - May 6 15:14:55 2009

I didn't look over your code but your comments about the message
continuing to
send caught my attention. This might be an obvious question, but do you
have
at least two CAN nodes on the network? CAN is not like RS232 where you
can just send a message to nobody, you must have another node with the
correct
settings for the message to be ACK'd. It also requires a properly
terminated
network, two 120 ohm resistors on each end and a common ground. Maybe
these have been covered but they are worth mentioning just in case...
Steve
--
Steven D. Letkeman BSc.
Zanthic Technologies Inc.
www.zanthic.com Embedded micro-controllers and CAN interfaces
Johannes Schmid wrote:
> 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
> j...@octanes.de
> 0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Johannes Schmid - May 6 17:12:57 2009

Hi!
> I didn't look over your code but your comments about the message
> continuing to
> send caught my attention. This might be an obvious question, but do
> you
> have
> at least two CAN nodes on the network? CAN is not like RS232 where you
> can just send a message to nobody, you must have another node with
> the
> correct
> settings for the message to be ACK'd. It also requires a properly
> terminated
> network, two 120 ohm resistors on each end and a common ground. Maybe
> these have been covered but they are worth mentioning just in case...

Yes, we have two terminations and tried with various nodes. As already
said, we also checked the ACK on the Bus using a scope. The other nodes
are known to work flawlessly as well as the Peak PCAN usb Dongle we use.

I was also suspected the ACK first but seems that this isn't the problem
(or the MSCAN does not recognize the ACK for some reason).

Regards,
Johannes
> --
> Steven D. Letkeman BSc.
> Zanthic Technologies Inc.
> www.zanthic.com Embedded micro-controllers and CAN interfaces
>
> Johannes Schmid wrote:
> >
> >
> > 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
> > j...@octanes.de
> > 0179 / 1674917
> >
> --
Johannes Schmid
High-Octane-Motorsports
Teamleiter Elektronik
j...@octanes.de
0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Steve Letkeman - May 6 17:23:59 2009

ok, I thought it was important to cover the basics first as you just
never know
where a person is starting from. Here is some very old and outdated code
but it may point you in the right direction...
Steve

// 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 home of the CAN-4-USB interface
// This simple program was written as a quick and easy

// example of initializing and testing the msCAN port (V2.14)
// on an MC9S12 processor. No warranty implied or given.
// This program was written as a single file for
// simplicity and only some of the registers are included.
// Written by Steve Letkeman Feb 2004

// compiled using the ICC12 compiler from imagecraft (www.imagecraft.com)
// Vector file not included but only contains two entries, start at 0xFFFE
// and the CAN0 receive interrupt vector pointing to CAN_Receive()

// sends CAN ID 1 (29 bit) at power up and receives ID 2 (29 bit) and
// echos back to ID 1 when received

#define CAN0CTL0 *(unsigned char volatile *)(0x0140)
#define CAN0CTL1 *(unsigned char volatile *)(0x0141)
#define CAN0BTR0 *(unsigned char volatile *)(0x0142)
#define CAN0BTR1 *(unsigned char volatile *)(0x0143)
#define CAN0RFLG *(unsigned char volatile *)(0x0144)
#define CAN0RIER *(unsigned char volatile *)(0x0145)
#define CAN0TFLG *(unsigned char volatile *)(0x0146)
//#define CAN0TIER *(unsigned char volatile *)(0x0147)
//#define CAN0TARQ *(unsigned char volatile *)(0x0148)
//#define CAN0TAAK *(unsigned char volatile *)(0x0149)
#define CAN0TBSEL *(unsigned char volatile *)(0x014A)
#define CAN0IDAC *(unsigned char volatile *)(0x014B)
//#define CAN0RXERR *(unsigned char volatile *)(0x014E)
//#define CAN0TXERR *(unsigned char volatile *)(0x014F)
#define CAN0IDAR0 *(unsigned char volatile *)(0x0150)
#define CAN0IDAR1 *(unsigned char volatile *)(0x0151)
#define CAN0IDAR2 *(unsigned char volatile *)(0x0152)
#define CAN0IDAR3 *(unsigned char volatile *)(0x0153)
#define CAN0IDMR0 *(unsigned char volatile *)(0x0154)
#define CAN0IDMR1 *(unsigned char volatile *)(0x0155)
#define CAN0IDMR2 *(unsigned char volatile *)(0x0156)
#define CAN0IDMR3 *(unsigned char volatile *)(0x0157)
#define CAN0IDAR4 *(unsigned char volatile *)(0x0158)
#define CAN0IDAR5 *(unsigned char volatile *)(0x0159)
#define CAN0IDAR6 *(unsigned char volatile *)(0x015A)
#define CAN0IDAR7 *(unsigned char volatile *)(0x015B)
#define CAN0IDMR4 *(unsigned char volatile *)(0x015C)
#define CAN0IDMR5 *(unsigned char volatile *)(0x015D)
#define CAN0IDMR6 *(unsigned char volatile *)(0x015E)
#define CAN0IDMR7 *(unsigned char volatile *)(0x015F)
#define CAN0RXFG (unsigned char volatile *)(0x0160)
#define CAN0TXFG (unsigned char volatile *)(0x0170)

#define CANE 0x80
#define INITAK 1
#define INITRQ 1
#define SLPRQ 2
#define SLPAK 2

void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr);
void CANInit(void);

void main(void)
{
unsigned char BufPntr[8];

CANInit();

asm("cli");

BufPntr[0]=0x11;
BufPntr[1]=0x22;
BufPntr[2]=0x33;
BufPntr[3]=0x44;
BufPntr[4]=0x55;
BufPntr[5]=0x66;
BufPntr[6]=0x77;
BufPntr[7]=0x88;

SendCANMessage(8, BufPntr); // send a CAN packet
with 8 bytes of data

while(1); // wait here for
receive interupt

}

//
#############################################################################

// Incoming CAN messages will be caught here
#pragma interrupt_handler CAN_Receive
void CAN_Receive(void)
{
unsigned char Temp[8];

Temp[0]=*(CAN0RXFG+4); // Grab the first data byte
// currently no checking for
number of bytes etc
SendCANMessage(1, Temp); // send it back

CAN0RFLG |=1; // clear rec flag
}

//
#############################################################################

void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr)
{
unsigned char NACAN,C;

while(!CAN0TFLG); // wait for
available buffer
NACAN=CAN0TFLG; // get the
next available CAN buffer
CAN0TBSEL=NACAN;

*(CAN0TXFG+0)=0x00; // set the
transmit ID
*(CAN0TXFG+1)=0x08; // extended ID
(29 bit)
*(CAN0TXFG+2)=0x00;
*(CAN0TXFG+3)=0x02; //
ID=00-00-00-01

if (NumBytes>8) NumBytes=8;
for (C=0;C *(CAN0TXFG+4+C)=*BufPntr++; // store the data

*(CAN0TXFG+0x0C)=NumBytes; // set number of
bytes to send

NACAN=CAN0TBSEL;
CAN0TFLG =NACAN; // transmit
}

//
#############################################################################

void CANInit(void)
{
CAN0CTL0 |= INITRQ; // set
INITRQ, this will also set INITAK
while (!(CAN0CTL1 & INITAK)); // wait for init
mode to occur

CAN0CTL1 = CANE; // Set CANE just
in case this is the first time after reset

CAN0BTR0=0x03;
CAN0BTR1=0x32; // for a CAN
Baud of 500kbps at 16Mhz crystal

CAN0IDMR0=0x00;
CAN0IDMR1=0x08; //IDE=1
CAN0IDMR2=0x00;
CAN0IDMR3=0x00;

CAN0IDAR0=0x00;
CAN0IDAR1=0x18; // SRR&IDE=1
CAN0IDAR2=0x00;
CAN0IDAR3=0x04; // ID=2, remote
frame (bit 0)=0

// set the second filter to must match 0xFFFFFFFF
CAN0IDMR4=0;
CAN0IDMR5=8; //IDE=1
CAN0IDMR6=0;
CAN0IDMR7=0;
CAN0IDAR4=0xFF;
CAN0IDAR5=0xFF;
CAN0IDAR6=0xFF;
CAN0IDAR7=0xFF;

CAN0IDAC=0; // set filters to
2 32 bit acceptance filters

CAN0CTL0 &= ~INITRQ; // clear
INITRQ
while (CAN0CTL1 & INITAK);

CAN0CTL1 |= CANE; // Set CANE
just in case this is the first time after reset
CAN0RIER |= 1; // enable
receive interrupt

}
Johannes Schmid wrote:
> Hi!
>
> > I didn't look over your code but your comments about the message
> > continuing to
> > send caught my attention. This might be an obvious question, but do
> > you
> > have
> > at least two CAN nodes on the network? CAN is not like RS232 where you
> > can just send a message to nobody, you must have another node with
> > the
> > correct
> > settings for the message to be ACK'd. It also requires a properly
> > terminated
> > network, two 120 ohm resistors on each end and a common ground. Maybe
> > these have been covered but they are worth mentioning just in case...
>
> Yes, we have two terminations and tried with various nodes. As already
> said, we also checked the ACK on the Bus using a scope. The other nodes
> are known to work flawlessly as well as the Peak PCAN usb Dongle we use.
>
> I was also suspected the ACK first but seems that this isn't the problem
> (or the MSCAN does not recognize the ACK for some reason).
>
> Regards,
> Johannes
>
> > --
> > Steven D. Letkeman BSc.
> > Zanthic Technologies Inc.
> > www.zanthic.com Embedded micro-controllers and CAN interfaces
> >
> > Johannes Schmid wrote:
> > >
> > >
> > > 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
> > > j...@octanes.de
>
> > > 0179 / 1674917
> > >
> > >
> >
> >
> >
> >
> >
> --
> Johannes Schmid
> High-Octane-Motorsports
> Teamleiter Elektronik
> j...@octanes.de
> 0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Johannes Schmid - May 6 17:33:38 2009

Hi!

Thanks, I think I found this in the mailing list archive before because
this was the code I started from. I had to change some names because
register definition were a bit different (only one MSCAN, so CAN0CTL
becomes CANCTL, etc.) and we use short identifiers (11 bit) but in the
end I implemented exactly this.

Did this work correctly for you on real hardware?

Thanks,
Johannes

Am Mittwoch, den 06.05.2009, 15:23 -0600 schrieb Steve Letkeman:
> ok, I thought it was important to cover the basics first as you just
> never know
> where a person is starting from. Here is some very old and outdated
> code
> but it may point you in the right direction...
> Steve
>
> // 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 home of the CAN-4-USB interface
> // This simple program was written as a quick and easy
>
> // example of initializing and testing the msCAN port (V2.14)
> // on an MC9S12 processor. No warranty implied or given.
> // This program was written as a single file for
> // simplicity and only some of the registers are included.
> // Written by Steve Letkeman Feb 2004
>
> // compiled using the ICC12 compiler from imagecraft
> (www.imagecraft.com)
> // Vector file not included but only contains two entries, start at
> 0xFFFE
> // and the CAN0 receive interrupt vector pointing to CAN_Receive()
>
> // sends CAN ID 1 (29 bit) at power up and receives ID 2 (29 bit) and
> // echos back to ID 1 when received
>
> #define CAN0CTL0 *(unsigned char volatile *)(0x0140)
> #define CAN0CTL1 *(unsigned char volatile *)(0x0141)
> #define CAN0BTR0 *(unsigned char volatile *)(0x0142)
> #define CAN0BTR1 *(unsigned char volatile *)(0x0143)
> #define CAN0RFLG *(unsigned char volatile *)(0x0144)
> #define CAN0RIER *(unsigned char volatile *)(0x0145)
> #define CAN0TFLG *(unsigned char volatile *)(0x0146)
> //#define CAN0TIER *(unsigned char volatile *)(0x0147)
> //#define CAN0TARQ *(unsigned char volatile *)(0x0148)
> //#define CAN0TAAK *(unsigned char volatile *)(0x0149)
> #define CAN0TBSEL *(unsigned char volatile *)(0x014A)
> #define CAN0IDAC *(unsigned char volatile *)(0x014B)
> //#define CAN0RXERR *(unsigned char volatile *)(0x014E)
> //#define CAN0TXERR *(unsigned char volatile *)(0x014F)
> #define CAN0IDAR0 *(unsigned char volatile *)(0x0150)
> #define CAN0IDAR1 *(unsigned char volatile *)(0x0151)
> #define CAN0IDAR2 *(unsigned char volatile *)(0x0152)
> #define CAN0IDAR3 *(unsigned char volatile *)(0x0153)
> #define CAN0IDMR0 *(unsigned char volatile *)(0x0154)
> #define CAN0IDMR1 *(unsigned char volatile *)(0x0155)
> #define CAN0IDMR2 *(unsigned char volatile *)(0x0156)
> #define CAN0IDMR3 *(unsigned char volatile *)(0x0157)
> #define CAN0IDAR4 *(unsigned char volatile *)(0x0158)
> #define CAN0IDAR5 *(unsigned char volatile *)(0x0159)
> #define CAN0IDAR6 *(unsigned char volatile *)(0x015A)
> #define CAN0IDAR7 *(unsigned char volatile *)(0x015B)
> #define CAN0IDMR4 *(unsigned char volatile *)(0x015C)
> #define CAN0IDMR5 *(unsigned char volatile *)(0x015D)
> #define CAN0IDMR6 *(unsigned char volatile *)(0x015E)
> #define CAN0IDMR7 *(unsigned char volatile *)(0x015F)
> #define CAN0RXFG (unsigned char volatile *)(0x0160)
> #define CAN0TXFG (unsigned char volatile *)(0x0170)
>
> #define CANE 0x80
> #define INITAK 1
> #define INITRQ 1
> #define SLPRQ 2
> #define SLPAK 2
>
> void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr);
> void CANInit(void);
>
> void main(void)
> {
> unsigned char BufPntr[8];
>
> CANInit();
>
> asm("cli");
>
> BufPntr[0]=0x11;
> BufPntr[1]=0x22;
> BufPntr[2]=0x33;
> BufPntr[3]=0x44;
> BufPntr[4]=0x55;
> BufPntr[5]=0x66;
> BufPntr[6]=0x77;
> BufPntr[7]=0x88;
>
> SendCANMessage(8, BufPntr); // send a CAN packet
> with 8 bytes of data
>
> while(1); // wait here for
> receive interupt
>
> }
>
> //
> #############################################################################
>
> // Incoming CAN messages will be caught here
> #pragma interrupt_handler CAN_Receive
> void CAN_Receive(void)
> {
> unsigned char Temp[8];
>
> Temp[0]=*(CAN0RXFG+4); // Grab the first data byte
> // currently no checking for
> number of bytes etc
> SendCANMessage(1, Temp); // send it back
>
> CAN0RFLG |=1; // clear rec flag
> }
>
> //
> #############################################################################
>
> void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr)
> {
> unsigned char NACAN,C;
>
> while(!CAN0TFLG); // wait for
> available buffer
> NACAN=CAN0TFLG; // get the
> next available CAN buffer
> CAN0TBSEL=NACAN;
>
> *(CAN0TXFG+0)=0x00; // set the
> transmit ID
> *(CAN0TXFG+1)=0x08; // extended ID
> (29 bit)
> *(CAN0TXFG+2)=0x00;
> *(CAN0TXFG+3)=0x02; //
> ID=00-00-00-01
>
> if (NumBytes>8) NumBytes=8;
> for (C=0;C > *(CAN0TXFG+4+C)=*BufPntr++; // store the data
>
> *(CAN0TXFG+0x0C)=NumBytes; // set number of
> bytes to send
>
> NACAN=CAN0TBSEL;
> CAN0TFLG =NACAN; // transmit
> }
>
> //
> #############################################################################
>
> void CANInit(void)
> {
> CAN0CTL0 |= INITRQ; // set
> INITRQ, this will also set INITAK
> while (!(CAN0CTL1 & INITAK)); // wait for init
> mode to occur
>
> CAN0CTL1 = CANE; // Set CANE just
> in case this is the first time after reset
>
> CAN0BTR0=0x03;
> CAN0BTR1=0x32; // for a CAN
> Baud of 500kbps at 16Mhz crystal
>
> CAN0IDMR0=0x00;
> CAN0IDMR1=0x08; //IDE=1
> CAN0IDMR2=0x00;
> CAN0IDMR3=0x00;
>
> CAN0IDAR0=0x00;
> CAN0IDAR1=0x18; // SRR&IDE=1
> CAN0IDAR2=0x00;
> CAN0IDAR3=0x04; // ID=2, remote
> frame (bit 0)=0
>
> // set the second filter to must match 0xFFFFFFFF
> CAN0IDMR4=0;
> CAN0IDMR5=8; //IDE=1
> CAN0IDMR6=0;
> CAN0IDMR7=0;
> CAN0IDAR4=0xFF;
> CAN0IDAR5=0xFF;
> CAN0IDAR6=0xFF;
> CAN0IDAR7=0xFF;
>
> CAN0IDAC=0; // set filters to
> 2 32 bit acceptance filters
>
> CAN0CTL0 &= ~INITRQ; // clear
> INITRQ
> while (CAN0CTL1 & INITAK);
>
> CAN0CTL1 |= CANE; // Set CANE
> just in case this is the first time after reset
> CAN0RIER |= 1; // enable
> receive interrupt
>
> }
>
> Johannes Schmid wrote:
> >
> >
> > Hi!
> >
> > > I didn't look over your code but your comments about the message
> > > continuing to
> > > send caught my attention. This might be an obvious question, but
> do
> > > you
> > > have
> > > at least two CAN nodes on the network? CAN is not like RS232 where
> you
> > > can just send a message to nobody, you must have another node with
> > > the
> > > correct
> > > settings for the message to be ACK'd. It also requires a properly
> > > terminated
> > > network, two 120 ohm resistors on each end and a common ground.
> Maybe
> > > these have been covered but they are worth mentioning just in
> case...
> >
> > Yes, we have two terminations and tried with various nodes. As
> already
> > said, we also checked the ACK on the Bus using a scope. The other
> nodes
> > are known to work flawlessly as well as the Peak PCAN usb Dongle we
> use.
> >
> > I was also suspected the ACK first but seems that this isn't the
> problem
> > (or the MSCAN does not recognize the ACK for some reason).
> >
> > Regards,
> > Johannes
> >
> > > --
> > > Steven D. Letkeman BSc.
> > > Zanthic Technologies Inc.
> > > www.zanthic.com Embedded micro-controllers and CAN interfaces
> > >
> > > Johannes Schmid wrote:
> > > >
> > > >
> > > > 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
> > > > j...@octanes.de > 40octanes.de>
> >
> > > > 0179 / 1674917
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > --
> > Johannes Schmid
> > High-Octane-Motorsports
> > Teamleiter Elektronik
> > j...@octanes.de
> > 0179 / 1674917
> >
> --
Johannes Schmid
High-Octane-Motorsports
Teamleiter Elektronik
j...@octanes.de
0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Steve Letkeman - May 6 18:31:09 2009

yes, it did work on hardware. Is it possible you have a hardware rec
pin issue? That
would explain the correct Ack on the bus and the continuous sending. Is
there any
pin routing involved in your scheme, maybe?
S
Johannes Schmid wrote:
> Hi!
>
> Thanks, I think I found this in the mailing list archive before because
> this was the code I started from. I had to change some names because
> register definition were a bit different (only one MSCAN, so CAN0CTL
> becomes CANCTL, etc.) and we use short identifiers (11 bit) but in the
> end I implemented exactly this.
>
> Did this work correctly for you on real hardware?
>
> Thanks,
> Johannes
>
> Am Mittwoch, den 06.05.2009, 15:23 -0600 schrieb Steve Letkeman:
> >
> >
> > ok, I thought it was important to cover the basics first as you just
> > never know
> > where a person is starting from. Here is some very old and outdated
> > code
> > but it may point you in the right direction...
> > Steve
> >
> > // 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 home of the CAN-4-USB interface
> > // This simple program was written as a quick and easy
> >
> > // example of initializing and testing the msCAN port (V2.14)
> > // on an MC9S12 processor. No warranty implied or given.
> > // This program was written as a single file for
> > // simplicity and only some of the registers are included.
> > // Written by Steve Letkeman Feb 2004
> >
> > // compiled using the ICC12 compiler from imagecraft
> > (www.imagecraft.com)
> > // Vector file not included but only contains two entries, start at
> > 0xFFFE
> > // and the CAN0 receive interrupt vector pointing to CAN_Receive()
> >
> > // sends CAN ID 1 (29 bit) at power up and receives ID 2 (29 bit) and
> > // echos back to ID 1 when received
> >
> > #define CAN0CTL0 *(unsigned char volatile *)(0x0140)
> > #define CAN0CTL1 *(unsigned char volatile *)(0x0141)
> > #define CAN0BTR0 *(unsigned char volatile *)(0x0142)
> > #define CAN0BTR1 *(unsigned char volatile *)(0x0143)
> > #define CAN0RFLG *(unsigned char volatile *)(0x0144)
> > #define CAN0RIER *(unsigned char volatile *)(0x0145)
> > #define CAN0TFLG *(unsigned char volatile *)(0x0146)
> > //#define CAN0TIER *(unsigned char volatile *)(0x0147)
> > //#define CAN0TARQ *(unsigned char volatile *)(0x0148)
> > //#define CAN0TAAK *(unsigned char volatile *)(0x0149)
> > #define CAN0TBSEL *(unsigned char volatile *)(0x014A)
> > #define CAN0IDAC *(unsigned char volatile *)(0x014B)
> > //#define CAN0RXERR *(unsigned char volatile *)(0x014E)
> > //#define CAN0TXERR *(unsigned char volatile *)(0x014F)
> > #define CAN0IDAR0 *(unsigned char volatile *)(0x0150)
> > #define CAN0IDAR1 *(unsigned char volatile *)(0x0151)
> > #define CAN0IDAR2 *(unsigned char volatile *)(0x0152)
> > #define CAN0IDAR3 *(unsigned char volatile *)(0x0153)
> > #define CAN0IDMR0 *(unsigned char volatile *)(0x0154)
> > #define CAN0IDMR1 *(unsigned char volatile *)(0x0155)
> > #define CAN0IDMR2 *(unsigned char volatile *)(0x0156)
> > #define CAN0IDMR3 *(unsigned char volatile *)(0x0157)
> > #define CAN0IDAR4 *(unsigned char volatile *)(0x0158)
> > #define CAN0IDAR5 *(unsigned char volatile *)(0x0159)
> > #define CAN0IDAR6 *(unsigned char volatile *)(0x015A)
> > #define CAN0IDAR7 *(unsigned char volatile *)(0x015B)
> > #define CAN0IDMR4 *(unsigned char volatile *)(0x015C)
> > #define CAN0IDMR5 *(unsigned char volatile *)(0x015D)
> > #define CAN0IDMR6 *(unsigned char volatile *)(0x015E)
> > #define CAN0IDMR7 *(unsigned char volatile *)(0x015F)
> > #define CAN0RXFG (unsigned char volatile *)(0x0160)
> > #define CAN0TXFG (unsigned char volatile *)(0x0170)
> >
> > #define CANE 0x80
> > #define INITAK 1
> > #define INITRQ 1
> > #define SLPRQ 2
> > #define SLPAK 2
> >
> > void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr);
> > void CANInit(void);
> >
> > void main(void)
> > {
> > unsigned char BufPntr[8];
> >
> > CANInit();
> >
> > asm("cli");
> >
> > BufPntr[0]=0x11;
> > BufPntr[1]=0x22;
> > BufPntr[2]=0x33;
> > BufPntr[3]=0x44;
> > BufPntr[4]=0x55;
> > BufPntr[5]=0x66;
> > BufPntr[6]=0x77;
> > BufPntr[7]=0x88;
> >
> > SendCANMessage(8, BufPntr); // send a CAN packet
> > with 8 bytes of data
> >
> > while(1); // wait here for
> > receive interupt
> >
> > }
> >
> > //
> >
> #############################################################################
>
> >
> > // Incoming CAN messages will be caught here
> > #pragma interrupt_handler CAN_Receive
> > void CAN_Receive(void)
> > {
> > unsigned char Temp[8];
> >
> > Temp[0]=*(CAN0RXFG+4); // Grab the first data byte
> > // currently no checking for
> > number of bytes etc
> > SendCANMessage(1, Temp); // send it back
> >
> > CAN0RFLG |=1; // clear rec flag
> > }
> >
> > //
> >
> #############################################################################
>
> >
> > void SendCANMessage(unsigned char NumBytes, unsigned char *BufPntr)
> > {
> > unsigned char NACAN,C;
> >
> > while(!CAN0TFLG); // wait for
> > available buffer
> > NACAN=CAN0TFLG; // get the
> > next available CAN buffer
> > CAN0TBSEL=NACAN;
> >
> > *(CAN0TXFG+0)=0x00; // set the
> > transmit ID
> > *(CAN0TXFG+1)=0x08; // extended ID
> > (29 bit)
> > *(CAN0TXFG+2)=0x00;
> > *(CAN0TXFG+3)=0x02; //
> > ID=00-00-00-01
> >
> > if (NumBytes>8) NumBytes=8;
> > for (C=0;C > > *(CAN0TXFG+4+C)=*BufPntr++; // store the data
> >
> > *(CAN0TXFG+0x0C)=NumBytes; // set number of
> > bytes to send
> >
> > NACAN=CAN0TBSEL;
> > CAN0TFLG =NACAN; // transmit
> > }
> >
> > //
> >
> #############################################################################
>
> >
> > void CANInit(void)
> > {
> > CAN0CTL0 |= INITRQ; // set
> > INITRQ, this will also set INITAK
> > while (!(CAN0CTL1 & INITAK)); // wait for init
> > mode to occur
> >
> > CAN0CTL1 = CANE; // Set CANE just
> > in case this is the first time after reset
> >
> > CAN0BTR0=0x03;
> > CAN0BTR1=0x32; // for a CAN
> > Baud of 500kbps at 16Mhz crystal
> >
> > CAN0IDMR0=0x00;
> > CAN0IDMR1=0x08; //IDE=1
> > CAN0IDMR2=0x00;
> > CAN0IDMR3=0x00;
> >
> > CAN0IDAR0=0x00;
> > CAN0IDAR1=0x18; // SRR&IDE=1
> > CAN0IDAR2=0x00;
> > CAN0IDAR3=0x04; // ID=2, remote
> > frame (bit 0)=0
> >
> > // set the second filter to must match 0xFFFFFFFF
> > CAN0IDMR4=0;
> > CAN0IDMR5=8; //IDE=1
> > CAN0IDMR6=0;
> > CAN0IDMR7=0;
> > CAN0IDAR4=0xFF;
> > CAN0IDAR5=0xFF;
> > CAN0IDAR6=0xFF;
> > CAN0IDAR7=0xFF;
> >
> > CAN0IDAC=0; // set filters to
> > 2 32 bit acceptance filters
> >
> > CAN0CTL0 &= ~INITRQ; // clear
> > INITRQ
> > while (CAN0CTL1 & INITAK);
> >
> > CAN0CTL1 |= CANE; // Set CANE
> > just in case this is the first time after reset
> > CAN0RIER |= 1; // enable
> > receive interrupt
> >
> > }
> >
> > Johannes Schmid wrote:
> > >
> > >
> > > Hi!
> > >
> > > > I didn't look over your code but your comments about the message
> > > > continuing to
> > > > send caught my attention. This might be an obvious question, but
> > do
> > > > you
> > > > have
> > > > at least two CAN nodes on the network? CAN is not like RS232 where
> > you
> > > > can just send a message to nobody, you must have another node with
> > > > the
> > > > correct
> > > > settings for the message to be ACK'd. It also requires a properly
> > > > terminated
> > > > network, two 120 ohm resistors on each end and a common ground.
> > Maybe
> > > > these have been covered but they are worth mentioning just in
> > case...
> > >
> > > Yes, we have two terminations and tried with various nodes. As
> > already
> > > said, we also checked the ACK on the Bus using a scope. The other
> > nodes
> > > are known to work flawlessly as well as the Peak PCAN usb Dongle we
> > use.
> > >
> > > I was also suspected the ACK first but seems that this isn't the
> > problem
> > > (or the MSCAN does not recognize the ACK for some reason).
> > >
> > > Regards,
> > > Johannes
> > >
> > > > --
> > > > Steven D. Letkeman BSc.
> > > > Zanthic Technologies Inc.
> > > > www.zanthic.com Embedded micro-controllers and CAN interfaces
> > > >
> > > > Johannes Schmid wrote:
> > > > >
> > > > >
> > > > > 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
> > > > > j...@octanes.de
> > > 40octanes.de>
> > >
> > > > > 0179 / 1674917
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > --
> > > Johannes Schmid
> > > High-Octane-Motorsports
> > > Teamleiter Elektronik
> > > j...@octanes.de
>
> > > 0179 / 1674917
> > >
> > >
> >
> >
> >
> >
> >
> --
> Johannes Schmid
> High-Octane-Motorsports
> Teamleiter Elektronik
> j...@octanes.de
> 0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Edward Karpicz - May 7 4:11:30 2009

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"
To: <6...@yahoogroups.com>
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
> j...@octanes.de
> 0179 / 1674917
>
> ------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Johannes Schmid - May 7 4:51:51 2009

Hi!
> yes, it did work on hardware. Is it possible you have a hardware rec
> pin issue? That
> would explain the correct Ack on the bus and the continuous sending.
> Is
> there any
> pin routing involved in your scheme, maybe?
> S
>
Well, the schemas are available here:
http://www.microsquirt.info/us_hardware.htm

We bought the pre-build device so I hope there are no routing errors. We
also checked that CANH/CANL are correctly wired on the CAN-driver-ic.
But if you say that this code should do than we probably really have
hardware issues or the bus timing is incorrect.

Thanks for your help so far!

Johannes

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Johannes Schmid - May 7 4:52:42 2009

Hi!

> 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.
>
OK, I will check this. Unforntunately the bus timing documentation of
the hcs12 is a bit strage but I will have a second look at it.

Thanks,
Johannes
> Edward
>
> ----- Original Message -----
> From: "Johannes Schmid"
> To: <6...@yahoogroups.com>
> 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
> > j...@octanes.de
> > 0179 / 1674917
> >
> >
> >
> > ------------------------------------
> >
> >



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: MSCAN problem - Johannes Schmid - May 7 5:56:13 2009

Hi!

> 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.
>

OK, I checked the clock speed things again and it's absolutely correct. Here is the code:

/* Set Can enable, use IPBusclk (24 MHz),clear rest */
CANCTL1 = 0xC0; // CANE = 1, CLKRSRC = 1 (Bus Clock)

/* Set timing for .5Mbits/ sec */
CANBTR0 = 0xC2; /* SJW=4,BR Prescaler= 3(24MHz CAN clk) */
CANBTR1 = 0x58; /* Tseg2 = 6, Tseg1 = 9 (Tseg1 + Tseg1 + Sync(=1) = 16 => 8 Mhz / 16 = 0.5 Mhz */

I adjusted the Tseg timings a bit because the manual says that my original timings weren't standard compliant but I didn't make a difference. The bit width on the scope was also correct.

Johannes

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

A good book for the MC9S12DP512? - Jerry Fields - May 7 10:07:31 2009


=20

Hello all,
I am looking for a good tutorial type book on my microcontroller. I have a =
MC9S12DP512 on a CMD-12DP512 development board. Devry provided me with a go=
od book for the HC11 back in 1994. "The 68HC11 Microcontroller" by Greenfie=
ld. It would be great to find a book that would take me step-by-step into a=
ll the functions for my current MCU! Thanks alot in advance!

=20

Jerry Fields

=20

=20

=20

=20

=20

=20

=20

=20

=20

=20

=20

=20

=20

_________________________________________________________________
Hotmail=AE goes with you.=20
http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=3DTXT_TAGLM_WL_HM_Tutor=
ial_Mobile1_052009

[Non-text portions of this message have been removed]

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: A good book for the MC9S12DP512? - "Dr. David A. Perreault" - May 7 13:40:50 2009

*Software and Hardware Engineering: Motorola M68HC12
*by Prof. Fred Cady and Jim Sibigtroth

Available from Oxford University press, Amazon, or Barnes & Noble (ISBN=20
0-19-512469-3). Fred Cady has written other college textbooks for the=20
M68HC11 and has been teaching microcontrollers at Montana State=20
University-Bozeman for several years. Jim Sibigtroth is the Motorola=20
systems engineer who defined the M68HC11, wrote the M68HC11 Reference=20
Manual (aka the Pink Book), and was part of the team that defined the=20
M68HC12.

This book can be used as a textbook for an undergraduate course on=20
microcontrollers, as a reference manual for the M68HC12, or as a source=20
for numerous programming examples. The early chapters can also serve as=20
a tutorial for engineers who are new to assembly language programming.=20
All code examples were developed and assembled using P&E Microcomputer=20
Systems tools, and can be run on the M68EVB912B32 or M68HC12A4EVB=20
evaluation boards.

Jerry Fields wrote:
>
> Hello all,
>
> I am looking for a good tutorial type book on my microcontroller. I=20
> have a MC9S12DP512 on a CMD-12DP512 development board. Devry provided=20
> me with a good book for the HC11 back in 1994. "The 68HC11=20
> Microcontroller" by Greenfield. It would be great to find a book that=20
> would take me step-by-step into all the functions for my current MCU!=20
> Thanks alot in advance!
>
> Jerry Fields
>
> __________________________________________________________
> Hotmail=AE goes with you.
> http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=3DTXT_TAGLM_WL_HM_Tut=
orial_Mobile1_052009=20
> torial_Mobile1_052009> [Non-text portions of this message have been removed]
>
>=20

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: A good book for the MC9S12DP512? - mculater12 - May 7 17:16:32 2009

Hi Jerry,

There are some newer books that specifically cover the MC9S12 (as opposed t=
o the older 68HC12 technology). I've compiled a list of all the books I've=
come across over the past little while here:
http://www.technologicalarts.ca/catalog/index.php?cPath=3D23
My top three picks (based on books I've actually purchased and read) appear=
at the top of the Amazon list (Huang, Cady, and Barret/Pack). However, th=
ere are some I haven't read yet ;o)

Best regards,
Carl Barnes
www.technologicalarts.com
Evaluate * Educate * Embed

--- In 6...@yahoogroups.com, "Dr. David A. Perreault" wrote:
>
> *Software and Hardware Engineering: Motorola M68HC12
> *by Prof. Fred Cady and Jim Sibigtroth
>=20
> Available from Oxford University press, Amazon, or Barnes & Noble (ISBN=20
> 0-19-512469-3). Fred Cady has written other college textbooks for the=20
> M68HC11 and has been teaching microcontrollers at Montana State=20
> University-Bozeman for several years. Jim Sibigtroth is the Motorola=20
> systems engineer who defined the M68HC11, wrote the M68HC11 Reference=20
> Manual (aka the Pink Book), and was part of the team that defined the=20
> M68HC12.
>=20
> This book can be used as a textbook for an undergraduate course on=20
> microcontrollers, as a reference manual for the M68HC12, or as a source=20
> for numerous programming examples. The early chapters can also serve as=20
> a tutorial for engineers who are new to assembly language programming.=20
> All code examples were developed and assembled using P&E Microcomputer=20
> Systems tools, and can be run on the M68EVB912B32 or M68HC12A4EVB=20
> evaluation boards.
>=20
>=20
>=20
>=20
> Jerry Fields wrote:
> >
> >
> >
> >
> >
> > Hello all,
> >
> > I am looking for a good tutorial type book on my microcontroller. I=20
> > have a MC9S12DP512 on a CMD-12DP512 development board. Devry provided=20
> > me with a good book for the HC11 back in 1994. "The 68HC11=20
> > Microcontroller" by Greenfield. It would be great to find a book that=20
> > would take me step-by-step into all the functions for my current MCU!=20
> > Thanks alot in advance!
> >
> > Jerry Fields
> >
> > __________________________________________________________
> > Hotmail=AE goes with you.
> > http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=3DTXT_TAGLM_WL_HM_T=
utorial_Mobile1_052009=20
> > Tutorial_Mobile1_052009>
> >
> > [Non-text portions of this message have been removed]
> >
> >=20
>=20
>=20
>=20
> [Non-text portions of this message have been removed]
>

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

RE: Re: A good book for the MC9S12DP512? - Jerry Fields - May 8 8:21:17 2009


Thanks a lot Carl! I would also like to thank all of you for your replies! =
With all of the engineering tasks my job puts in front of me, this will mak=
e things much easier!=20
=20
It is very much appreciated!=20
=20
Thanks again,
Jerry Fields

=20

=20

=20
=20
To: 6...@yahoogroups.com
From: m...@yahoo.com
Date: Thu, 7 May 2009 21:15:22 +0000
Subject: [68HC12] Re: A good book for the MC9S12DP512?

Hi Jerry,

There are some newer books that specifically cover the MC9S12 (as opposed t=
o the older 68HC12 technology). I've compiled a list of all the books I've =
come across over the past little while here:
http://www.technologicalarts.ca/catalog/index.php?cPath=3D23
My top three picks (based on books I've actually purchased and read) appear=
at the top of the Amazon list (Huang, Cady, and Barret/Pack). However, the=
re are some I haven't read yet ;o)

Best regards,
Carl Barnes
www.technologicalarts.com
Evaluate * Educate * Embed

--- In 6...@yahoogroups.com, "Dr. David A. Perreault" wrote:
>
> *Software and Hardware Engineering: Motorola M68HC12
> *by Prof. Fred Cady and Jim Sibigtroth
>=20
> Available from Oxford University press, Amazon, or Barnes & Noble (ISBN=20
> 0-19-512469-3). Fred Cady has written other college textbooks for the=20
> M68HC11 and has been teaching microcontrollers at Montana State=20
> University-Bozeman for several years. Jim Sibigtroth is the Motorola=20
> systems engineer who defined the M68HC11, wrote the M68HC11 Reference=20
> Manual (aka the Pink Book), and was part of the team that defined the=20
> M68HC12.
>=20
> This book can be used as a textbook for an undergraduate course on=20
> microcontrollers, as a reference manual for the M68HC12, or as a source=20
> for numerous programming examples. The early chapters can also serve as=20
> a tutorial for engineers who are new to assembly language programming.=20
> All code examples were developed and assembled using P&E Microcomputer=20
> Systems tools, and can be run on the M68EVB912B32 or M68HC12A4EVB=20
> evaluation boards.
>=20
>=20
>=20
>=20
> Jerry Fields wrote:
> >
> >
> >
> >
> >
> > Hello all,
> >
> > I am looking for a good tutorial type book on my microcontroller. I=20
> > have a MC9S12DP512 on a CMD-12DP512 development board. Devry provided=20
> > me with a good book for the HC11 back in 1994. "The 68HC11=20
> > Microcontroller" by Greenfield. It would be great to find a book that=20
> > would take me step-by-step into all the functions for my current MCU!=20
> > Thanks alot in advance!
> >
> > Jerry Fields
> >
> > __________________________________________________________
> > Hotmail=AE goes with you.
> > http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=3DTXT_TAGLM_WL_HM_T=
utorial_Mobile1_052009=20
> > Tutorial_Mobile1_052009>
> >
> > [Non-text portions of this message have been removed]
> >
> >=20
>=20
>=20
>=20
> [Non-text portions of this message have been removed]
>

_________________________________________________________________
Hotmail=AE has a new way to see what's up with your friends.
http://windowslive.com/Tutorial/Hotmail/WhatsNew?ocid=3DTXT_TAGLM_WL_HM_Tut=
orial_WhatsNew1_052009

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - James Murray - May 12 15:58:18 2009

Have you asked about this on the Megasquirt forums?
We welcome similar discussions on www.msextra.com

James

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - Johannes Schmid - May 12 16:07:57 2009

Hi!

> Have you asked about this on the Megasquirt forums?
> We welcome similar discussions on www.msextra.com

Yes, I did: http://www.msefi.com/viewtopic.php?f=69&t=35338

Actually I really would like to use the msextra code because it has a
much better structure (not to mention that I was very lucky to get a
free educational license from Freescale and it would be much easier with
gcc). Anyway, msextra does not yet support our v-twin
(http://www.msefi.com/viewtopic.php?f=89&t=34979) yet.

Did you experience problems like this with msextra? The CAN code seems
to be mostly the same.

Regards,
Johannes
--
Johannes Schmid
High-Octane-Motorsports
Teamleiter Elektronik
j...@octanes.de
0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: MSCAN problem - James Murray - May 12 16:59:00 2009

Once I understood the Megasquirt usage of CAN, it has been working ok.

I also have CAN running on the 9S12XEP100 processor communicating with the Megasquirt firmware on the 9S12C64.

James

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: MSCAN problem - Johannes Schmid - May 19 10:11:42 2009

Hi!

> I also have CAN running on the 9S12XEP100 processor communicating with
> the Megasquirt firmware on the 9S12C64.

Just for reference. The solution was that there is a bug on the board
connecting TXCAN and RXCAN with about 2 Ohm (instead of infinite
resistance). We have another Megasquirt (not Microsquirt) unit where
everything works fine. I just hope that not Microsquirts have this
broken board...

Johannes
--
Johannes Schmid
High-Octane-Motorsports
Teamleiter Elektronik
j...@octanes.de
0179 / 1674917

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )