首页 | 最新需求 | 最新现货 | IC库存 | 供应商 | IC英文资料库 | IC中文资料库 | IC价格 | 电路图 | 应用资料 | 技术资料
 电路图:    3万份资料
您现在的位置:首页 >  电路图 芯片中文资料列表  
 
 
介绍:

Using the Serial Port on the MAXQ610 Microcontroller

Abstract: The MAXQ610 microcontroller provides two standard USART serial ports. The asynchronous mode 1, one of the modes supported by the MAXQ610's serial ports, can be used to communicate with PC COM ports and many other types of legacy equipment. This application note explains how the interrupt handling support provided by the MAXQ610 for serial-port transmit and receive operations allows the application to respond quickly to the serial port when a new character is received or when a character has completed transmission.

OverviewThe MAXQ610 microcontroller includes peripherals to allow communication with external devices or systems. These peripherals include a master/slave Serial Peripheral Interface (SPI™); a carrier generation/modulation system for infrared (IR) communication; and two separate universal synchronous/asynchronous receiver/transmitters (USARTs), commonly known as serial ports.

This application note demonstrates the use of the serial port on the MAXQ610 in 10-bit asynchronous mode. This mode is commonly used for communications with, and/or sending debug output to, a standard COM port on a PC. This mode allows two devices or systems to communicate by simply agreeing on a common bit format and baud rate, regardless of the actual operating frequency found on either side of the communications channel.

Demonstration code for this application note is written for the MAXQ610 and the MAXQ610 EV (evaluation) kit, using the assembly-based MAX-IDE environment. The code and project files for the demo application covered in this application note are available for download.

The following hardware and software are required to run the demonstration code.
  • MAXQ610 EV kit board
  • MAXQJTAG board (serial-to-JTAG interface)
  • JTAG programming cable (2 x 5 female-to-female 0.100" header, 10-connector ribbon cable)
  • DB9 straight-through male-to-female serial cable
  • 5VDC regulated, center-post-positive power supply
  • PC with available COM (serial) port or USB-to-serial adapter
  • MAX-IDE environment
  • Terminal emulator (such as MTK operating in the Dumb Terminal mode, HyperTerminal, or TeraTerm)
The latest installation package and documentation for the MAX-IDE environment are available for free download.
  • MAX-IDE installation
  • MAXQ Core Assembly Guide
  • Development Tools Guide
To run the C version of the demonstration code, the IAR Embedded Workbench® must be installed. An evaluation copy of this software is available on the CD for the MAXQ610 EV kit.

Setting Up the MAXQ610 EV KitThe demonstration code covered in this application note operates on the MAXQ610 EV kit. However, to make the code run properly and to enable the features in the code, the jumpers on the EV kit board must be configured correctly. The same jumper configuration is used on the kit board for both steps of running the demo (i.e., loading code and executing code).

Configure the jumpers on the MAXQ610 EV kit.
  • JH1: connect pins 2 and 3.
  • JH2: connect pins 2 and 3.
  • JH3: connect pins 2 and 3.
  • Connect the following jumpers (pins 1 and 2): JH14, JH20, JH22, JH23, JH24, JH25, and JH26.
Once the MAXQ610 EV kit board has been configured correctly, set up the hardware to compile and load the demonstration code.
  • Connect jumpers JH1, JH2, and JH3 on the serial-to-JTAG board.
  • Connect the 5VDC power supply to plug J2 on the serial-to-JTAG board.
  • Connect the DB9 cable from the COM1 port on the PC to the J1 connector on the serial-to-JTAG board.
  • Connect the JTAG programming cable from P2 on the serial-to-JTAG board to P5 on the MAXQ610 EV kit board. The red wire on the JTAG cable should go to pin 1 (TCK) on both connectors.
  • Turn on the power to the 5VDC supply.

Serial Port Modes and InitializationEach of the two USART peripherals on the MAXQ610 can operate in either a synchronous or an asynchronous mode. When operating in the synchronous mode (mode 0), the MAXQ610 acts as a bus master for all transactions. It configures the TXD line to act as a shift clock for both transmit and receive operations, while RXD is used as a bidirectional data line. Under this arrangement, data can only be transmitted in one direction at a time (half-duplex), and only at the request of the master.

In the asynchronous operation modes (modes 1, 2, and 3), there are two unidirectional data lines: TXD and RXD. The TXD line carries asynchronous data from the MAXQ610's serial port to an external device, while the RXD line carries asynchronous data from the external device back to the MAXQ610. The MAXQ610 and the external device must agree on a common format (number of data bits, parity bit, and stop bit) and a common baud rate (bus frequency) in order to communicate. These modes allow data to be transmitted in a full-duplex manner, since transfers on the TXD and RXD lines can occur independently and do not need to be synchronized to one another. The MAXQ610 can transmit data to the external device on the TXD line at any point, whether or not the external device is currently transmitting on RXD, and vice versa.

For this demonstration, we will select mode 1 which has the following characteristics.
  • Asynchronous transmission (on TXD) and reception (on RXD) of serial data
  • Baud clock provided by a dedicated baud clock generator (programmable using the PR register)
  • Eight data bits, 1 start bit, 1 stop bit
  • No parity
The baud rate (bits transmitted/received per second) used by the serial port in mode 1 is determined by the following two equations (as discussed in the MAXQ Family User's Guide):

Baud clock frequency (BAUD) = system clock frequency × PR/217(Eq. 1)
Baud rate = BAUD × 2(SMOD × 2)/26(Eq. 2)
Equation 1 describes the output of the baud clock generator. The frequency of the output generated is controlled by the contents of the 16-bit PR (phase) register. Loading a higher value into the PR register results in a higher-frequency baud clock.

Equation 2 factors in the effects of a control bit (SMOD) in the SMD or Serial Port Mode register. Setting this bit to 1 increases the final baud rate by a factor of 4. This means that the Equation 2 can also be written in either of the following ways, depending on the value of SMOD:

When SMOD=0, baud rate = BAUD/64(Eq. 3)
When SMOD=1, baud rate = BAUD/16(Eq. 4)
For most crystal-speed and baud-rate combinations, either setting for SMOD can be used. Note that the setting of SMOD affects the value to be loaded into the PR register. For our application, we will select SMOD=1, which means that the baud-rate equation reduces to the following:

Baud rate = (system clock frequency × PR/217)/16(Eq. 5)
Or:

Baud rate = (system clock frequency × PR)/221(Eq. 6)
Solving for the PR value gives us the equation that most interests us. Typically, the baud rate and system clock frequency are fixed, and we simply want to know the desired PR register setting that will produce the intended baud rate. Therefore:

PR = baud rate × 221/(system clock frequency)(Eq. 7)
For example, use the standard 12MHz crystal found on the MAXQ610 EV kit and select a baud rate of 9600 baud. The desired setting for the PR register is (9600 × 221/12000000), which is approximately 1677 or 068Dh.

Once the values for PR and SMOD have been calculated, initializing the serial port is simply a matter of setting the USART to the proper mode and writing the PR and SMOD values. Since we are using serial port 0, the code will be writing to the appropriate set of registers for that serial port (SCON0, SMD0, PR0, and SBUF0).

;===================================================================;=;= InitSerial0;=;= Set up serial port 0 to run in 10-bit asynchronous mode at;= 9600 baud.;=InitSerial0: move

 
 

更多 110
关于我们 | 联系我们 | IC列表库索引1 | IC列表库索引2 | IC列表库索引3 | IC列表库索引4 |
深  圳13410210660             QQ : 84325569   点击这里与集成电路资料查询网联系
联系方式: E-mail:CaiZH01@163.com