This application note describes how to develop applications using the MAXQ serial driver library on the MAXQ2000 microcontroller evaluation (EV) kit
. The MAXQ serial driver is available for the IAR Embedded Workbench® for MAXQ
and Rowley Associates' CrossWorks for MAXQ
, two integrated development and debugging environments for MAXQ applications using C and assembly languages. Sample code in C demonstrates MAXQ serial-driver usage and limitations, and how to implement RTS/CTS flow control using the MAXQ serial driver.
MAXQ Serial-Driver Overview
The MAXQ serial driver provides a set of C functions which enable the user to configure the MAXQ UART for serial communication. These functions are listed in the source file, maxq_serial.h
, supplied in the MAXQ2000 EV kit.
The MAXQ serial driver provides the following features.
- Even, odd, and none parity.
- Separate transmit and receive internal buffers. The size of these buffers is defined at compile time.
- Non-blocking serial_write and serial_read routines.
- A serial_isr() function that should be called as part of the interrupt handler by the user application. It computes the parity as "per configuration" and transmits/receives the data on the serial line.
- Support for the flow control at the application level. The function serial_stopTx() stops the transmission of serial data, and serial_restartTx() restarts the serial transmission.
The source code for the MAXQ2000 serial driver is available here
. The driver can be ported for other MAXQ devices by modifying a few configuration parameters as follows.
- maxq_config.h contains compiler-specific configuration parameters. Modify the following lines in the file to suit your device and compiler:
// user configurable options here
The above two lines specify that the driver will be compiled for IAR and MAXQ2000. To compile the driver for CrossWorks for MAXQ, modify the lines as below:
// user configurable options here
- The above two lines let the user include device-specific files for either the IAR or CrossWorks tool chains. maxq_serial.h contains driver-specific configuration parameters: driver buffer size, serial-port number, and crystal frequency in Hz. Change the following code to change the driver buffer size:
#define RX_RNG_SIZE 256
#define TX_RNG_SIZE 256
Modify the following code to specify the serial port (SERIAL_PORT0 for serial port 0, SERIAL_PORT1 for serial port 1) for which you want the driver configured:
// specify which serial port you are using
Modify the following code to change the crystal clock used for the EV kit. The MAXQ2000 EV kit uses a 16MHz crystal:
#define XTAL_CLK 16000000 // 16,000,000Hz
Hardware and Software Requirements
To run the application provided in this application note, you need a MAXQ2000 EV kit, a +5V power supply with minimally 200mA capacity, a PC with two serial ports (one for downloading the application onto the EV kit, and the other for communication between the MAXQ application and PC application), a straight-through serial cable, the MAXQ development tool set (IAR Embedded Workbench or CrossWorks 1.0), and the Java™ runtime environment on your PC (including the commApi and BlackBox example).
The MAXQ2000 EV kit should be set up for serial communication with RTS/CTS flow control. The jumper and DIP switch settings follow:
- Set switch SW3 1-8 to the off position.
- Set switch SW1 1, 2, 5, and 6 to the off position and SW3, 4, 7, and 8 to the on position.
- Set switch SW6, 3, and 8 to the on position, and rest to the off position.
These switch settings connect the RTS, TXD0, RXD0 and CTS signals of the MAXQ2000 EV kit's serial connector to the microcontroller, and enable SW4 DPST to pull the microcontroller's INT11 signal to ground. See Figure 1.
JU1: connect Pins 1 and 2
JU2: connect Pins 1 and 2
JU3: connect Pins 1 and 2
JU11: closed (The MAXQ2000 EV kit is powered by a JTAG interface
board which is powered by a +5V power supply.)
- Connect the serial cable between the MAXQ2000 EV kit and a PC serial port.
Figure 1. This setup of the MAXQ2000 EV kit's switch settings enables serial communication with RTS/CTS flow control.
- Download the demo software.
- Install the development tool set (IAR Embedded Workbench for MAXQ, CrossWorks for MAXQ).
- Download and install both the Java Runtime Environment and the Java communications API.
- Run the BlackBox example in the Java communications API distribution. If this works correctly, then you should be able to see your host serial ports.
Getting Started with the MAXQ Serial Driver
To begin using the development tools, please review either of two application notes. For the Rowley CrossWorks for the MAXQ, see application note 3698, "Getting Started with Rowley CrossWorks and the MAXQ2000 Evaluation Kit
", or for the IAR Embedded Workbench for MAXQ, see application note 3378, "Getting Started with the IAR Compiler and the MAXQ2000 Evaluation Kit
Execute the Java BlackBox sample application on your PC and configure it for 115200 baud, 8 data bits, 1 stop bit, and none parity. Enable the RTC/CTS flow control by clicking on the 'Xmt' check box for the serial port of your choice. The BlackBox setup is shown in Figure 2
. Note the RTS and CTS lines are green indicating that the hardware flow control is off.
From the demonstration software downloaded earlier, open the corresponding project (.EWW for IAR and .hzp for CrossWorks). Compile the application and download it into the MAXQ EV kit. For detailed instructions on downloading applications to the MAXQ, see the application notes mentioned above. Power on the MAXQ EV kit and you should see serial output from the MAXQ printed onto the BlackBox GUI. Enter some characters in the input window, and observe that the same characters are printed in the BlackBox output window. The keyed characters are transmitted from the PC to the MAXQ EV kit, and in turn, echoed back to the PC. The MAXQ application reports the number of bytes received, which should match the BlackBox report of bytes sent.
Signaling the MAXQ EV kit to Stop Sending the Characters
Click on the RTS text in the BlackBox GUI. This event signals the EV kit to stop transmitting the characters. Notice that the printing in the BlackBox stops. Click again on the RTS text to enable the MAXQ to send characters, and see that the test string continues to update.
Signaling the PC to Stop Sending the Characters
Press the SW4 switch on the MAXQ EV kit. This signals the PC (BlackBox application) to stop sending the characters. The CTS text on the GUI should turn from green to black. Enter some characters in the BlackBox application and see that the characters are not echoed back. Press the SW4 switch again which turns the CTS signal back to green. The characters that were typed before should echo back.
Figure 2. The BlackBox sample application to run on your PC.
The file sample_serial.c
contains the application's main routine and interrupt service routines (ISR) for servicing the serial interrupts and external interrupts. The firmware does the following:
- serial_init() initializes the serial driver.
- serial_setparameters() configures the serial driver for 115200/8/1/N. You can configure these parameters according to your application needs.
- Configures the external interrupts 10 (Int10 is connected to RTS line) and 11 (SW6 #3 is ON).
- Enables the interrupts for module 1 (external interrupts) and module 2 (UART).
- Enables global interrupts.
- Reads and writes from/to the serial port in a loop through serial_read() and serial_write().
- The interrupt service routine handles RTS/CTS control flow. (Pressing the SW4 button asserts or deasserts the RTS line from the EV kit; the RTS line from the PC stops/restarts the serial transmission.)
Limitations and Development Issues
- The MAXQ serial driver does not support flow control (software/hardware). It is the responsibility of the application to implement the flow control. The sample application provided in this application note describes the hardware (RTS/CTS) flow control.
- The MAXQ serial driver provided is compiled for MAXQ2000 and 16MHz crystal configurations. Changing the crystal frequency will alter the driver's baud rate computation.
- The MAXQ serial-driver internal transmit-and-receive buffers' sizes are fixed at compile time as 256 bytes.
The MAXQ compiler provided by IAR and Rowley Associates and the libraries provided by Maxim allow applications written in C to access the power and functionality of MAXQ devices. The MAXQ serial will enable users to deploy applications that use the MAXQ UART.