beautypg.com

4 uart mode 1 asynchrono, 5 uart interrupts example, 6 uart transmit data exa – Maxim Integrated MAXQ7667 User Manual

Page 161: 5 uart interrupts example -31, 6 uart transmit data example -31, Maxq7667 user’s guide

background image

8.5.4 UART Mode 1 Asynchronous Full-Duplex Setup Example

To set up the UART/LIN controller for UART operation, the LIN or UART mode select (LUN[1:0]) bits in CNT0 are set for UART mode.

To set up the UART mode, set the registers as shown in the following example. In this example the UART is set for asynchronous com-

munication using mode 1 with 115,200 baud.

Set LUN bits (CNT0.1:0) to 0 to select the UART mode.

Set FEDE bit (SMD.0) to 0 to disable the framing error detection.

Set SMOD bit (SMD.1) to 1 (16 times the baud clock for mode 1).

Set IE bit (SMD.2) to 0.

Set OFS bit (SMD.6) to 1.

Disable infrared modulation by setting EIR bit (SMD.7) to 0.

Set TMR (0x800).

Set SM2 (SCON.5) to 0 for mode 1.

Set SM1 (SCON.6) to 1 for mode 1.

Set SM0 (SCON.7) to 0 for mode 1.

Set BT to 0x3AFB to set baud rate divider with 16MHz clock for 115,200 baud.

The UART is now configured and ready to transmit and receive. To transmit or receive data, the SBUF register is written or read. The

MAXQ core must wait until the transmit buffer shifts out the data before writing more data to the SBUF register. To receive, the MAXQ

core must wait until the data has been completely shifted into the receive register before reading. The preferred method to control the

flow to and from the SBUF register is to use transmit and receive interrupts.

8.5.5 UART Interrupts Example

To use the UART interrupts, the global, Module 3, and UART interrupts must be enabled. The following steps show how to enable the

interrupts.

Set the IGE bit in the Interrupt Control (IC.0) register.

Set the IM3 bit in the Interrupt Mask (IMR.3) register.

Set the IE bit in the Serial Mode (SMD.2) register.

Once the UART interrupts have been enabled, the interrupt flags should be cleared to ensure proper initialization as shown in the fol-

lowing example.

Clear the RI bit (SCON.0) by setting it to 0.

Clear the TI bit (SCON.1) by setting it to 0.

8.5.6 UART Transmit Data Example

To transmit data using the SBUF register without overwriting it, the application code should examine the transmit interrupt (TI) flag

immediately after writing the SBUF register. When the transmit buffer is shifting out the data, the TI flag is set and the application code

should wait until complete. The following example details the method to prevent overwriting.

Clear the TI bit (SCON.1) by setting it to 0.

Send the character by writing to the SBUF register.

Wait until the TI bit is set before sending next character.

8-31

__________________________________________________________________________________________________________

MAXQ7667 User’s Guide