Posts Tagged ‘break mcu hex’

PostHeaderIcon ATmega162A: Two Serial Ports and What a Second One Implies

One serial port is a product talking to something. Two serial ports is a product standing between two things, and that changes what the firmware does: it stops being a controller and becomes a translator.

The distinction is visible in an image before a single function is understood, because two channels means two sets of registers, two interrupt vectors, and code that moves data from one to the other.

What the second port implies

Four product shapes, each recognisable:

Bridge. Bytes arrive on one channel and leave on the other, with little or no modification. The code is a loop and two buffers.

Protocol translator. Frames arrive in one format and leave in another. The code contains two parsers and a mapping between them, and the mapping is the design.

Device plus service port. The main channel talks to the application; the second is a maintenance interface that accepts commands. The command handler is the interesting part.

Redundancy. Two channels carrying the same traffic, for reliability. Rare, and visible because the code treats them identically.

Shape Code signature What to look for first
Bridge Copy loop between two data registers Buffer sizes
Translator Two parsers, one mapper The mapping table
Service port Command dispatcher The command list
Redundancy Identical handling paths Failover logic

Why the interrupt vectors give it away

Each channel has its own receive and transmit vectors. In the vector table, four entries pointing at closely-spaced handlers means two channels active, because the handlers are usually generated from the same template and land near each other.

That is a cheap signal. Counting vector targets and looking for pairs takes a minute and establishes the channel count before any disassembly.

Buffer sizes describe the traffic

A bridge needs buffers, and the buffer sizes are set by the traffic: a command channel needs a few bytes, a data channel needs more, and a protocol with long frames needs a lot.

The initialisation code sets pointers and lengths for each buffer. Those values are a specification of what the product expects to receive — which for a translator is the frame size of the protocol it speaks.

Where the property is settled

The lock byte and the fuse byte are read before the array, as always. On this family the JTAG interface is present, and a product that used it during development may leave the fuse in a state that removes four port pins from general use.

That matters here because a bridge needs pins for the second channel, and a design that disabled JTAG did so to free pins for exactly that purpose. The fuse byte and the architecture tell the same story from two directions.

Reading order

  1. Signature, fuses, lock byte.
  2. Array read, verified.
  3. Vector table: count channel pairs.
  4. Initialisation: buffer pointers and lengths per channel.
  5. The path between channels: copy loop, parser, or dispatcher.

Step 5 determines the product category, and it is usually reachable within the first few thousand instructions because translators tend to be small.

Related notes

FAQ

Are the two channels truly independent? Yes. Separate registers, separate vectors, separate baud rate generators.

Can both run at different baud rates? Yes, and the initialisation sets them separately.

Does a second port mean a second protocol? Usually, which is why translators exist.

Is JTAG relevant to the serial channels? Only through pin allocation: disabling it frees pins that a second channel may use.

Conclusion

A second serial channel changes the product category, and the change is visible in the vector table before anything else is read. Buffer sizes describe the traffic, and the code between the channels is the design. On a part built for bridging, that path is where the value is.