EmbeddedRelated.com
Forums

Serial Communication

Started by Jackie Johnson April 15, 2004
Good afternoon...I was wondering if anyone has a program written for
serial communication (SCI) using interrupts (would be using two
controllers - one as a transmitter and one as a receiver)?

Thanks,
Jackie



--- In , "Jackie Johnson" <fishhut@a...> wrote:
> Good afternoon...I was wondering if anyone has a program written for
> serial communication (SCI) using interrupts (would be using two
> controllers - one as a transmitter and one as a receiver)?

Look in the Theo files in the Yahoo files area, both direct and interrupt driven Serial stuff there.

It even works. Cheers, Theo


I also just ran into a need for something like SCI using ints and was
thinking of doing something like setting up a routine to send one char via
SCI_isr and the receiver would be based on receiving a char and putting it
into a circular buffer. Accessing the circular buffer with a pointer and
storing into the buffer would have to be atomic so using tpa and tap to save
CCR would be necessary when adjusting the PUT and GET pointers is concerned.
Valvano's book (University of Texas site) covers this subject very well. I
did this very thing for a msCAN program using the D60A chip and it worked
real nice... After doing a rough code for the SCI int version we decided
that the CAN module could simply that the buffer of data for the SCI_isr and
send it via the CAN bus to the receiver -- much faster than SCI, but the
idea is the same.
Sydney Faria
----- Original Message -----
From: Jackie Johnson
To:
Sent: Thursday, April 15, 2004 9:31 PM
Subject: [68HC12] Serial Communication Good afternoon...I was wondering if anyone has a program written for
serial communication (SCI) using interrupts (would be using two
controllers - one as a transmitter and one as a receiver)?

Thanks,
Jackie
--------------------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


Although it seems, on first glance, that updating a circular (ring) buffer
may need to be atomic, if you will look very carefully at how the head and
tail pointers function, you will see that it is not necessary to actually
lock interrupts or use other "atomic" techniques.

Rx buffer

The buffer head pointer is only updated by the Rx ISR. The 'main' task
never updates the head pointer.

The buffer tail pointer is only updated by the 'main' task, never by the
ISR.

If you use a semiphore to inform the main task that more data is available,
be careful when you post it. Similar logic applies to the Tx buffer.

Go open a 6-pack and think about it.

Best wishes, Bob Smith
--- Avoid computer viruses, Practice safe hex ---

-- Specializing in small, cost effective
embedded control systems --

http://www.smithmachineworks.com/embedprod.html Robert L. (Bob) Smith
Smith Machine Works, Inc.
9900 Lumlay Road
Richmond, VA 23236 804/745-1065
----- Original Message -----
From: "Sydney Faria" <>
To: <>
Sent: Saturday, April 17, 2004 10:00 AM
Subject: Re: [68HC12] Serial Communication > I also just ran into a need for something like SCI using ints and was
> thinking of doing something like setting up a routine to send one char via
> SCI_isr and the receiver would be based on receiving a char and putting it
> into a circular buffer. Accessing the circular buffer with a pointer and
> storing into the buffer would have to be atomic so using tpa and tap to
save
> CCR would be necessary when adjusting the PUT and GET pointers is
concerned.
> Valvano's book (University of Texas site) covers this subject very well.
I
> did this very thing for a msCAN program using the D60A chip and it worked
> real nice... After doing a rough code for the SCI int version we decided
> that the CAN module could simply that the buffer of data for the SCI_isr
and
> send it via the CAN bus to the receiver -- much faster than SCI, but the
> idea is the same.
> Sydney Faria
> ----- Original Message -----
> From: Jackie Johnson
> To:
> Sent: Thursday, April 15, 2004 9:31 PM
> Subject: [68HC12] Serial Communication > Good afternoon...I was wondering if anyone has a program written for
> serial communication (SCI) using interrupts (would be using two
> controllers - one as a transmitter and one as a receiver)?
>
> Thanks,
> Jackie >
> --------------------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 >
>
> --------------------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

>
>



--- In , "Bob Smith" <bobsmith5@v...> wrote:
> Although it seems, on first glance, that updating a circular (ring) buffer
> may need to be atomic, if you will look very carefully at how the

Excuse my ignorance Bob, but I seem to miss something, "atomic" in my mind is associated with interrupts that can occur in the middle of an instruction cycle, say a DMA event that occurs on a clock boundary thereby leaving the current instruction partially completed.

Does something like this occur in the Motorola devices?

Regards,

Theo



Well, I am using the CAN interrupts to 'produce' the messages in the
circular queue and the rest of the program is 'consume' the circular queue,
effectively I have two threads of execution and shared resources have to be
atomic or I will have corrupt 'put' and 'get' pointers to the queue. I use
the 'put' and 'get' to update the common variable, NEWMSGS, which is used by
the 'get' to keep accessing the queue until there are no more messages, so,
since both 'put' and 'get' both access NEWMSGS, all access to NEWMSGS must
be atomic: if I did not do this then there always is the possibility of
corrupting NEWMSGS via the producer-consumer problem from operating system
theory. At least that's what I thought was the case when we were looking at
threads. All I am really doing is implementing threads in this micro
controller by using these atomic access methods.
Sydney
----- Original Message -----
From: theobee00
To:
Sent: Saturday, April 17, 2004 2:05 PM
Subject: [68HC12] Re: Serial Communication --- In , "Bob Smith" <bobsmith5@v...> wrote:
> Although it seems, on first glance, that updating a circular (ring)
buffer
> may need to be atomic, if you will look very carefully at how the

Excuse my ignorance Bob, but I seem to miss something, "atomic" in my mind
is associated with interrupts that can occur in the middle of an instruction
cycle, say a DMA event that occurs on a clock boundary thereby leaving the
current instruction partially completed.

Does something like this occur in the Motorola devices?

Regards,

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



--- In , "Sydney Faria" <n1huq@h...> wrote:
> Well, I am using the CAN interrupts to 'produce' the messages in the
> circular queue and the rest of the program is 'consume' the circular queue,
> effectively I have two threads of execution and shared resources have to be
> atomic or I will have corrupt 'put' and 'get' pointers to the queue.

Ah, is that what you mean, similar to bit operations on a port where interrupts can occur acting on the same port.

The traditional method is (was?) to disable interupts during such updates, making it "Atomic", in your case until the pointers are updated.

Although with circular buffers I would have thought the read and write are independent, i.e. the producer only needs to know free space, and the consumer if char is available.

As long as main program gets char first before updating the pointer that should be interruptable, and the interrupt would have to drop the char anyway if there is no space.

Ah well, back to the grind, I am busy updating some scaling routines and my 32 bit division routine run out of steam, am now busy dividing and multiplying the variables to retain some semblance of accuracy.
Don't think there is enough time for floating point, maybe see if there's a ready made 40 bit one in the libraries, aargh.

At least with this chip I have enough resources to have a few separate routines if need be, the 6303 memory was overlaid up to five times to save a few RAM locations, what a tangle.

Cheers, Theo



At 11:05 AM 4/17/04, you wrote:
>--- In , "Bob Smith" <bobsmith5@v...> wrote:
> > Although it seems, on first glance, that updating a circular (ring) buffer
> > may need to be atomic, if you will look very carefully at how the
>
>Excuse my ignorance Bob, but I seem to miss something, "atomic" in my mind
>is associated with interrupts that can occur in the middle of an
>instruction cycle, say a DMA event that occurs on a clock boundary thereby
>leaving the current instruction partially completed.
>
>Does something like this occur in the Motorola devices?


No, Motorola processors never break into the middle of any instruction for
any reason. 68HC12s don't have DMA.

Gary Olmstead
Toucan Technology
Ventura CA



At 02:02 PM 4/18/04, you wrote:

>Although with circular buffers I would have thought the read and write are
>independent, i.e. the producer only needs to know free space, and the
>consumer if char is available.


Normally yes, but if I read it right, he has one variable to handle both
"in" and "out".

Gary Olmstead
Toucan Technology
Ventura CA



At 05:31 PM 4/18/2004 -0700, you wrote:
>At 11:05 AM 4/17/04, you wrote:
> >--- In , "Bob Smith" <bobsmith5@v...> wrote:
> > > Although it seems, on first glance, that updating a circular (ring) buffer
> > > may need to be atomic, if you will look very carefully at how the
> >
> >Excuse my ignorance Bob, but I seem to miss something, "atomic" in my mind
> >is associated with interrupts that can occur in the middle of an
> >instruction cycle, say a DMA event that occurs on a clock boundary thereby
> >leaving the current instruction partially completed.
> >
> >Does something like this occur in the Motorola devices? >No, Motorola processors never break into the middle of any instruction for
>any reason. 68HC12s don't have DMA.

Actually, the HC12 was the first of the Moto microcontrollers where there *was* a possibility of interrupting an instruction, at least one of a very few instructions. From the CPU12 reference manual

"When an interrupt service request is recognized, the CPU responds at the
completion of the instruction being executed. Interrupt latency varies according to the
number of cycles required to complete the current instruction. Because the REV,
REVW and WAV instructions can take many cycles to complete, they are designed so
that they can be interrupted. Instruction execution resumes when interrupt execution
is complete."

So, those 3 instructions are interruptable, but the balance of the instructions are not.

ed
--