Erlen Primer · all experiments

Electrical · Digital · Investigate

Read a serial line by hand

The terminal shows rubbish where the board sends READY. Why, and what does the board actually send?

Read a serial line by hand: the bench

The bench

A board sends one line a second on its TX wire: READY, one status byte, then a carriage return and a line feed. Its label says 115 200 baud, 8N1. Your receiving board, an ATmega328P on a 16 MHz crystal, takes the wire on its RXD pin and passes every byte to the laptop's terminal; it was set from the datasheet's table for 115 200 at 16 MHz: UBRR 8, normal speed, 8N1. A scope's probe is on the wire, triggered on its first falling edge, with one cursor timed from the trigger. A MAX3232 module, RS-232 to logic levels, is in the parts tray. The terminal shows rubbish.

What you do

Controls

  • Receiving board: UBRR: 0 to 207
  • Receiving board: speed: Normal or Double speed
  • Receiving board: frame: 0 to 4
  • Scope time base: 0 to 6
  • Scope delay, µs: 0 to 800
  • Scope cursor, divisions: 0 to 10

Buttons

  • Record the line

Stockroom

  • Between the wire and RXD: Nothing: straight in · A MAX3232, RS-232 to logic

Unknown

  • Board: what it sends, and why the terminal shows rubbish

Predictions

  • The board's label says 115 200 baud, 8N1, and the receiving board is set to 115 200, 8N1, from the datasheet's own table. The terminal will show…
  • The terminal shows rubbish. With nothing changed, the board sends the same line again. The rubbish will…

To work out

  • After READY the board sends one status byte, which the terminal cannot print. Read it off the scope, bit by bit: what is it, as a decimal number?
  • At what rate does the board actually send? Measure it on the scope with the cursor, over as many bits as you can. In baud, three significant figures. (baud)

To conclude

  • The terminal showed rubbish because…

Results kept

  • Lines: UBRR, Speed, Frame, Into RXD, Receiving rate (baud), Cursor (µs), Bytes, Same as before, Frame errors, Parity errors, Line right, Status byte

What you find

  • Nothing changed, and the rubbish came back much the same, wrong in the same places: noise would not repeat itself. The two ends disagree the same way on every line.
  • READY came through right: in every bit, at least two of the receiving board's three votes fell inside the bit it was meant to read.

What is simplified

Both ends are AVR USARTs as Microchip's ATmega328P datasheet describes them, sampled tick by tick: sixteen samples a bit (eight at double speed), the middle three voted. Where the datasheet is silent, a start bit after a frame must fall from the stop bit as voted. The line carries no noise and its edges are instant: a MAX3232's slew (6 to 30 V/µs) and its receiver's 300 ns delay are left out, and an RS-232 low straight into the logic pin is held at −0.6 V by the pin's protection diode, with nothing damaged here; the pin is rated only to −0.5 V, Microchip says no more than 1 mA through that diode (its note AVR182; the automotive datasheet's injection current is the same), and a MAX3232 can push 35 mA, so a real pin may not survive it. The receiving board's 16 MHz crystal is taken as exact. A board with no crystal runs 5.5 to 9.5 % off by seed, inside its ±10 % factory calibration; the datasheet's typical curves put most parts within about 2 % at room temperature. The board sends one line a second, its frames back to back. Changing the receiving board's settings restarts it and clears the terminal. The receiving board passes each byte it takes, and its frame and parity errors, through its SPI port to a USB bridge and the laptop: a second link, never at fault, whose working is left out (the ATmega328P has one USART, an SPI port and a 2-wire interface). The terminal shows ISO 8859-1, with a dot for anything it cannot print. The scope's probe loads nothing.

Topics

serial, uart, usart, rs-232, baud rate, bit time, start bit, stop bit, parity, framing error, frame format, 8n1, oversampling, majority vote, clock tolerance, crystal, rc oscillator, ubrr, atmega328p, avr, max3232, logic levels, oscilloscope, cursor, decoding, troubleshooting