Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
9
Добавлен:
21.12.2020
Размер:
8.16 Mб
Скачать

PIC18F8722 FAMILY

20.2.2EUSART ASYNCHRONOUS RECEIVER

The receiver block diagram is shown in Figure 20-6. The data is received on the RXx pin and drives the data recovery block. The data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at FOSC. This mode would typically be used in RS-232 systems.

To set up an Asynchronous Reception:

1.Initialize the SPBRGHx:SPBRGx registers for the appropriate baud rate. Set or clear the BRGH and BRG16 bits, as required, to achieve the desired baud rate.

2.Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.

3.If interrupts are desired, set enable bit RCxIE.

4.If 9-bit reception is desired, set bit RX9.

5.Enable the reception by setting bit CREN.

6.Flag bit, RCxIF, will be set when reception is complete and an interrupt will be generated if enable bit, RCxIE, was set.

7.Read the RCSTAx register to get the 9th bit (if enabled) and determine if any error occurred during reception.

8.Read the 8-bit received data by reading the RCREGx register.

9.If any error occurred, clear the error by clearing enable bit CREN.

10.If using interrupts, ensure that the GIE and PEIE bits in the INTCON register (INTCON<7:6>) are set.

20.2.3SETTING UP 9-BIT MODE WITH ADDRESS DETECT

This mode would typically be used in RS-485 systems. To set up an Asynchronous Reception with Address Detect Enable:

1.Initialize the SPBRGHx:SPBRGx registers for the appropriate baud rate. Set or clear the BRGH and BRG16 bits, as required, to achieve the desired baud rate.

2.Enable the asynchronous serial port by clearing the SYNC bit and setting the SPEN bit.

3.If interrupts are required, set the RCEN bit and select the desired priority level with the RCxIP bit.

4.Set the RX9 bit to enable 9-bit reception.

5.Set the ADDEN bit to enable address detect.

6.Enable reception by setting the CREN bit.

7.The RCxIF bit will be set when reception is complete. The interrupt will be Acknowledged if the RCxIE and GIE bits are set.

8.Read the RCSTAx register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable).

9.Read RCREGx to determine if the device is being addressed.

10.If any error occurred, clear the CREN bit.

11.If the device has been addressed, clear the ADDEN bit to allow all received data into the receive buffer and interrupt the CPU.

FIGURE 20-6: EUSART RECEIVE BLOCK DIAGRAM

 

 

 

CREN

 

 

OERR

FERR

 

 

x64 Baud Rate CLK

 

 

 

 

 

 

 

 

BRG16

SPBRGHx

SPBRGx

64

MSb

 

RSRx Register

 

LSb

or

 

 

 

 

 

 

 

 

 

 

 

 

16

Stop

(8)

7

• • •

1

0

Start

 

Baud Rate Generator

or

 

4

 

 

 

 

 

 

 

 

 

 

 

RX9

 

 

 

 

 

 

 

Pin Buffer

Data

 

 

 

 

 

 

 

 

and Control

Recovery

 

 

 

 

 

 

 

RXx

 

 

 

 

RX9D

RCREGx Register

FIFO

 

 

 

 

 

 

 

 

 

 

 

SPEN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8

 

 

 

 

 

 

Interrupt

RCxIF

 

Data Bus

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCxIE

 

 

 

 

 

DS39646B-page 260

Preliminary

2004 Microchip Technology Inc.

PIC18F8722 FAMILY

FIGURE 20-7:

ASYNCHRONOUS RECEPTION

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RXx (pin)

Start

 

 

 

Start

 

 

 

 

Start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

bit 7/8 Stop

 

 

 

 

 

 

bit bit 0 bit 1

bit 7/8 Stop bit bit 0

 

bit 7/8 Stop bit

 

 

 

 

 

 

 

 

 

bit

 

 

bit

 

 

 

 

 

 

bit

 

 

Rcv Shift Reg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Rcv Buffer Reg

 

 

 

 

 

Word 1

 

Word 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read Rcv

 

 

 

 

RCREGx

 

RCREGx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Buffer Reg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCREGx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCxIF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(Interrupt Flag)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OERR bit

CREN

Note: This timing diagram shows three words appearing on the RXx input. The RCREGx (receive buffer) is read after the third word causing the OERR (overrun) bit to be set.

TABLE 20-6: REGISTERS ASSOCIATED WITH ASYNCHRONOUS RECEPTION

 

 

 

 

 

 

 

 

 

Reset

Name

Bit 7

Bit 6

Bit 5

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

Values

 

 

 

 

 

 

 

 

 

on page

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

INTCON

GIE/GIEH

PEIE/GIEL

TMR0IE

INT0IE

RBIE

TMR0IF

INT0IF

RBIF

57

PIR1

PSPIF

ADIF

RC1IF

TX1IF

SSP1IF

CCP1IF

TMR2IF

TMR1IF

60

PIE1

PSPIE

ADIE

RC1IE

TX1IE

SSP1IE

CCP1IE

TMR2IE

TMR1IE

60

IPR1

PSPIP

ADIP

RC1IP

TX1IP

SSP1IP

CCP1IP

TMR2IP

TMR1IP

60

TRISC

TRISC7

TRISC6

TRISC5

TRISC4

TRISC3

TRISC2

TRISC1

TRISC0

60

 

 

 

 

 

 

 

 

 

 

TRISG

TRISG4

TRISG3

TRISG2

TRISG1

TRISG0

60

RCSTAx

SPEN

RX9

SREN

CREN

ADDEN

FERR

OERR

RX9D

59

 

 

 

 

 

 

 

 

 

 

RCREGx

EUSARTx Receive Register

 

 

 

 

 

59

 

 

 

 

 

 

 

 

 

 

TXSTAx

CSRC

TX9

TXEN

SYNC

SENDB

BRGH

TRMT

TX9D

59

BAUDCONx

ABDOVF

RCIDL

SCKP

BRG16

WUE

ABDEN

61

SPBRGHx

EUSARTx Baud Rate Generator Register High Byte

 

 

 

61

 

 

 

 

 

 

SPBRGx

EUSARTx Baud Rate Generator Register Low Byte

 

 

 

59

 

 

 

 

 

 

 

 

 

 

Legend: — = unimplemented locations read as ‘0’. Shaded cells are not used for asynchronous reception.

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 261

PIC18F8722 FAMILY

20.2.4AUTO-WAKE-UP ON SYNC BREAK CHARACTER

During Sleep mode, all clocks to the EUSART are suspended. Because of this, the Baud Rate Generator is inactive and a proper byte reception cannot be performed. The auto-wake-up feature allows the controller to wake-up due to activity on the RXx/DTx line, while the EUSART is operating in Asynchronous mode.

The auto-wake-up feature is enabled by setting the WUE bit (BAUDCONx<1>). Once set, the typical receive sequence on RXx/DTx is disabled and the EUSART remains in an Idle state, monitoring for a wake-up event independent of the CPU mode. A wake-up event consists of a high-to-low transition on the RXx/DTx line. (This coincides with the start of a Sync Break or a Wake-up Signal character for the LIN protocol.)

Following a wake-up event, the module generates an RCxIF interrupt. The interrupt is generated synchronously to the Q clocks in normal operating modes (Figure 20-8) and asynchronously, if the device is in Sleep mode (Figure 20-9). The interrupt condition is cleared by reading the RCREGx register.

The WUE bit is automatically cleared once a low-to- high transition is observed on the RXx line following the wake-up event. At this point, the EUSART module is inactive and returns to normal operation. This signals to the user that the Sync Break event is over.

20.2.4.1Special Considerations Using Auto-Wake-up

Since auto-wake-up functions by sensing rising edge transitions on RXx/DTx, information with any state changes before the Stop bit may signal a false end-of-

character and cause data or framing errors. To work properly, therefore, the initial character in the transmission must be all ‘0’s. This can be 00h (8 bytes) for standard RS-232 devices or 000h (12 bits) for LIN bus.

Oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., XT or HS mode). The Sync Break (or Wake-up Signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the EUSART.

20.2.4.2Special Considerations Using the WUE Bit

The timing of WUE and RCxIF events may cause some confusion when it comes to determining the validity of received data. As noted, setting the WUE bit places the EUSART in an inactive state. The wake-up event causes a receive interrupt by setting the RCxIF bit. The WUE bit is cleared after this when a rising edge is seen on RXx/DTx. The interrupt condition is then cleared by reading the RCREGx register. Ordinarily, the data in RCREGx will be dummy data and should be discarded.

The fact that the WUE bit has been cleared (or is still set) and the RCxIF flag is set should not be used as an indicator of the integrity of the data in RCREGx. Users should consider implementing a parallel method in firmware to verify received data integrity.

To assure that no actual data is lost, check the RCIDL bit to verify that a receive operation is not in process. If a receive operation is not occurring, the WUE bit may then be set just prior to entering the Sleep mode.

FIGURE 20-8: AUTO-WAKE-UP BIT (WUE) TIMINGS DURING NORMAL OPERATION

Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4

OSC1

Bit set by user

 

Auto-Cleared

WUE bit(1)

 

 

 

 

RXx/DTx Line

 

 

 

RCxIF

 

 

Cleared due to user read of RCREGx

 

 

 

Note 1: The EUSART remains inactive while the WUE bit is set.

 

FIGURE 20-9:

AUTO-WAKE-UP BIT (WUE) TIMINGS DURING SLEEP

Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4

Q1

Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4

OSC1

Bit set by user

 

Auto-Cleared

WUE bit(2)

 

 

 

 

RXx/DTx Line

Note 1

 

RCxIF

Sleep Command Executed

 

Sleep Ends

 

Cleared due to user read of RCREGx

 

 

 

 

 

Note 1: If the wake-up event requires long oscillator warm-up time, the auto-clear of the WUE bit can occur before the oscillator is ready. This sequence should not depend on the presence of Q clocks.

2:The EUSART remains inactive while the WUE bit is set.

DS39646B-page 262

Preliminary

2004 Microchip Technology Inc.

Соседние файлы в папке Склад