pekdb

UART I/O

Current version is 2.2.0

About
UART I/O is an I/O device which communicates via RS232. It only uses RxD and TxD to transmit messages from and to the device. You can easy use a terminal program or write your own to communicate. The device has 8 channels which can be set to output or input independent of each other. It's also possibly to update the firmware via RS232, i.e. no need for an external programmer. The used microcontroller is AVR ATtiny2313.



Communicate
The I/O device uses 19200bps, 8 bits, no parity and one stop bit. To control the device you need to send different commands. Every command result in an answer back to the master.

A new C++ class shall be written to make it easier for implementing the communication in your own program. The class will be published here when finnished.


Commands
Choose channels as input/output:
Byte 1 to send = 0x01
Byte 2 to send = 0x00-0xFF, where a high bit is output
Byte 1 to receive = 0x81

Read from inputs:
Byte 1 to send = 0x02
Byte 1 to receive = 0x82
Byte 2 to receive = 0x00-0xFF, status of input channels

Write to outputs:
Byte 1 to send = 0x03
Byte 2 to send = 0x00-0xFF, status of output channels
Byte 1 to receive = 0x83

Get version of the program in the I/O device:
Byte 1 to send = 0x04
Byte 1 to receive = 0x84
Byte 2 to receive = Major version
Byte 3 to receive = Minor version
Byte 4 to receive = Patch version

Enable interrupt:
Byte 1 to send = 0x05
Byte 2 to send = 0x00-0xFF, sensible pins (0 is interrupt off)
Byte 1 to receive = 0x85

Update firmware:
Byte 1 to send = 0x10
See below how to update the firmware.


Interrupts

Interrupts let you read the status of all pins when a sensible pin is changing state. If a sensible pin is changing state, lets say go from high to low, two bytes will automatically be sent to the master:
Byte 1 to receive = 0x85
Byte 2 to receive = 0x00-0xFF, status of input channels
Using interrupts is a good way to get rid of polling and to faster know when one input pin has changed it's state.


Firmware updates

When sending 0x10 you enable the firmware updating mode.

Firmware data to the MCU consists of the following parts,
where < LAST > is the first byte received:

Data:  < LAST >< PAGE >< DATA >< CHECKSUM >
Bytes:   -1-     -1-     -32-      -1-

LAST: 0x00 = not the last message,  0x01 = last message in update sequence
PAGE: Page in memory = 0x00-0x3F (tiny2313)
DATA: Data to write
CHECKSUM: Checksum of message = 2 complement of all bytes (except the checksum)

Answer to firmware data from the MCU:

Data:  < STATUS >< CHECKSUM >
Bytes:    -1-        -1-

STATUS: 0x00 = wrong checksum (send again), 0x01 = no errors (ready for next message of firmware data)
CHECKSUM: Checksum of message = 2 complement of the < STATUS > byte

Example of programming sequence:
1. Send 0x10 to enable "Firmware update mode"
2. Wait for message < 0x01 >< 0xFF >, i.e. the MCU is ready
3. Send < 0x00 >< 0x00 >< 32 bytes >< checksum > to program page 0x00
4. Wait for message < 0x01 >< 0xFF >, i.e. the MCU is ready for next page to program
5. Send < 0x00 >< 0x01 >< 32 bytes >< checksum > to program page 0x01
6. Wait for message < 0x01 >< 0xFF >, i.e. the MCU is ready for next page to program
7. Send < 0x01 >< 0x02 >< 32 bytes >< checksum > to program page 0x02 and quit
8. Wait for message < 0x01 >< 0xFF >, everything went OK

Notes:
If you receive the message of checksum error in the last programming
message (the last page to download), the program will still quit from
programming mode. To try reprogram the last page you need to enter programming
mode again and program the last page. To go around this you can always send
< 0x00 > as the first byte in the programming message. When you have finished
all programming you send 0x01 as the first byte and be assured of that the
checksum is wrong. Then the program will quit from programming mode.


Design
Click here to see the circuit diagram (AT90S2313 changed to ATtiny2313).
Click here to see the pcb layout.
Click here to see the component layout and top layer with two wires.
Click here to receive the code for the AVR microcontroller.


History
v2.2.0 - 2004.12.30 : Firmware updates via RS232, interrupt of I/O signals, timer is gone, different acknowledge bytes
v2.1.0 - 2003.01.18 : Added acknowledge byte
v2.0.0 - 2002.05.23 : Better version, added timer capabilities
v1.0.0 - 2001.10.25 : The first version

Copyright (c) 2004 PerErik Klarenfjord, All Rights Reserved
All trademarks are the property of their owners
Any actions you take after reading this website are your own responsibility
MADE IN SWEDEN
Hosted by GMQ