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

PIC18F8722 FAMILY

19.4.14SLEEP OPERATION

While in Sleep mode, the I2C module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from Sleep (if the MSSP interrupt is enabled).

19.4.15EFFECTS OF A RESET

A Reset disables the MSSP module and terminates the current transfer.

19.4.16MULTI-MASTER MODE

In Multi-Master mode, the interrupt generation on the detection of the Start and Stop conditions allows the determination of when the bus is free. The Stop (P) and Start (S) bits are cleared from a Reset or when the MSSP module is disabled. Control of the I2C bus may be taken when the P bit (SSPxSTAT<4>) is set, or the bus is Idle, with both the S and P bits clear. When the bus is busy, enabling the MSSP interrupt will generate the interrupt when the Stop condition occurs.

In multi-master operation, the SDAx line must be monitored for arbitration to see if the signal level is the expected output level. This check is performed in hardware with the result placed in the BCLxIF bit.

The states where arbitration can be lost are:

Address Transfer

Data Transfer

A Start Condition

A Repeated Start Condition

An Acknowledge Condition

19.4.17MULTI -MASTER COMMUNICATION, BUS COLLISION AND BUS ARBITRATION

Multi-Master mode support is achieved by bus arbitration. When the master outputs address/data bits onto the SDAx pin, arbitration takes place when the master outputs a ‘1’ on SDAx, by letting SDAx float high and another master asserts a ‘0’. When the SCLx pin floats high, data should be stable. If the expected data on SDAx is a ‘1’ and the data sampled on the SDAx pin = 0, then a bus collision has taken place. The master will set the Bus Collision Interrupt Flag, BCLxIF and reset the I2C port to its Idle state (Figure 19-25).

If a transmit was in progress when the bus collision occurred, the transmission is halted, the BF flag is cleared, the SDAx and SCLx lines are deasserted and the SSPxBUF can be written to. When the user services the bus collision Interrupt Service Routine and if the I2C bus is free, the user can resume communication by asserting a Start condition.

If a Start, Repeated Start, Stop or Acknowledge condition was in progress when the bus collision occurred, the condition is aborted, the SDAx and SCLx lines are deasserted and the respective control bits in the SSPxCON2 register are cleared. When the user services the bus collision Interrupt Service Routine and if the I2C bus is free, the user can resume communication by asserting a Start condition.

The master will continue to monitor the SDAx and SCLx pins. If a Stop condition occurs, the SSPxIF bit will be set.

A write to the SSPxBUF will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred.

In Multi-Master mode, the interrupt generation on the detection of Start and Stop conditions allows the determination of when the bus is free. Control of the I2C bus can be taken when the P bit is set in the SSPxSTAT register, or the bus is Idle and the S and P bits are cleared.

FIGURE 19-25: BUS COLLISION TIMING FOR TRANSMIT AND ACKNOWLEDGE

SDAx

SCLx

Data changes

SDAx line pulled low

while SCLx = 0

by another source

 

 

 

 

 

 

SDAx released

 

 

 

 

 

 

 

 

 

 

by master

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample SDAx. While SCLx is high, data doesn’t match what is driven by the master.

Bus collision has occurred.

Set bus collision interrupt (BCLxIF)

BCLxIF

DS39646B-page 240

Preliminary

2004 Microchip Technology Inc.

PIC18F8722 FAMILY

19.4.17.1Bus Collision During a Start Condition

During a Start condition, a bus collision occurs if:

a)SDAx or SCLx are sampled low at the beginning of the Start condition (Figure 19-26).

b)SCLx is sampled low before SDAx is asserted low (Figure 19-27).

During a Start condition, both the SDAx and the SCLx pins are monitored.

If the SDAx pin is already low, or the SCLx pin is already low, then all of the following occur:

the Start condition is aborted,

the BCLxIF flag is set and

the MSSP module is reset to its inactive state (Figure 19-26).

The Start condition begins with the SDAx and SCLx pins deasserted. When the SDAx pin is sampled high, the Baud Rate Generator is loaded from SSPxADD<6:0> and counts down to ‘0’. If the SCLx pin is sampled low while SDAx is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ‘1’ during the Start condition.

If the SDAx pin is sampled low during this count, the BRG is reset and the SDAx line is asserted early (Figure 19-28). If, however, a ‘1’ is sampled on the SDAx pin, the SDAx pin is asserted low at the end of the BRG count. The Baud Rate Generator is then reloaded and counts down to ‘0’. If the SCLx pin is sampled as ‘0’ during this time, a bus collision does not occur. At the end of the BRG count, the SCLx pin is asserted low.

Note: The reason that bus collision is not a factor during a Start condition is that no two bus masters can assert a Start condition at the exact same time. Therefore, one master will always assert SDAx before the other. This condition does not cause a bus collision because the two masters must be allowed to arbitrate the first address following the Start condition. If the address is the same, arbitration must be allowed to continue into the data portion, Repeated Start or Stop conditions.

FIGURE 19-26: BUS COLLISION DURING START CONDITION (SDAx ONLY)

SDAx goes low before the SEN bit is set.

Set BCLxIF,

S bit and SSPxIF set because

SDAx = 0, SCLx = 1.

SDAx

SCLx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Set SEN, enable Start

 

 

SEN cleared automatically because of bus collision.

 

 

 

 

 

 

 

SEN

condition if SDAx = 1, SCLx = 1

 

 

MSSP module reset into Idle state.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx sampled low before

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Start condition. Set BCLxIF.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

S bit and SSPxIF set because

 

 

 

 

 

 

BCLxIF

SDAx = 0, SCLx = 1.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SSPxIF and BCLxIF are cleared in software

S

SSPxIF

SSPxIF and BCLxIF are cleared in software

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 241

PIC18F8722 FAMILY

FIGURE 19-27: BUS COLLISION DURING START CONDITION (SCLx = 0)

SDAx = 0, SCLx = 1

SDAx

SCLx

SEN

BCLxIF

TBRG TBRG

Set SEN, enable Start sequence if SDAx = 1, SCLx = 1

SCLx = 0 before SDAx = 0,

bus collision occurs. Set BCLxIF.

SCLx = 0 before BRG time-out, bus collision occurs. Set BCLxIF.

Interrupt cleared in software

S

0

0

 

SSPxIF

0

0

FIGURE 19-28: BRG RESET DUE TO SDAx ARBITRATION DURING START CONDITION

SDAx

SCLx

SEN

 

SDAx = 0, SCLx = 1

 

 

 

 

 

 

 

 

 

 

 

 

Set S

Set SSPxIF

 

Less than TBRG

 

 

 

 

 

 

 

 

 

 

 

 

TBRG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SDAx pulled low by other

 

master.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Reset BRG and assert SDAx.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

S

SCLx pulled low after BRG time-out

BCLxIF

S

SSPxIF

Set SEN, enable START

sequence if SDAx = 1, SCLx = 1

0

SDAx = 0, SCLx = 1,

 

 

Interrupts cleared

set SSPxIF

 

 

 

in software

 

 

DS39646B-page 242

Preliminary

2004 Microchip Technology Inc.

PIC18F8722 FAMILY

19.4.17.2Bus Collision During a Repeated Start Condition

During a Repeated Start condition, a bus collision occurs if:

a)A low level is sampled on SDAx when SCLx goes from low level to high level.

b)SCLx goes low before SDAx is asserted low, indicating that another master is attempting to transmit a data ‘1’.

When the user deasserts SDAx and the pin is allowed to float high, the BRG is loaded with SSPxADD<6:0> and counts down to ‘0’. The SCLx pin is then deasserted and when sampled high, the SDAx pin is sampled.

If SDAx is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ‘0’, Figure 19-29). If SDAx is sampled high, the BRG is reloaded and begins counting. If SDAx goes from high-to-low before the BRG times out, no bus collision occurs because no two masters can assert SDAx at exactly the same time.

If SCLx goes from high-to-low before the BRG times out and SDAx has not already been asserted, a bus collision occurs. In this case, another master is attempting to transmit a data ‘1’ during the Repeated Start condition (see Figure 19-30).

If, at the end of the BRG time-out, both SCLx and SDAx are still high, the SDAx pin is driven low and the BRG is reloaded and begins counting. At the end of the count, regardless of the status of the SCLx pin, the SCLx pin is driven low and the Repeated Start condition is complete.

FIGURE 19-29: BUS COLLISION DURING A REPEATED START CONDITION (CASE 1)

SDAx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SCLx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sample SDAx when SCLx goes high.

 

 

If SDAx = 0, set BCLxIF and release SDAx and SCLx.

RSEN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BCLxIF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Cleared in software

 

 

 

 

 

 

 

 

 

 

 

 

S

 

 

 

 

 

0

 

 

 

 

 

 

 

 

SSPxIF

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

FIGURE 19-30: BUS COLLISION DURING REPEATED START CONDITION (CASE 2)

TBRG TBRG

SDAx

 

 

 

SCLx

 

 

 

BCLxIF

 

SCLx goes low before SDAx,

 

 

 

set BCLxIF. Release SDAx and SCLx.

 

RSEN

 

 

 

 

 

 

S

 

 

 

 

 

 

SSPxIF

 

 

 

Interrupt cleared in software

0

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 243

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