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

PIC18F8722 FAMILY

19.4.2OPERATION

The MSSP module functions are enabled by setting MSSP Enable bit, SSPEN (SSPxCON1<5>).

The SSPxCON1 register allows control of the I2C operation. Four mode selection bits (SSPxCON1<3:0>) allow one of the following I2C modes to be selected:

I2C Master mode, clock

I2C Slave mode (7-bit address)

I2C Slave mode (10-bit address)

I2C Slave mode (7-bit address) with Start and Stop bit interrupts enabled

I2C Slave mode (10-bit address) with Start and Stop bit interrupts enabled

I2C Firmware Controlled Master mode, slave is Idle

Selection of any I2C mode with the SSPEN bit set forces the SCLx and SDAx pins to be open-drain, provided these pins are programmed as inputs by setting the appropriate TRISC or TRISD bits. To ensure proper operation of the module, pull-up resistors must be provided externally to the SCLx and SDAx pins.

19.4.3SLAVE MODE

In Slave mode, the SCLx and SDAx pins must be configured as inputs (TRISC<4:3> set). The MSSP module will override the input state with the output data when required (slave-transmitter).

The I2C Slave mode hardware will always generate an interrupt on an address match. Through the mode select bits, the user can also choose to interrupt on Start and Stop bits

When an address is matched, or the data transfer after an address match is received, the hardware automatically will generate the Acknowledge (ACK) pulse and load the SSPxBUF register with the received value currently in the SSPxSR register.

Any combination of the following conditions will cause the MSSP module not to give this ACK pulse:

The Buffer Full bit, BF (SSPxSTAT<0>), was set before the transfer was received.

The overflow bit, SSPOV (SSPxCON1<6>), was set before the transfer was received.

In this case, the SSPxSR register value is not loaded into the SSPxBUF, but bit SSPxIF is set. The BF bit is cleared by reading the SSPxBUF register, while bit SSPOV is cleared through software.

The SCLx clock input must have a minimum high and low for proper operation. The high and low times of the I2C specification, as well as the requirement of the MSSP module, are shown in timing parameter 100 and parameter 101.

19.4.3.1Addressing

Once the MSSP module has been enabled, it waits for a Start condition to occur. Following the Start condition, the 8 bits are shifted into the SSPxSR register. All incoming bits are sampled with the rising edge of the clock (SCLx) line. The value of register SSPxSR<7:1> is compared to the value of the SSPxADD register. The address is compared on the falling edge of the eighth clock (SCLx) pulse. If the addresses match and the BF and SSPOV bits are clear, the following events occur:

1.The SSPxSR register value is loaded into the SSPxBUF register.

2.The Buffer Full bit, BF, is set.

3.An ACK pulse is generated.

4.The MSSP Interrupt Flag bit, SSPxIF, is set (and interrupt is generated, if enabled) on the falling edge of the ninth SCLx pulse.

In 10-bit Address mode, two address bytes need to be received by the slave. The five Most Significant bits (MSbs) of the first address byte specify if this is a 10-bit address. Bit R/W (SSPxSTAT<2>) must specify a write so the slave device will receive the second address byte. For a 10-bit address, the first byte would equal ‘11110 A9 A8 0’, where ‘A9’ and ‘A8’ are the two MSbs of the address. The sequence of events for 10-bit address is as follows, with steps 7 through 9 for the slave-transmitter:

1.Receive first (high) byte of address (bits SSPxIF, BF and UA (SSPxSTAT<1>) are set on address match).

2.Update the SSPxADD register with second (low) byte of address (clears bit UA and releases the SCLx line).

3.Read the SSPxBUF register (clears bit BF) and clear flag bit SSPxIF.

4.Receive second (low) byte of address (bits SSPxIF, BF and UA are set).

5.Update the SSPxADD register with the first (high) byte of address. If match releases SCLx line, this will clear bit UA.

6.Read the SSPxBUF register (clears bit BF) and clear flag bit SSPxIF.

7.Receive Repeated Start condition.

8.Receive first (high) byte of address (bits SSPxIF and BF are set).

9.Read the SSPxBUF register (clears bit BF) and clear flag bit SSPxIF.

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 219

PIC18F8722 FAMILY

19.4.3.2Reception

When the R/W bit of the address byte is clear and an address match occurs, the R/W bit of the SSPxSTAT register is cleared. The received address is loaded into the SSPxBUF register and the SDAx line is held low (ACK).

When the address byte overflow condition exists, then the no Acknowledge (ACK) pulse is given. An overflow condition is defined as either bit BF (SSPxSTAT<0>) is set, or bit SSPOV (SSPxCON1<6>) is set.

An MSSP interrupt is generated for each data transfer byte. The interrupt flag bit, SSPxIF, must be cleared in software. The SSPxSTAT register is used to determine the status of the byte.

If SEN is enabled (SSPxCON2<0> = 1), SCLx will be held low (clock stretch) following each data transfer. The clock must be released by setting bit, CKP (SSPxCON1<4>). See Section 19.4.4 “Clock Stretching” for more detail.

19.4.3.3Transmission

When the R/W bit of the incoming address byte is set and an address match occurs, the R/W bit of the SSPxSTAT register is set. The received address is loaded into the SSPxBUF register. The ACK pulse will be sent on the ninth bit and pin SCLx is held low regardless of SEN (see Section 19.4.4 “Clock Stretching” for more detail). By stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. The transmit data must be loaded into the SSPxBUF register which also loads the SSPxSR register. Then pin SCLx should be enabled by setting bit, CKP (SSPxCON1<4>). The eight data bits are shifted out on the falling edge of the SCLx input. This ensures that the SDAx signal is valid during the SCLx high time (Figure 19-9).

The ACK pulse from the master-receiver is latched on the rising edge of the ninth SCLx input pulse. If the SDAx line is high (not ACK), then the data transfer is complete. In this case, when the ACK is latched by the slave, the slave logic is reset (resets SSPxSTAT register) and the slave monitors for another occurrence of the Start bit. If the SDAx line was low (ACK), the next transmit data must be loaded into the SSPxBUF register. Again, pin SCLx must be enabled by setting bit CKP.

An MSSP interrupt is generated for each data transfer byte. The SSPxIF bit must be cleared in software and the SSPxSTAT register is used to determine the status of the byte. The SSPxIF bit is set on the falling edge of the ninth clock pulse.

DS39646B-page 220

Preliminary

2004 Microchip Technology Inc.

.Inc Technology Microchip 2004

Preliminary

221 page-DS39646B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Receiving Address

 

 

 

R/W = 0

 

 

 

 

Receiving Data

 

 

 

 

 

 

 

 

ACK

 

 

 

Receiving Data

 

 

 

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

A7

 

A6

 

A5 A4 A3

A2 A1

 

 

 

 

ACK

 

D7 D6 D5 D4 D3

 

D2 D1

 

D0

 

 

D7

 

D6 D5 D4 D3 D2

 

D1 D0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SCLx

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

P

S

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SSPxIF (PIR1<3> or PIR3<7>)

Bus master terminates transfer

BF (SSPxSTAT<0>)

Cleared in software

SSPxBUF is read

SSPOV (SSPxCON1<6>)

SSPOV is set because SSPxBUF is

still full. ACK is not sent.

CKP

(CKP does not reset to ‘0’ when SEN = 0)

8:-19FIGURE

 

 

I

 

 

2

 

 

BIT-7 (RECEPTION, 0 = SEN WITH TIMING MODE SLAVE C™

 

PIC18F8722

ADDRESS)

 

FAMILY

222 page-DS39646B

Preliminary

.Inc Technology Microchip 2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Transmitting Data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Receiving Address

 

 

 

R/W = 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx

 

 

 

A7

 

A6

 

 

 

A4

 

A3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

D7

 

D6

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

A5

 

 

 

A2

A1

 

 

 

 

 

 

 

ACK

 

 

 

 

D5

 

D4

 

D3

 

D2

D1

 

D0

 

 

 

 

SCLx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

2

 

3

 

4

 

5

 

6

 

 

 

7

 

 

8

 

 

 

9

 

 

 

 

 

 

1

 

 

2

 

3

 

4

 

5

 

6

 

 

7

 

8

 

 

 

9

 

 

 

 

S

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Data in

sampled

SSPxIF (PIR1<3> or PIR3<7>)

BF (SSPxSTAT<0>)

SCLx held low while CPU responds to SSPxIF

Cleared in software

From SSPxIF ISR

SSPxBUF is written in software

CKP

CKP is set in software

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Transmitting Data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

D7

 

D6

 

D5

 

D4

 

D3

 

D2

 

D1

D0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

2

 

3

 

4

 

5

 

6

 

7

 

 

8

 

9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

P

Cleared in software

From SSPxIF ISR

SSPxBUF is written in software

CKP is set in software

9:-19FIGURE

 

FAMILYPIC18F8722

TIMINGMODESLAVE C™

 

I

 

 

2

 

 

BIT-7 (TRANSMISSION,

 

 

ADDRESS)

 

 

 

 

 

.Inc Technology Microchip 2004

Preliminary

223 page-DS39646B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Clock is held low until

 

Clock is held low until

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

update of SSPxADD has

 

update of SSPxADD has

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

taken place

 

taken place

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Receive First Byte of Address

 

 

 

 

Receive Second Byte of Address

 

 

 

 

 

 

 

 

 

 

Receive Data Byte

 

 

 

 

 

 

 

 

 

Receive Data Byte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

R/W = 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx

 

 

 

1 1 1 1 0 A9 A8

 

 

ACK

 

A7 A6 A5 A4 A3 A2 A1

A0 ACK

D7 D6 D5 D4 D3 D2

 

D1 D0 ACK D7 D6 D5 D4 D3 D2 D1 D0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SCLx

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

P

S

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bus master

 

 

 

 

 

 

 

 

 

 

 

SSPxIF (PIR1<3> or PIR3<7>)

 

 

 

 

 

 

 

 

 

terminates

 

 

 

 

 

 

 

 

 

transfer

 

 

 

 

 

 

 

 

 

 

 

Cleared in software

Cleared in software

Cleared in software

Cleared in software

 

 

 

BF (SSPxSTAT<0>)

SSPxBUF is written with

Dummy read of SSPxBUF

contents of SSPxSR

to clear BF flag

SSPOV (SSPxCON1<6>)

SSPOV is set because SSPxBUF is

still full. ACK is not sent.

UA (SSPxSTAT<1>)

UA is set indicating that the SSPxADD needs to be updated

Cleared by hardware when SSPxADD is updated with low byte of address

UA is set indicating that SSPxADD needs to be updated

Cleared by hardware when SSPxADD is updated with high byte of address

CKP

(CKP does not reset to ‘0’ when SEN = 0)

10:-19FIGURE

 

 

I

 

 

2

 

 

ADDRESS) BIT-10 (RECEPTION, 0 = SEN WITH TIMING MODE SLAVE C™

 

FAMILY PIC18F8722

224 page-DS39646B

Preliminary

.Inc Technology Microchip 2004

 

 

Bus master

Clock is held low until

Clock is held low until

terminates

transfer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

update of SSPxADD has

 

update of SSPxADD has

 

 

 

 

Clock is held low until

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

taken place

 

taken place

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CKP is set to ‘1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Receive First Byte of Address

R/W = 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Receive Second Byte of Address

 

 

 

 

 

 

 

Receive First Byte of Address

R/W = 1

 

 

Transmitting Data Byte

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx

 

 

 

1 1 1 1 0 A9 A8

 

 

 

 

A7 A6 A5 A4 A3 A2 A1 A0

 

 

ACK

1 1 1 1 0 A9 A8

 

 

 

 

ACK

D7 D6 D5 D4 D3 D2 D1

 

D0

 

 

 

ACK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SCLx

S

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

P

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sr

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SSPxIF (PIR1<3> or PIR3<7>)

Cleared in software

Cleared in software

Cleared in software

BF (SSPxSTAT<0>)

SSPxBUF is written with contents of SSPxSR

UA (SSPxSTAT<1>)

UA is set indicating that the SSPxADD needs to be updated

CKP (SSPxCON1<4>)

Dummy read of SSPxBUF to clear BF flag

Cleared by hardware when SSPxADD is updated with low byte of address

UA is set indicating that SSPxADD needs to be updated

Dummy read of SSPxBUF

 

 

 

 

 

 

BF flag is clear

 

Write of SSPxBUF

Completion of

 

to clear BF flag

 

at the end of the

 

initiates transmit

data transmission

 

 

 

 

 

third address sequence

clears BF flag

 

 

 

 

 

 

 

 

Cleared by hardware when SSPxADD is updated with high byte of address.

CKP is set in software

CKP is automatically cleared in hardware, holding SCLx low

11:-19FIGURE

 

FAMILYPIC18F8722

TIMINGMODESLAVE C™

 

I

 

 

2

 

 

ADDRESS) BIT-10 (TRANSMISSION,

 

 

 

 

 

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