Interrupt driven MsCan bus

Started by Paul Johnson August 12, 2002
Hi All,

All of the examples I have seen using the CAN bus with the HC12 line uses
simple polling. Is anyone aware of an example using interrupts? Has anyone
out there used interrupts themselves?

On a related note, all of the examples use only one of the output registers,
but in an interrupt routine I would assume that you would use any open
register, no? Does anyone have any experience with this?

Thanks,

Paul



Hi,
I always use Rx and Tx interrupts for msCAN.
I never used polling except for synchronization.
Regards,
Venu

@interrupt void CANRxhandler(void) // CAN Receive interrupt handler
{
char Filter; // temprory variable
CH_INT CAN_RxBuff; // temp variable for CAN ID storage
CAN_RxBuff.INT = RBUF[0] << 8 | RBUF[1];// save CAN ID from
Rx buffers
CANid = ((CAN_RxBuff.INT & CAN_ID_MASK_2A) >> 5);// allign ID
bits
Filter = CIDAC & 0x0F; // get filter value
if(Filter == 0x01) // filter 1
{
switch(CANid)
{
case 0: // ID - 700
CanDaqBusy(); // CAN-DAQ busy message
break;
case 1: // ID - 701
CanDaqReady(); // CAN-DAQ ready message
break;
case 2: // ID - 702
EnableIntDaq(); // Enable Internal Data acquisition
break;
}
}
if(Filter == 0x02) // filter 2
{
// your code
}
if(Filter == 0x03) // filter 3
{
// your code
}
CRFLG = RXF; // clear RXF flag
}

--- In 68HC12@y..., "Paul Johnson" <paul@l...> wrote:
> Hi All,
>
> All of the examples I have seen using the CAN bus with the HC12
line uses
> simple polling. Is anyone aware of an example using interrupts?
Has anyone
> out there used interrupts themselves?
>
> On a related note, all of the examples use only one of the output
registers,
> but in an interrupt routine I would assume that you would use any
open
> register, no? Does anyone have any experience with this?
>
> Thanks,
>
> Paul





Hi Venu,

Thanks for this example, it's very helpful. You made one comment that
intrigues me when you talked about using polling for synchronization.

Do I understand that to mean that you wake up with interrupts off, us
polling on all devices to establish who's out there, etc., then switch to
interrupt mode? Is this related to the SYNCH bit in the CMCR0 register? I
do not really know how to use this bit. Sometimes, if I wait for it to go
high, it never does. If I just ignore it polling seems to work anyway.
Sometimes if I wait for it to go hi it does. I have not been able to
determine what makes this bit change.

If you have some pointer on synchronization, I would be most appreciative.

Thanks,

Paul

> -----Original Message-----
> From: kp_venu [mailto:]
> Sent: Monday, August 12, 2002 9:19 PM
> To:
> Subject: [68HC12] Re: Interrupt driven MsCan bus > Hi,
> I always use Rx and Tx interrupts for msCAN.
> I never used polling except for synchronization.
> Regards,
> Venu
>
> @interrupt void CANRxhandler(void) // CAN Receive interrupt handler
> {
> char Filter; // temprory variable
> CH_INT CAN_RxBuff; // temp variable for CAN ID storage
> CAN_RxBuff.INT = RBUF[0] << 8 | RBUF[1];// save CAN ID from
> Rx buffers
> CANid = ((CAN_RxBuff.INT & CAN_ID_MASK_2A) >> 5);// allign ID
> bits
> Filter = CIDAC & 0x0F; // get filter value
> if(Filter == 0x01) // filter 1
> {
> switch(CANid)
> {
> case 0: // ID - 700
> CanDaqBusy(); // CAN-DAQ busy message
> break;
> case 1: // ID - 701
> CanDaqReady(); // CAN-DAQ ready message
> break;
> case 2: // ID - 702
> EnableIntDaq(); // Enable Internal Data acquisition
> break;
> }
> }
> if(Filter == 0x02) // filter 2
> {
> // your code
> }
> if(Filter == 0x03) // filter 3
> {
> // your code
> }
> CRFLG = RXF; // clear RXF flag
> }
>
> --- In 68HC12@y..., "Paul Johnson" <paul@l...> wrote:
> > Hi All,
> >
> > All of the examples I have seen using the CAN bus with the HC12
> line uses
> > simple polling. Is anyone aware of an example using interrupts?
> Has anyone
> > out there used interrupts themselves?
> >
> > On a related note, all of the examples use only one of the output
> registers,
> > but in an interrupt routine I would assume that you would use any
> open
> > register, no? Does anyone have any experience with this?
> >
> > Thanks,
> >
> > Paul >
> -------------------- >
> ">http://docs.yahoo.com/info/terms/ >





Paul,
Yes. It's related to SYNCH bit in CMCR0 register.
Synchronisation is done at end of initialisation routine.
Regards,
Venu
void CanInit(void) // CAN initialisation routine
{
CMCR0 |= SFTRES; // place MSCAN12 in soft reset mode

// CMCR1 = 1; // MSCAN12 clock = 2(ECLK)
// 250kbps = 0xC3, 500kpbs =
0xC1;
CBTR0 = BTR0; // Synchronisation jump width = 4Tq clock
cycles
// SJW1,SJw0 = 11 = C0h
// Baud rate =
500Kbs,prescaler=4 0011 = 03h
CBTR1 = BTR1; // SAMP = 0; one sample per bit
// Time Segment 1 = 10Tq
clock cycles = 1001= 9h
// Time segment 2 = 5 Tq
clock cycles = 0100= 4h
CTCR = 0; // clear transmitt control register

CIDAC = 0x17; // four 16-bit Acceptance Filters

FilterConfig(); // Acceptance Filter configuarion for PM-ECU
// located in ECU Configuration file
CMCR0 &= ~(SFTRES); // take MSCAN12 out of soft reset
CRFLG = 0xFF; // Clear all CAN error flags
CRIER = BOFFIE | OVRIE | RXFIE; // Enable interrupts for
Error and receive flags
while(!(CMCR0 & SYNCH)){}; //wait for synchronisation with
CAN bus
}

--- In 68HC12@y..., "Paul Johnson" <paul@l...> wrote:
> Hi Venu,
>
> Thanks for this example, it's very helpful. You made one comment
that
> intrigues me when you talked about using polling for
synchronization.
>
> Do I understand that to mean that you wake up with interrupts off,
us
> polling on all devices to establish who's out there, etc., then
switch to
> interrupt mode? Is this related to the SYNCH bit in the CMCR0
register? I
> do not really know how to use this bit. Sometimes, if I wait for
it to go
> high, it never does. If I just ignore it polling seems to work
anyway.
> Sometimes if I wait for it to go hi it does. I have not been able
to
> determine what makes this bit change.
>
> If you have some pointer on synchronization, I would be most
appreciative.
>
> Thanks,
>
> Paul
>
> > -----Original Message-----
> > From: kp_venu [mailto:kp_venu@y...]
> > Sent: Monday, August 12, 2002 9:19 PM
> > To: 68HC12@y...
> > Subject: [68HC12] Re: Interrupt driven MsCan bus
> >
> >
> > Hi,
> > I always use Rx and Tx interrupts for msCAN.
> > I never used polling except for synchronization.
> > Regards,
> > Venu
> >
> > @interrupt void CANRxhandler(void) // CAN Receive interrupt
handler
> > {
> > char Filter; // temprory variable
> > CH_INT CAN_RxBuff; // temp variable for CAN ID storage
> > CAN_RxBuff.INT = RBUF[0] << 8 | RBUF[1];// save CAN ID from
> > Rx buffers
> > CANid = ((CAN_RxBuff.INT & CAN_ID_MASK_2A) >> 5);// allign ID
> > bits
> > Filter = CIDAC & 0x0F; // get filter value
> > if(Filter == 0x01) // filter 1
> > {
> > switch(CANid)
> > {
> > case 0: // ID - 700
> > CanDaqBusy(); // CAN-DAQ busy message
> > break;
> > case 1: // ID - 701
> > CanDaqReady(); // CAN-DAQ ready message
> > break;
> > case 2: // ID - 702
> > EnableIntDaq(); // Enable Internal Data acquisition
> > break;
> > }
> > }
> > if(Filter == 0x02) // filter 2
> > {
> > // your code
> > }
> > if(Filter == 0x03) // filter 3
> > {
> > // your code
> > }
> > CRFLG = RXF; // clear RXF flag
> > }
> >
> > --- In 68HC12@y..., "Paul Johnson" <paul@l...> wrote:
> > > Hi All,
> > >
> > > All of the examples I have seen using the CAN bus with the HC12
> > line uses
> > > simple polling. Is anyone aware of an example using interrupts?
> > Has anyone
> > > out there used interrupts themselves?
> > >
> > > On a related note, all of the examples use only one of the
output
> > registers,
> > > but in an interrupt routine I would assume that you would use
any
> > open
> > > register, no? Does anyone have any experience with this?
> > >
> > > Thanks,
> > >
> > > Paul
> >
> >
> >
> > --------------------
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >





Venu,

You have been very generous with your information. Thank you very much.

I have two more quick questions.

1. What compiler are you using? I don't recognize the @interrupt form from
either HIWARE or ICC12.

2. In you transmit interrupt, do you use all three output buffers or just
the first one? I assume that transmission would be much more efficient if
all three buffers are used.

Thanks again for the great kick-start.

Best regards,

Paul

> -----Original Message-----
> From: kp_venu [mailto:]
> Sent: Tuesday, August 13, 2002 8:37 PM
> To:
> Subject: [68HC12] Re: Interrupt driven MsCan bus > Paul,
> Yes. It's related to SYNCH bit in CMCR0 register.
> Synchronisation is done at end of initialisation routine.
> Regards,
> Venu
> void CanInit(void) // CAN initialisation routine
> {
> CMCR0 |= SFTRES; // place MSCAN12 in soft reset mode
>
> // CMCR1 = 1; // MSCAN12 clock = 2(ECLK)
> // 250kbps = 0xC3, 500kpbs =
> 0xC1;
> CBTR0 = BTR0; // Synchronisation jump width = 4Tq clock
> cycles
> // SJW1,SJw0 = 11 = C0h
> // Baud rate =
> 500Kbs,prescaler=4 0011 = 03h
> CBTR1 = BTR1; // SAMP = 0; one sample per bit
> // Time Segment 1 = 10Tq
> clock cycles = 1001= 9h
> // Time segment 2 = 5 Tq
> clock cycles = 0100= 4h
> CTCR = 0; // clear transmitt control register
>
> CIDAC = 0x17; // four 16-bit Acceptance Filters
>
> FilterConfig(); // Acceptance Filter configuarion for PM-ECU
> // located in ECU Configuration file
> CMCR0 &= ~(SFTRES); // take MSCAN12 out of soft reset
> CRFLG = 0xFF; // Clear all CAN error flags
> CRIER = BOFFIE | OVRIE | RXFIE; // Enable interrupts for
> Error and receive flags
> while(!(CMCR0 & SYNCH)){}; //wait for synchronisation with
> CAN bus
> }
>





Hi!

Hiware interrupts:

a vector definition in prm-file

VECTOR ADDRESS 0xffc6 Can_RxIntHandler /* MSCAN 0 Receive */ and a handler function (use '#pragma TRAP_PROC' instead of '@interrupt')

#pragma TRAP_PROC
void CANRxIntHandler()
{
...
}

JK

-----Original Message-----
From: Paul Johnson [mailto:]
Sent: 13. elokuuta 2002 0:53
To:
Subject: [68HC12] Interrupt driven MsCan bus Hi All,

All of the examples I have seen using the CAN bus with the HC12 line uses
simple polling. Is anyone aware of an example using interrupts? Has anyone
out there used interrupts themselves?

On a related note, all of the examples use only one of the output registers,
but in an interrupt routine I would assume that you would use any open
register, no? Does anyone have any experience with this?

Thanks,

Paul
--------------------
">http://docs.yahoo.com/info/terms/


Paul,
I'm using COSMIC compiler(an excellent one).
For ICC12,
#pragma interrupt_handler MyInterrupthandler
no idea about HIWARE.
I use Tx interrupt for Internal Data acqusition of h/w with Tx1 and
Tx2 and other messages will use Tx0 (without any Tx interrupt).
Regards,
Venu

--- In 68HC12@y..., "Paul Johnson" <paul@l...> wrote:
> Venu,
>
> You have been very generous with your information. Thank you very
much.
>
> I have two more quick questions.
>
> 1. What compiler are you using? I don't recognize the @interrupt
form from
> either HIWARE or ICC12.
>
> 2. In you transmit interrupt, do you use all three output buffers
or just
> the first one? I assume that transmission would be much more
efficient if
> all three buffers are used.
>
> Thanks again for the great kick-start.
>
> Best regards,
>
> Paul
>





about 1):
to mark as interrupt, you can use for HIWARE/Metrowerks either a pragma or the interrupt keyword:
#pragma TRAP_PROC
void myISR(void) {....
or
interrupt void MyISR(void) {...

optionally you can specify the vector number with the interrupt keyword (so you do not need to
adapt/edit the linker command file:

interrupt 0 void MyResetISR(void) {...

Erich

> -----Original Message-----
> From: Paul Johnson [mailto:]
> Sent: Thursday, August 15, 2002 7:36 PM
> To:
> Subject: RE: [68HC12] Re: Interrupt driven MsCan bus > Venu,
>
> You have been very generous with your information. Thank you very much.
>
> I have two more quick questions.
>
> 1. What compiler are you using? I don't recognize the @interrupt form from
> either HIWARE or ICC12.
>
> 2. In you transmit interrupt, do you use all three output buffers or just
> the first one? I assume that transmission would be much more efficient if
> all three buffers are used.
>
> Thanks again for the great kick-start.
>
> Best regards,
>
> Paul
>
> > -----Original Message-----
> > From: kp_venu [mailto:]
> > Sent: Tuesday, August 13, 2002 8:37 PM
> > To:
> > Subject: [68HC12] Re: Interrupt driven MsCan bus
> >
> >
> > Paul,
> > Yes. It's related to SYNCH bit in CMCR0 register.
> > Synchronisation is done at end of initialisation routine.
> > Regards,
> > Venu
> > void CanInit(void) // CAN initialisation routine
> > {
> > CMCR0 |= SFTRES; // place MSCAN12 in soft reset mode
> >
> > // CMCR1 = 1; // MSCAN12 clock = 2(ECLK)
> > // 250kbps = 0xC3, 500kpbs =
> > 0xC1;
> > CBTR0 = BTR0; // Synchronisation jump width = 4Tq clock
> > cycles
> > // SJW1,SJw0 = 11 = C0h
> > // Baud rate =
> > 500Kbs,prescaler=4 0011 = 03h
> > CBTR1 = BTR1; // SAMP = 0; one sample per bit
> > // Time Segment 1 = 10Tq
> > clock cycles = 1001= 9h
> > // Time segment 2 = 5 Tq
> > clock cycles = 0100= 4h
> > CTCR = 0; // clear transmitt control register
> >
> > CIDAC = 0x17; // four 16-bit Acceptance Filters
> >
> > FilterConfig(); // Acceptance Filter configuarion for PM-ECU
> > // located in ECU Configuration file
> > CMCR0 &= ~(SFTRES); // take MSCAN12 out of soft reset
> > CRFLG = 0xFF; // Clear all CAN error flags
> > CRIER = BOFFIE | OVRIE | RXFIE; // Enable interrupts for
> > Error and receive flags
> > while(!(CMCR0 & SYNCH)){}; //wait for synchronisation with
> > CAN bus
> > }
> >
> -------------------- >
> ">http://docs.yahoo.com/info/terms/



Hi Venu,

> I'm using COSMIC compiler(an excellent one).
> For ICC12

Good to know. I have used both ICC12 and Metrowerks (which I am using now),
so I am familiar with their standards for interrupts.

> I use Tx interrupt for Internal Data acqusition of h/w with Tx1 and
> Tx2 and other messages will use Tx0 (without any Tx interrupt).

Reserving one register for non-interrupt messages is a good idea. In the
past (with serial buses) I have used a message queuing scheme with priority
bits to assure that time-critical messages get sent first. It works well,
but in high bandwidth situations it's possible that the low priority message
may wait a long time. Of course, depending on the priority of the Tx0
message, the CAN controller might hold it for quite a while in a similar
situation. I look forward to playing with these ideas.

Thanks again for your very generous assistance.

Regards,

Paul