A parting word on serial ports

9 May

Serial2 and serial3: We can run the same two examples on serial2 and serial3 that we just tested on serial0. To do this you must implement the full serial port hardware as shown in the schematic in Figures 9-19 and 9-20 (the UART and line drivers). You should be able to rerun both SerialLoopTest.tini and MeterReader.tini on serial2 and serial3 with the exact same results. But again, just as with serial1, we need to indicate to TINI that we are interested in using the serial port2 or 3 this time. Not only must we enable these serial ports but we have found that we need to reboot TINI after doing so, so that the TINI firmware can find and initialize them. Run serialports.tini to enable them.

TINI /> java serialports.tini -e 23 -q
enabling serial2
enabling serial3
serial1: disabled for 1-wire communication
enabled for serial communication
serial2: enabled, address 0×380028
serial3: enabled, address 0×380020
Search for ports on boot enabled
TINI />

Now reboot TINI. If you do this with JavaKit running and TINI serial0 connected to your PC, you should see some new information in the boot test that goes whizzing by. Before installing the serial2 and serial3 ports, your boot test probably looked some- thing like this:

——> TINI Boot <——
TINI OS 1.02d
API Version 800C
Copyright (C) 1999 – 2001 Dallas Semiconductor Corporation
18000000
Running POR Code
Memory POR Routines
000020
0080,0100,0180,0200,0280,0300,0380,0400,0480,0500,0580,0600,Transient
blocks freed: 0626, size: 01FDC0
CPersistant blocks freed: 0000, size: 000000
KM_Init Passed
Ethernet MAC Address Part Found
TTS Revision: 179 , Date: 11/05/01 5:16p
Thread_Init Passed
External Serial Port Init
External serial ports not enabled
Memory Available: 06D3C0
Creating Task:
0100
01
Loading application at 0×070100
Creating Task:
0200
02
Application load complete

The interesting lines are in bold text, telling us that the serial ports (meaning serial2 and serial3) are not enabled. If you enable them but don’t implement them in hard- ware, or your hardware is not working properly, then you might see something like this:

TTS Revision: 179 , Date: 11/05/01 5:16p
Thread_Init Passed
External Serial Port Init
Port serial2 NOT detected
Port serial3 NOT detected
Memory Available: 0F3620
Creating Task:

This is telling us that while TINI was trying to initialize serial2 and serial3, it couldn’t find them. Either they are not connected or not working properly. Once the hardware is working properly you will see this sort of message in that part of the boot sequence:

TTS Revision: 179 , Date: 11/05/01 5:16p
Thread_Init Passed
External Serial Port Init
Port serial2 detected
Port serial3 detected
Memory Available: 06D3C0
Creating Task:

If you have gotten to this point, then serial2 and serial3 should be working just fine. You can run both SerialLoopTest.tini and MeterReader.tini on serial2 and serial3 with the exact same results as with serial0 and serial1.

A parting word on serial ports

It is possible to change the speed of the serial port by directly changing the clock divisor the UART uses. Why would you want to do this? In Chapter 12 on controller area net- works, we will find that we cannot achieve CAN bus speeds greater than 125 kbps because the TINI CPU oscillator of 18.432 MHz doesn’t divide nicely and leaves us with an unacceptable percent error (for the CAN bus). If we switch the TINI CPU to a 18.0 MHz oscillator, then we get very nice CAN bus speeds (with no error) at speeds of 500 kbps and 1 Mbps but this unfortunately changes the speed of the internal TINI UART as well (the external UART has its own oscillator so that remains unchanged). By changing the oscillator from 18.432 MHz to 18 MHz we are slowing TINI by 2.3% (and remember that the TINI clock will be 2.3% slower so all time and time-related methods will be 2.3% off). The 16550 UART has a number of programmable registers for adjusting various things and controlling the UART operation. The serial port baud rate is controlled by a divisor that divides the UART clock down. The divisor is determined by:

If we leave the divisor alone but change the TINI clock, we can find the actual baud rate using this new clock speed (it’s 2.3% slower):

Again, this error is 2.3%, which is within the 5% allowed in RS-232 specification. If we are interested in reducing the error brought on by changing the CPU clock, then we can program the UART with a new divisor to account for this slower clock using this method:

TINISerialPort.setDivisor( int );

Table 9-4 shows the new divisor and the error. There is still some error as the 18-MHz clock we use is not evenly divisible by the baud rates we want. It is worth noting that we can’t reduce the error for the higher speeds but with all baud rates below 38400 there is less than 1% error.

Table 9-4: UART baud rate divisor after changing clock

I think we can conclude that if you do need the faster speeds for a CAN bus and you change the CPU oscillator to 18 MHz, it’s probably not worth changing the UART baud rate divisor (unless, of course, you select an oscillator that is significantly faster or slower than 18.432 MHz—then you will need to change the serial port baud rate divisor).

Parallel Ports
The TINI stick and socketboard also support parallel I/O. This is not the traditional parallel port that you would find on a personal computer such as that meant for a printer, but simply parallel data lines for input and output to other digital devices. The E10 socketboard has direct support for 16 inputs and 16 outputs. These parallel I/O lines provide digital control lines to you for whatever purpose you can dream up. With these you can control external logic, light-emitting diodes, and relays, and read the status of switches and simple sensors. Review how we a added memory-mapped device in Chapter 8. That’s exactly how the E10 socketboard implements parallel I/O.

We can add multiple banks of parallel inputs, outputs or bi-directional I/O depending on our needs. These parallel I/O lines can be constructed from a wide variety of logic circuits depending on the application, and they can be configured to control a still wider variety of devices.

TINI parallel ports
If you examine the TINI socketboard Rev C schematic6 , page 4, you notice that there are two major sections to the parallel I/O: the port control logic (address decoders and selectors) and the I/O buffers/drivers.

Port control
The port control logic performs the address decoding and selects the appropriate buffer/ driver for either writing data to a parallel device or reading data from a parallel device. The address decoders place the E10 parallel I/O at 0×380000 and 0×3800001 in the TINI memory map. Both locations are available for reading and writing, but both read and write use different drivers/buffers (not the same as 16 bi-directional I/O lines). When writing data, the /WR line enables U4:B, which in turn enables either /ENWR0 or /ENWR1. /ENWR0 enables U12 and /ENWR1 enables U16. When reading parallel data, the /WR line enables U4:B, which in turn enables either /ENWR0 or /ENWR1. / ENWR0 enables U12 and /ENWR1 enables U16.

Figure 9-23: Parallel port control

Parallel I/O buffers/
The chips U12, U14, U16, and U17 are the input buffers and output drivers for the I/O ports.

• U12, U16 use a 74HC574  (octal D-type flip-flip)7 to provide 16 tristate, latched, outline lines. U12 does not have pull-ups (these eight outputs will float when not driven) and U16 does (these eight outputs will go high when not driven by the flip-flop.

• U14, U17 use a 74HC541 (octal buffer/line driver)8 to provide 16 latched inputs. All 16 input lines have pull-ups, so they will be high when there is no input signal.

drivers

Figure 9-24: Parallel port buffers/drivers

Random Posts

Comments are closed.