Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

How to implement 6 UART Serial Connections using Atmega128

How to implement 6 UART Serial Connections using Atmega128

2004-02-03 by suri_list

We have to implement 6 serial connections to 6 modules from each 
module. we are going to use the atmega128 on each module.

The atmega128 has 2 uarts so i can implement 2 simultaneous uarts.
It is preferable not to have any external components (we have to keep 
footprint small) , so i want to do everything with the atmega128.

-- But what abt the other 4. Will I have to bit bang the rest of the 
4 using a software routine uart?

-- Any other interesting solution which will allow me to use timers 
or something so that the cpu doesnt have to be busy doing the serial 
commn

RE: [AVR-Chat] How to implement 6 UART Serial Connections using Atmega128

2004-02-04 by Pearless

Hi,

We had a similar requirement where we need the ATMEga128 to have a total of 6 UARTS.

Unless your speed requirements are very low, and your processor requirements outside of your software UARTS is not very high, I would recommend that you go for a hardware option, otherwise you may spent a lot of processor time on watching you software serial UARTS.

We have chosen the Oxford Semiconductor (http://www.oxsemi.co.uk/pages/uarts/index.html ) OX16C954 chip as it also has 128 byte transmit and 128 byte receive buffers per UART, does RS485 half and full duplex, full hardware RS232, IrDA, and much more. The chip is roughly the same size as ATMega128. (I have absolutely NO connection with that company)

We will be releasing the hardware and software under GPL for the Ethernut processor (refer to www.ethernut.de ) in the next month or so.

You may well be able to graft the hardware onto your design.

Cheers Douglas

From: suri_list [mailto:suri_list@yahoo.com]
Sent: Wednesday, 4 February 2004 10:52 a.m.
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] How to implement 6 UART Serial Connections using Atmega128

We have to implement 6 serial connections to 6 modules from each
module. we are going to use the atmega128 on each module.

The atmega128 has 2 uarts so i can implement 2 simultaneous uarts.
It is preferable not to have any external components (we have to keep
footprint small) , so i want to do everything with the atmega128.

-- But what abt the other 4. Will I have to bit bang the rest of the
4 using a software routine uart?

-- Any other interesting solution which will allow me to use timers
or something so that the cpu doesnt have to be busy doing the serial
commn








Yahoo! Groups Links


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 30/01/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 30/01/2004

Re: [AVR-Chat] How to implement 6 UART Serial Connections using Atmega128

2004-02-04 by Wagner Lipnharski

suri_list wrote:
> We have to implement 6 serial connections to 6 modules from each
> module. we are going to use the atmega128 on each module.
>
> The atmega128 has 2 uarts so i can implement 2 simultaneous uarts.
> It is preferable not to have any external components (we have to keep
> footprint small) , so i want to do everything with the atmega128.
>
> -- But what abt the other 4. Will I have to bit bang the rest of the
> 4 using a software routine uart?
>
> -- Any other interesting solution which will allow me to use timers
> or something so that the cpu doesnt have to be busy doing the serial
> commn


What will be the serial data rate on all the 6 ports, mostly the 4 to be
done by software (bit-bang)?

Doing multi-bit-bang software routines is not that difficult, mostly to
transmit, and mostly if all use the same data rate.

Lets say that all should use 9600bps, so that is the frequency you should
use at some timer causing an interrupt.

Forget the existant UARTs in the chip for a while. Lets concentrate at the
bit-bang transmission routine.

You allocate 4 register or sram variables to hold the data to be
transmitted, lets call them TBR1 to TBR4 (Transmission Buffer Register),
another 4 bariables TR1 to TR4 (transmission register) another 4 variables
as a flag, TF1 to TF4.  Another 4 variables, TRC1-4 are the counter for bits
transfered. At reset all variables at set to zero.

The TBR1-4 will hold the byte TO BE transmitted, and this is where your
application software writes such byte.  It is a Transmission Buffer.

The TR1-4 are actually the place where bits are rolled out being
transmitted, so the transmission software-uart works on those.

The TRC1-4 are the transmission bit counter.

The TF1-4 are the flag bytes, they holds two kind of information.  Value $01
means TBR is busy holding the next byte to be transmitted, $00 means that
byte was already copied to TR and TBR is free to receive the next byte to be
transmitted.

Lets reffer to them as TFx, TRx, TRCx TBRx

Whenever your software wants to transmit something at UARTx, it should first
check the value of the correspondent TFx (Flag), if different from zero, the
buffer is not available, it is holding the next byte to be transmitted, so
the software waits.  If it is zero, it means the buffer is empty so it can
writes the transmission data byte to TBRx (Transmission Buffer - TO BE
transmitted), and set TFx to $01, meaning the buffer is holding a new byte
to be transmitted.

The 9600Hz interrupt timer routine, at every interrupt, will scan first
check the TRCx bytes, one at time. If the TRCx contains $00 it means the
last (if ever) byte in TRx was already done, nothing should be transmitted,
and in this case, it needs to se if a new byte should be transmitted,
looking at TFx, if TFx is zero, then that particular UARTx has nothing to
transmit, so it moves to the next UARTx set of registers and do it for all
of them.  IF TRCx contains $00 and TFx contains $01, it means a new byte is
available to be transmitted at TRBx, so it copies TRBx contents to TRx, set
TRCx to $0A and clear TFx, freeing the buffer, and skip to the next UARTx.

During the 9600Hz interrupt timer routine, if the TRCx is different from
zero, it does this:

If it is $0A, send the START pulse (sets UARTx TX pin high), decrement TRCx
and go to next UARTx.
If TRCx is higher than 1 and lower than $0A, it shifts left TRx and moves
the Carry bit to the correspondent UARTx TX pin. Decrement TRCx and go to
next UARTx.
If TRCx is 1, it is the stop bit, so sets zero to the UARTx TX pin.
Decrement TRCx (to zero).

This does all the transmission job, for as many UARTs you need.

==========

The receiver part is a little picky, since it requires a faster sampling of
the incoming serial data.
The idea is to run another timer routine running at least 4 to 5 times
faster than the incoming speed.
So, planning to build  9600 serial ports, it will be wise to produce this
timer interrupt running at 48kHz.
It uses a similar approach for the transmitter, a receiv"ing" buffer, a 10
bits counter, a receiv"ed" buffer and a flag, for each of the UARTx.

At every 48kHz interrupt, it checks if the flag shows a byte actually under
reception, if not, it just observes the RXx pin, if it is down, nothing is
happening, if suddently it appears up, the start bit is comming, so it sets
the bits counter to 47.  Why 47?  Remember that this timer is running 5
times faster than the incomming bits, and that it is possible that the Start
bit arised in between the last reading and this one, so it is possible one
5x clock period was lost, no problem. Remember that to sample the incoming
data bits, it is wise to do it in middle of the actual incoming bit time, so
the 8 next bits to receive (actually data bits) times 5 is 40 interrupts,
plus the half bit, plus the whole start bit, adds 9.5 x 5 = 47.5, leaves as
47.  Then, at every of this 48kHz interrupt, the sub-RX-UARTx routine checks
if each counter is lower than 41 and above 5. If it is, a byte is under
reception, so it checks if the counter is a round multiple of 5, like 5, 10,
15... up to 40. If it is, then the UARTx RX pin is SHIFTED LEFT into the
correspondent receiv"ing" register.  In any case, counter above zero, it is
decremented by one.  When the counter reaches a value below 5 but not zero,
the receiv"ing" register is copied to receiv"ed" register and the flag is
seto to 1, indicating a valid received byte available at receiv"ed"
register.  When counter = 0, nothing is done.

It seems that reception is harder, but nothing at all.

A 48kHz interrupt timer routine can handle almost 160 instructions if clock
is 8MHz, fairly easy to deal up to 8 UARTs RX and TX.

An extra counter could decrement a counter from 5 and reset it to 5 when
zero, for each time this interrupt happens.  Whenever the counter reaches
zero, it can launches the transmission routine above, so you don't need to
have two timers running.  Of course, it consider 48kHz to be 5x the UARTs
speed of 9600bps, and all run at the same speed.

This routines are so nice, that I would use the required 6 UARTs by
software, leave the hardware uarts alone... :)))  To increase from 4 to 6,
it is just a matter of more 16 variable bytes and extend the interrupt
routines a little.

Wagner Lipnharski - email:  wagner@ustr.net
UST Research Inc. - Development Director
http://www.ustr.net - Orlando Florida 32837
Licensed Consultant Atmel AVR _/_/_/_/_/_/

RE: [AVR-Chat] How to implement 6 UART Serial Connections using Atmega128

2004-02-04 by JoeT

I have done four ports on a ATmega16. It has one hardware uart. This was
done in Basic (BASCOM). And it works well. Maybe this will help.

At the start:

''''''''''''''''''''''''''''''
' Open com ports
''''''''''''''''''''''''''''''
'open portD.4 for output to HOPTO
Open "comd.4:9600,8,n,1" For Output As #1

'open portD.5 for input from Hopto
Open "comd.5:9600,8,n,1" For Input As #2

'open portD.6 for output To Particle Counter
Open "comd.6:9600,8,n,1" For Output As #3

'open portD.7 for input from Particle Counter
Open "comd.7:9600,8,n,1" For Input As #4

'open portC.2 for output to Hand Held
Open "comc.2:9600,8,n,1" For Output As #5

'open portC. for input from HandHeld
Open "comc.3:9600,8,n,1" For Input As #6


I then just print to the port numbers ie.

Print "Hello"  ' output to hardware uart
Print #1, "Hello"   ' would output to software port 1
waitkey(#2)  ' would wait for input


And at the end.

'''''''''''''''''''''''
'  close com ports
'''''''''''''''''''''''
Close #1
Close #2
Close #3
Close #4
Close #5
Close #6


JoeT


-----Original Message-----
From: Wagner Lipnharski [mailto:wagner@ustr.net]
Sent: Wednesday, February 04, 2004 11:36 AM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] How to implement 6 UART Serial Connections using
Atmega128


suri_list wrote:
Show quoted textHide quoted text
> We have to implement 6 serial connections to 6 modules from each
> module. we are going to use the atmega128 on each module.
>
> The atmega128 has 2 uarts so i can implement 2 simultaneous uarts.
> It is preferable not to have any external components (we have to keep
> footprint small) , so i want to do everything with the atmega128.
>
> -- But what abt the other 4. Will I have to bit bang the rest of the
> 4 using a software routine uart?
>
> -- Any other interesting solution which will allow me to use timers
> or something so that the cpu doesnt have to be busy doing the serial
> commn

ATMega128 SPI

2004-02-05 by harshit suri

Hello

From the manual of ATMEGA128 i gather that general
purpose IO can be used as as SS (Slave Select pin). 

I only see one dedicated SS pin = pin 10 (PB0) in the
data sheet. 

--How does the SPI module know which are the other SS
Pins that i have connected as SS to the slaves?

--So does this mean that the CPU has to be involved in
a multi slave situation. as it shall have to pull the
SS for the slaves low ? 

--How many slaves can i connect to a single Atmega128?

--What is the maximum bit rate of communication
assuming that i am using a 16Mhz Xtal?

Thankyou


__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

Re: [AVR-Chat] ATMega128 SPI

2004-02-05 by Dave VanHorn

At 08:54 PM 2/4/2004 -0800, harshit suri wrote:
>Hello
>
> From the manual of ATMEGA128 i gather that general
>purpose IO can be used as as SS (Slave Select pin).
>
>I only see one dedicated SS pin = pin 10 (PB0) in the
>data sheet.

The SPI hardware on the 128 can only "see" that pin.
However you can use any other GPIO pin to signal to the other chip(s).


>--How does the SPI module know which are the other SS
>Pins that i have connected as SS to the slaves?

It dosen't.

>--So does this mean that the CPU has to be involved in
>a multi slave situation. as it shall have to pull the
>SS for the slaves low ?

There has to be one SS for each slave.
If you have five slaves, then you'll need to signal each of them, by 
pulling it's SS low, that "I'm talking to YOU".


>--How many slaves can i connect to a single Atmega128?

How big is your circuit board?  How high is up?

>--What is the maximum bit rate of communication
>assuming that i am using a 16Mhz Xtal?

See data sheet, Clock / 4 would be 4 MHz
If you enable the double speed mode, then 8 MHz.

The question really is: How fast can your slaves receive?
Show quoted textHide quoted text
>Thankyou
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! Finance: Get your refund fast by filing online.
>http://taxes.yahoo.com/filing.html
>
>
>
>
>Yahoo! Groups Links
>
>
>
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.