1
\$\begingroup\$

I want to receive 5-bit serial words using a microcontroller's hardware UART at 45 Baud. This is the basic protocol for teletype machines. Since the baud rate is 45, I really want this done in hardware so that I am not spending all the processor time polling a pin, and for ease of programming.

Are there microcontrollers that can do 5-bit serial data in hardware? Is there a reasonable hardware/software implementation that won't tie up the processor?

\$\endgroup\$
0

5 Answers 5

8
\$\begingroup\$

If you have sufficient intercharacter space (~3 extra stop bits), you could use the MCU UART port, as there isn't really a difference between an 8-bit character (0x00 through 0x1F) on a UART and a 5-bit character with 4 stop bits.

Barring that, your best bet would be to use a level interrupt (pin change, etc) to detect the leading edge of the start bit, then configure a timer to interrupt you either once per bit or possibly a couple times so you can do some extra verification. 45 baud is really slow, so unless you're using upwards of 95% of the MCU time (or all it's peripherals), this shouldn't cause any problems.

The Atmel AVR USART module supports 5-9 bit modes, so any (newer) ATtiny (e.g. ATtiny2313) or ATmega (e.g. ATmega328P) will allow you to do this in hardware, vastly simplifying your software, saving your time.

The maximum clock divider you can apply to the UART on an AVR is 216, so if you have a clock of 16 MHz, the lowest rate it can run at is 244 bps with no system clock divider. If you use an ATmega, like on an Arduino, the clock prescale register (CLKPR, §8.12.2 in Atmega48/88/168/328 datasheet) can be used to slow down the system clock up to 256x at run-time, or simply program the CKDIV8 fuse to set the prescale register's default to 8.

The real determining factor on what you should use is what else you're doing besides talking with the TTY. If you are going to plug this into a computer, you will want to reserve a (or the, if there's only 1) UART for communicating with the PC and do a software UART if required (as mentioned by everyone, this is near trivial at 45 bps). If you want to press a button and have the TTY do something, using the only UART for that would be fine.

\$\endgroup\$
4
  • \$\begingroup\$ @vicatcu, I think it is a great answer, which is +1, why choose because they use a microcontroller you like, who cares, many micros will live and die before your career is finished. \$\endgroup\$
    – Kortuk
    Commented Dec 21, 2010 at 17:30
  • \$\begingroup\$ @Kortuk, I agree - forgive my bigotry :) \$\endgroup\$
    – vicatcu
    Commented Dec 21, 2010 at 17:33
  • 1
    \$\begingroup\$ @vicatcu, just thought I would drop a note, I think many people vote on the micro they use because they are happy others use it. The fact that you say it out loud means you recognize your bigotry and are coping with it. We can avoid the intervention for now. \$\endgroup\$
    – Kortuk
    Commented Dec 21, 2010 at 17:39
  • \$\begingroup\$ you worked for the answer credit here, 2 edits to keep adding things you found. well done. \$\endgroup\$
    – Kortuk
    Commented Dec 21, 2010 at 19:29
3
\$\begingroup\$

The first three datasheets I looked at all show support for 5 bit serial communication. Here is the list:

\$\endgroup\$
1
  • \$\begingroup\$ Coincidentally, the first 3 datasheets/families I looked at don't. Microchip 16-18F, 8051, and MSP430 processors don't support 5-bit fields. \$\endgroup\$
    – W5VO
    Commented Dec 21, 2010 at 17:11
2
\$\begingroup\$

You will probably have to bit-bang the interface. Any MCU will be suitable.

\$\endgroup\$
2
  • \$\begingroup\$ Agree you do not need to do this in hardware. 45 baud is 22 ms per bit, so this is a simple task for any modern micro. \$\endgroup\$
    – tcrosley
    Commented Dec 21, 2010 at 15:43
  • 3
    \$\begingroup\$ it's always easier to load a buffer, set a flag and let hardware tell you when it's done (in the case of transmit)... or to let hardware tell you there is something new to deal with (in the case of receive) \$\endgroup\$
    – vicatcu
    Commented Dec 21, 2010 at 16:51
2
\$\begingroup\$

For normal asynchronous operation on the ATTiny2313 AVR, lets say running at 1.8432MHz set:

UBRR  = 0x9FF; //(f_osc / (16 * BAUD)) - 1 = 2559 =
UCSRA = 0x00;  // 1x trasnmit speed, multi-processor mode disabled
UCSRB = 0xD8;  // enable rx and tx complete interrupts, enable tx and rx hardware
UCSRC = 0x00;  // 5 data-bits, 1 stop-bit, no parity bits

Then implement the RX and TX complete interrupts and you should be good to go.

\$\endgroup\$
0
\$\begingroup\$

Looking at the datasheet: LPC17xx has support for 5 Bit data.

SiLabs 80C51F0XX has only 8 and 9 bit.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.