ATmega8 (961730), страница 33
Текст из файла (страница 33)
Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)fosc = 11.0592 MHzfosc = 8.0000 MHzfosc = 14.7456 MHzBaudRate(bps)UBRRErrorUBRRErrorUBRRErrorUBRRErrorUBRRErrorUBRRError24002070.2%416-0.1%2870.0%5750.0%3830.0%7670.0%48001030.2%2070.2%1430.0%2870.0%1910.0%3830.0%9600510.2%1030.2%710.0%1430.0%950.0%1910.0%14.4k34-0.8%680.6%470.0%950.0%630.0%1270.0%19.2k250.2%510.2%350.0%710.0%470.0%950.0%28.8k162.1%34-0.8%230.0%470.0%310.0%630.0%38.4k120.2%250.2%170.0%350.0%230.0%470.0%57.6k8-3.5%162.1%110.0%230.0%150.0%310.0%76.8k6-7.0%120.2%80.0%170.0%110.0%230.0%115.2k38.5%8-3.5%50.0%110.0%70.0%150.0%230.4k18.5%38.5%20.0%50.0%30.0%70.0%250k10.0%30.0%2-7.8%5-7.8%3-7.8%65.3%0.5M00.0%10.0%––2-7.8%1-7.8%3-7.8%1M––00.0%––––0-7.8%1-7.8%Max1.158(1)U2X = 00.5 MbpsU2X = 11 MbpsU2X = 0691.2 kbpsU2X = 11.3824 MbpsU2X = 0921.6 kbpsU2X = 11.8432 MbpsUBRR = 0, Error = 0.0%ATmega8(L)2486O–AVR–10/04ATmega8(L)Table 63.
Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)fosc = 16.0000 MHzfosc = 18.4320 MHzfosc = 20.0000 MHzBaudRate(bps)UBRRErrorUBRRErrorUBRRErrorUBRRErrorUBRRErrorUBRRError2400416-0.1%8320.0%4790.0%9590.0%5200.0%10410.0%48002070.2%416-0.1%2390.0%4790.0%2590.2%5200.0%96001030.2%2070.2%1190.0%2390.0%1290.2%2590.2%14.4k680.6%138-0.1%790.0%1590.0%86-0.2%173-0.2%19.2k510.2%1030.2%590.0%1190.0%640.2%1290.2%28.8k34-0.8%680.6%390.0%790.0%420.9%86-0.2%38.4k250.2%510.2%290.0%590.0%32-1.4%640.2%57.6k162.1%34-0.8%190.0%390.0%21-1.4%420.9%76.8k120.2%250.2%140.0%290.0%151.7%32-1.4%115.2k8-3.5%162.1%90.0%190.0%10-1.4%21-1.4%230.4k38.5%8-3.5%40.0%90.0%48.5%10-1.4%250k30.0%70.0%4-7.8%82.4%40.0%90.0%0.5M10.0%30.0%––4-7.8%––40.0%1M00.0%10.0%––––––––Max1.U2X = 0(1)1 MbpsU2X = 12 MbpsU2X = 0U2X = 11.152 MbpsU2X = 02.304 MbpsU2X = 11.25 Mbps2.5 MbpsUBRR = 0, Error = 0.0%1592486O–AVR–10/04Two-wire SerialInterfaceFeatures••••••••••Two-wire Serial InterfaceBus DefinitionThe Two-wire Serial Interface (TWI) is ideally suited for typical microcontroller applications.
The TWI protocol allows the systems designer to interconnect up to 128 differentdevices using only two bi-directional bus lines, one for clock (SCL) and one for data(SDA). The only external hardware needed to implement the bus is a single pull-upresistor for each of the TWI bus lines. All devices connected to the bus have individualaddresses, and mechanisms for resolving bus contention are inherent in the TWIprotocol.Simple Yet Powerful and Flexible Communication Interface, only two Bus Lines NeededBoth Master and Slave Operation SupportedDevice can Operate as Transmitter or Receiver7-bit Address Space Allows up to 128 Different Slave AddressesMulti-master Arbitration SupportUp to 400 kHz Data Transfer SpeedSlew-rate Limited Output DriversNoise Suppression Circuitry Rejects Spikes on Bus LinesFully Programmable Slave Address with General Call SupportAddress Recognition Causes Wake-up When AVR is in Sleep ModeFigure 68.
TWI Bus InterconnectionVCCDevice 1Device 2Device 3........Device nR1R2SDASCLTWI TerminologyThe following definitions are frequently encountered in this section.Table 64. TWI Terminology160TermDescriptionMasterThe device that initiates and terminates a transmission. The Master alsogenerates the SCL clock.SlaveThe device addressed by a Master.TransmitterThe device placing data on the bus.ReceiverThe device reading data from the bus.ATmega8(L)2486O–AVR–10/04ATmega8(L)Electrical InterconnectionAs depicted in Figure 68, both bus lines are connected to the positive supply voltagethrough pull-up resistors.
The bus drivers of all TWI-compliant devices are open-drain oropen-collector. This implements a wired-AND function which is essential to the operation of the interface. A low level on a TWI bus line is generated when one or more TWIdevices output a zero. A high level is output when all TWI devices tri-state their outputs,allowing the pull-up resistors to pull the line high. Note that all AVR devices connected tothe TWI bus must be powered in order to allow any bus operation.The number of devices that can be connected to the bus is only limited by the buscapacitance limit of 400 pF and the 7-bit slave address space.
A detailed specification ofthe electrical characteristics of the TWI is given in “Two-wire Serial Interface Characteristics” on page 242. Two different sets of specifications are presented there, onerelevant for bus speeds below 100 kHz, and one valid for bus speeds up to 400 kHz.Data Transfer and FrameFormatTransferring BitsEach data bit transferred on the TWI bus is accompanied by a pulse on the clock line.The level of the data line must be stable when the clock line is high. The only exceptionto this rule is for generating start and stop conditions.Figure 69. Data ValiditySDASCLData StableData StableData ChangeSTART and STOP ConditionsThe Master initiates and terminates a data transmission. The transmission is initiatedwhen the Master issues a START condition on the bus, and it is terminated when theMaster issues a STOP condition.
Between a START and a STOP condition, the bus isconsidered busy, and no other master should try to seize control of the bus. A specialcase occurs when a new START condition is issued between a START and STOP condition. This is referred to as a REPEATED START condition, and is used when theMaster wishes to initiate a new transfer without relinquishing control of the bus. After aREPEATED START, the bus is considered busy until the next STOP.
This is identical tothe START behavior, and therefore START is used to describe both START andREPEATED START for the remainder of this datasheet, unless otherwise noted. Asdepicted below, START and STOP conditions are signalled by changing the level of theSDA line when the SCL line is high.1612486O–AVR–10/04Figure 70.
START, REPEATED START and STOP conditionsSDASCLSTARTAddress Packet FormatSTOPREPEATED STARTSTARTSTOPAll address packets transmitted on the TWI bus are 9 bits long, consisting of 7 addressbits, one READ/WRITE control bit and an acknowledge bit. If the READ/WRITE bit isset, a read operation is to be performed, otherwise a write operation should be performed. When a Slave recognizes that it is being addressed, it should acknowledge bypulling SDA low in the ninth SCL (ACK) cycle. If the addressed Slave is busy, or forsome other reason can not service the Master’s request, the SDA line should be lefthigh in the ACK clock cycle. The Master can then transmit a STOP condition, or aREPEATED START condition to initiate a new transmission. An address packet consisting of a slave address and a READ or a WRITE bit is called SLA+R or SLA+W,respectively.The MSB of the address byte is transmitted first.
Slave addresses can freely be allocated by the designer, but the address 0000 000 is reserved for a general call.When a general call is issued, all slaves should respond by pulling the SDA line low inthe ACK cycle. A general call is used when a Master wishes to transmit the same message to several slaves in the system. When the general call address followed by a Writebit is transmitted on the bus, all slaves set up to acknowledge the general call will pullthe SDA line low in the ack cycle.
The following data packets will then be received by allthe slaves that acknowledged the general call. Note that transmitting the general calladdress followed by a Read bit is meaningless, as this would cause contention if severalslaves started transmitting different data.All addresses of the format 1111 xxx should be reserved for future purposes.Figure 71. Address Packet FormatAddr MSBAddr LSBR/WACK789SDASCL12START162ATmega8(L)2486O–AVR–10/04ATmega8(L)Data Packet FormatAll data packets transmitted on the TWI bus are nine bits long, consisting of one databyte and an acknowledge bit.
During a data transfer, the Master generates the clock andthe START and STOP conditions, while the Receiver is responsible for acknowledgingthe reception. An Acknowledge (ACK) is signalled by the Receiver pulling the SDA linelow during the ninth SCL cycle. If the Receiver leaves the SDA line high, a NACK is signalled. When the Receiver has received the last byte, or for some reason cannot receiveany more bytes, it should inform the Transmitter by sending a NACK after the final byte.The MSB of the data byte is transmitted first.Figure 72.
Data Packet FormatData MSBData LSBACK89AggregateSDASDA fromTransmitterSDA fromReceiverSCL fromMaster127SLA+R/WCombining Address and DataPackets into a TransmissionSTOP, REPEATEDSTART or NextData ByteData ByteA transmission basically consists of a START condition, a SLA+R/W, one or more datapackets and a STOP condition. An empty message, consisting of a START followed bya STOP condition, is illegal. Note that the Wired-ANDing of the SCL line can be used toimplement handshaking between the Master and the Slave. The Slave can extend theSCL low period by pulling the SCL line low.
This is useful if the clock speed set up by theMaster is too fast for the Slave, or the Slave needs extra time for processing betweenthe data transmissions. The Slave extending the SCL low period will not affect the SCLhigh period, which is determined by the Master. As a consequence, the Slave canreduce the TWI data transfer speed by prolonging the SCL duty cycle.Figure 73 shows a typical data transmission. Note that several data bytes can be transmitted between the SLA+R/W and the STOP condition, depending on the softwareprotocol implemented by the application software.Figure 73. Typical Data TransmissionAddr MSBAddr LSBR/WACKData MSB7891Data LSBACK89SDASCL1START2SLA+R/W27Data ByteSTOP1632486O–AVR–10/04Multi-master BusThe TWI protocol allows bus systems with several masters.














