12.07.2015 Views

ATmega32A Datasheet - Sunrom Technologies

ATmega32A Datasheet - Sunrom Technologies

ATmega32A Datasheet - Sunrom Technologies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ATmega32A</strong>Table 20-2.Status Code(TWSR)Prescaler Bitsare 0TWEN must be set to enable the Two-wire Serial Interface, TWSTA must be written to one totransmit a START condition and TWINT must be written to one to clear the TWINT Flag. TheTWI will then test the Two-wire Serial Bus and generate a START condition as soon as the busbecomes free. After a START condition has been transmitted, the TWINT Flag is set by hardware,and the status code in TWSR will be $08 (See Table 20-2). In order to enter MT mode,SLA+W must be transmitted. This is done by writing SLA+W to TWDR. Thereafter the TWINT bitshould be cleared (by writing it to one) to continue the transfer. This is accomplished by writingthe following value to TWCR:TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIEValue 1 X 0 0 X 1 0 XWhen SLA+W have been transmitted and an acknowledgement bit has been received, TWINT isset again and a number of status codes in TWSR are possible. Possible status codes in mastermode are $18, $20, or $38. The appropriate action to be taken for each of these status codes isdetailed in Table 20-2.When SLA+W has been successfully transmitted, a data packet should be transmitted. This isdone by writing the data byte to TWDR. TWDR must only be written when TWINT is high. If not,the access will be discarded, and the Write Collision bit (TWWC) will be set in the TWCR Register.After updating TWDR, the TWINT bit should be cleared (by writing it to one) to continue thetransfer. This is accomplished by writing the following value to TWCR:TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIEValue 1 X 0 0 X 1 0 XThis scheme is repeated until the last byte has been sent and the transfer is ended by generatinga STOP condition or a repeated START condition. A STOP condition is generated by writingthe following value to TWCR:TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIEValue 1 X 0 1 X 1 0 XA REPEATED START condition is generated by writing the following value to TWCR:TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIEValue 1 X 1 0 X 1 0 XAfter a repeated START condition (state $10) the Two-wire Serial Interface can access thesame slave again, or a new slave without transmitting a STOP condition. Repeated STARTenables the master to switch between slaves, master transmitter mode and master receivermode without losing control of the bus.Status Codes for Master Transmitter ModeStatus of the Two-wire SerialBus and Two-wire Serial InterfaceHardware$08 A START condition has beentransmitted$10 A repeated START conditionhas been transmitted$18 SLA+W has been transmitted;ACK has been receivedTo/from TWDRApplication Software ResponseTo TWCRSTA STO TWINT TWEANext Action Taken by TWI HardwareLoad SLA+W 0 0 1 X SLA+W will be transmitted;ACK or NOT ACK will be receivedLoad SLA+W orLoad SLA+RLoad data byte orNo TWDR action orNo TWDR action orNo TWDR action000101000011111111XXXXXXSLA+W will be transmitted;ACK or NOT ACK will be receivedSLA+R will be transmitted;Logic will switch to Master Receiver modeData byte will be transmitted and ACK or NOT ACK willbe receivedRepeated START will be transmittedSTOP condition will be transmitted andTWSTO Flag will be ResetSTOP condition followed by a START condition will betransmitted and TWSTO Flag will be Reset8155C–AVR–02/11189

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!