Serial i/o – Echelon Mini FX User Manual
Page 91
78 Developing
Device
Applications
current.raw[0] = (unsigned)touch_byte(ioTemperatureSensor, 0xFFu);
if (touch_reset(ioTemperatureSensor)) {
// The value currently held in ‘current’ is the raw DS18S20
// data, in Celsius, at a resolution of 0.5 degrees.
// SNVT_temp_p, however, provides a resolution of 0.01 in
// a fixed-point implementation.
// Correct the raw reading by factor 50 thus:
current.value *= 50ul;
// Start the next conversion cycle:
(void) touch_byte(ioTemperatureSensor, DS18S20_SKIP_ROM);
(void) touch_byte(ioTemperatureSensor, DS18S20_CONVERT);
} else {
current.value = 32767l;
}
}
return current.value;
}
Serial I/O
Serial I/O is often used to exchange application data with other processors or computers.
A simple serial text output is also often useful for simple application-level debugging and
diagnosing, or for reporting calibration data during manufacture.
Both the FT 5000 EVB and the PL 3150/PL 3170 EVB support a EIA-232 line driver and
a 9-pin standard serial port (J201). To use this serial port, you must configure your EVB
as described in Table 5-3 in the Getting Started with Neuron C section earlier in this
chapter. This enables your application to drive the asynchronous serial output from the
Smart Transceiver’s I/O 10 pin through the EIA-232 line driver and to the J201
connector.
To monitor the serial output generated by the examples in this chapter, you can connect
your EVB to your computer using a DB9 Male-Female Serial Extension Cable or a USB
Type A to Type B Cable (FT 5000 EVB only), and then run Windows HyperTerminal,
PuTTY, or another terminal emulation program on your computer. Configure the
terminal emulation program for direct connection to your serial port (typically COM1 or
COM2), 9600 bps, 8 data bits, no parity, one stop bit, and no flow control.
The following example implements the SerialOutput() function, which uses the SCI
serial I/O model through pins I/O 8 (RxD, which is not used in this example) and I/O 10
(TxD, which is used to send data). The SerialOutput() function sends a zero-terminated
string (without the termination byte) to the serial output, using the SCI input/output
model. The function automatically appends a "\r\n" line termination.
The SCI I/O model uses the on-chip hardware UART. If the SCI I/O model is not
available on your hardware platform, you can use the serial output model instead.
IO_8 sci baud(SCI_9600) ioSerial;
void SerialOutput(const char *data)
{
// Send data:
io_out_request(ioSerial, data, strlen(data));
while(!io_out_ready(ioSerial)) ;
// Send line termination:
io_out_request(ioSerial, “\r\n”, 2);
}