Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Архив4 / Proshin_polnostyu_ves_kursach / pic18f2455_2550_4455_4550.pdf
Скачиваний:
49
Добавлен:
07.08.2013
Размер:
7.07 Mб
Скачать

PIC18F2455/2550/4455/4550

20.2.2EUSART ASYNCHRONOUS RECEIVER

The receiver block diagram is shown in Figure 20-6. The data is received on the RX 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.

The RXDTP bit (BAUDCON<5>) allows the RX signal to be inverted (polarity reversed). Devices that buffer signals from RS-232 to TTL levels also perform an inversion of the signal (when RS-232 = positive, TTL = 0). Inverting the polarity of the RX pin data by setting the RXDTP bit allows for the use of circuits that provide buffering without inverting the signal.

To set up an Asynchronous Reception:

1.Initialize the SPBRGH:SPBRG 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 the signal at the RX pin is to be inverted, set the RXDTP bit.

4.If interrupts are desired, set enable bit RCIE.

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

6.Enable the reception by setting bit CREN.

7.Flag bit, RCIF, will be set when reception is complete and an interrupt will be generated if enable bit, RCIE, was set.

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

9.Read the 8-bit received data by reading the RCREG register.

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

11.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 SPBRGH:SPBRG 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 the signal at the RX pin is to be inverted, set the RXDTP bit. If the signal from the TX pin is to be inverted, set the TXCKP bit.

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

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

6.Set the ADDEN bit to enable address detect.

7.Enable reception by setting the CREN bit.

8.The RCIF bit will be set when reception is complete. The interrupt will be Acknowledged if the RCIE and GIE bits are set.

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

10.Read RCREG to determine if the device is being addressed.

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

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

DS39632D-page 250

Preliminary

2007 Microchip Technology Inc.

PIC18F2455/2550/4455/4550

FIGURE 20-6: EUSART RECEIVE BLOCK DIAGRAM

 

 

 

CREN

 

 

OERR

 

FERR

 

 

x64 Baud Rate CLK

 

 

 

 

 

 

 

 

BRG16

SPBRGH

SPBRG

64

MSb

 

 

RSR Register

 

LSb

or

 

 

 

 

 

 

 

 

 

 

 

 

 

16

Stop

(8)

7

• • •

1

0

Start

 

Baud Rate Generator

or

 

4

 

 

 

 

 

 

 

 

 

 

 

RX9

 

 

 

 

 

 

 

Pin Buffer

Data

 

 

 

 

 

 

 

 

and Control

Recovery

 

 

 

 

 

 

 

RX

 

 

 

RX9D

RCREG Register

FIFO

 

 

 

 

 

 

 

 

 

 

 

RXDTP

SPEN

 

 

 

 

8

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Interrupt

RCIF

 

 

Data Bus

 

 

 

 

 

RCIE

 

 

 

 

 

 

FIGURE 20-7: ASYNCHRONOUS RECEPTION, RXDTP = 0 (RX NOT INVERTED)

RX (pin)

Start

 

 

 

Start

 

 

 

Start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

bit bit 0 bit 1

bit 7/8 Stop bit bit 0

 

bit 7/8 Stop bit

 

bit 7/8 Stop

 

 

 

 

 

 

 

bit

 

 

bit

 

 

 

 

 

 

 

bit

 

Rcv Shift Reg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Rcv Buffer Reg

 

 

 

 

 

Word 1

 

Word 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read Rcv

 

 

 

 

RCREG

 

RCREG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Buffer Reg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCREG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RCIF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(Interrupt Flag)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OERR bit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CREN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Note: This timing diagram shows three words appearing on the RX input. The RCREG (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

51

PIR1

 

SPPIF(1)

ADIF

RCIF

TXIF

SSPIF

CCP1IF

TMR2IF

TMR1IF

54

PIE1

 

SPPIE(1)

ADIE

RCIE

TXIE

SSPIE

CCP1IE

TMR2IE

TMR1IE

54

IPR1

 

SPPIP(1)

ADIP

RCIP

TXIP

SSPIP

CCP1IP

TMR2IP

TMR1IP

54

RCSTA

 

SPEN

RX9

SREN

CREN

ADDEN

FERR

OERR

RX9D

53

 

 

 

 

 

 

 

 

 

 

 

RCREG

 

EUSART Receive Register

 

 

 

 

 

53

 

 

 

 

 

 

 

 

 

 

 

TXSTA

 

CSRC

TX9

TXEN

SYNC

SENDB

BRGH

TRMT

TX9D

53

BAUDCON

ABDOVF

RCIDL

RXDTP

TXCKP

BRG16

WUE

ABDEN

53

SPBRGH

 

EUSART Baud Rate Generator Register High Byte

 

 

 

53

 

 

 

 

 

 

 

SPBRG

 

EUSART Baud Rate Generator Register Low Byte

 

 

 

53

 

 

 

 

 

 

 

 

 

 

 

Legend:

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

Note 1:

Reserved in 28-pin devices; always maintain these bits clear.

 

 

 

 

2007 Microchip Technology Inc.

Preliminary

DS39632D-page 251

PIC18F2455/2550/4455/4550

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 RX/DT line while the EUSART is operating in Asynchronous mode.

The auto-wake-up feature is enabled by setting the WUE bit (BAUDCON<1>). Once set, the typical receive sequence on RX/DT 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 RX/DT 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 RCIF 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 RCREG register.

The WUE bit is automatically cleared once a low-to- high transition is observed on the RX line following the wake-up event. At this point, the EUSART module is in Idle mode 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 RX/DT, 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 RCIF 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 Idle mode. The wake-up event causes a receive interrupt by setting the RCIF bit. The WUE bit is cleared after this when a rising edge is seen on RX/DT. The interrupt condition is then cleared by reading the RCREG register. Ordinarily, the data in RCREG will be dummy data and should be discarded.

The fact that the WUE bit has been cleared (or is still set) and the RCIF flag is set should not be used as an indicator of the integrity of the data in RCREG. 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)

 

 

 

RX/DT Line

 

 

 

RCIF

 

 

Cleared due to user read of RCREG

 

 

 

Note 1: The EUSART remains in Idle 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)

 

 

 

RX/DT Line

 

 

Note 1

 

 

 

RCIF

Sleep Command Executed

 

Sleep Ends

 

Cleared due to user read of RCREG

 

 

 

 

 

 

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 in Idle while the WUE bit is set.

DS39632D-page 252

Preliminary

2007 Microchip Technology Inc.

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