Скачиваний:
30
Добавлен:
04.03.2014
Размер:
3.14 Mб
Скачать

 

 

ATmega128

Table of Contents

Features................................................................................................

1

 

Pin Configurations...............................................................................

2

 

Overview...............................................................................................

2

 

Block Diagram ......................................................................................................

3

 

ATmega103 and ATmega128 Compatibility .........................................................

4

 

Pin Descriptions....................................................................................................

5

 

About Code Examples.........................................................................

7

 

AVR CPU Core .....................................................................................

8

 

Introduction ...........................................................................................................

8

 

Architectural Overview..........................................................................................

8

 

ALU – Arithmetic Logic Unit..................................................................................

9

 

Status Register .....................................................................................................

9

 

General Purpose Register File ...........................................................................

10

 

Stack Pointer ......................................................................................................

12

 

Instruction Execution Timing...............................................................................

13

 

Reset and Interrupt Handling..............................................................................

13

 

AVR ATmega128 Memories ..............................................................

16

 

In-System Reprogrammable Flash Program Memory ........................................

16

 

SRAM Data Memory...........................................................................................

17

 

EEPROM Data Memory......................................................................................

19

 

I/O Memory .........................................................................................................

24

 

External Memory Interface..................................................................................

24

 

System Clock and Clock Options ....................................................

34

 

Clock Systems and their Distribution ..................................................................

34

 

Clock Sources.....................................................................................................

35

 

Default Clock Source ..........................................................................................

35

 

Crystal Oscillator.................................................................................................

36

 

Low-frequency Crystal Oscillator ........................................................................

37

 

External RC Oscillator ........................................................................................

38

 

Calibrated Internal RC Oscillator ........................................................................

39

 

External Clock.....................................................................................................

40

 

Timer/Counter Oscillator.....................................................................................

41

 

Power Management and Sleep Modes.............................................

42

 

Idle Mode ............................................................................................................

43

 

ADC Noise Reduction Mode...............................................................................

43

 

Power-down Mode..............................................................................................

43

 

Power-save Mode...............................................................................................

43

 

Standby Mode.....................................................................................................

44

 

Extended Standby Mode ....................................................................................

44

 

 

i

2467M–AVR–11/04

 

 

Minimizing Power Consumption .........................................................................

45

System Control and Reset ................................................................

47

Internal Voltage Reference .................................................................................

52

Watchdog Timer .................................................................................................

52

Timed Sequences for Changing the Configuration of the Watchdog Timer .......

55

Interrupts ............................................................................................

57

Interrupt Vectors in ATmega128.........................................................................

57

I/O Ports..............................................................................................

63

Introduction .........................................................................................................

63

Ports as General Digital I/O ................................................................................

64

Alternate Port Functions .....................................................................................

68

Register Description for I/O Ports .......................................................................

84

External Interrupts.............................................................................

87

8-bit Timer/Counter0 with PWM and Asynchronous Operation ....

90

Overview.............................................................................................................

90

Timer/Counter Clock Sources.............................................................................

91

Counter Unit........................................................................................................

91

Output Compare Unit..........................................................................................

92

Compare Match Output Unit ...............................................................................

94

Modes of Operation ............................................................................................

95

Timer/Counter Timing Diagrams.........................................................................

99

8-bit Timer/Counter Register Description .........................................................

101

Asynchronous Operation of the Timer/Counter ................................................

104

Timer/Counter Prescaler...................................................................................

107

16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3).......

109

Overview...........................................................................................................

109

Accessing 16-bit Registers ...............................................................................

112

Timer/Counter Clock Sources...........................................................................

115

Counter Unit......................................................................................................

115

Input Capture Unit.............................................................................................

116

Output Compare Units ......................................................................................

118

Compare Match Output Unit .............................................................................

120

Modes of Operation ..........................................................................................

121

Timer/Counter Timing Diagrams.......................................................................

128

16-bit Timer/Counter Register Description .......................................................

131

Timer/Counter3, Timer/Counter2, and Timer/Counter1 Prescalers ...

142

8-bit Timer/Counter2 with PWM......................................................

144

ii ATmega128

2467M–AVR–11/04

ATmega128

Overview...........................................................................................................

144

Timer/Counter Clock Sources...........................................................................

145

Counter Unit......................................................................................................

145

Output Compare Unit........................................................................................

146

Compare Match Output Unit .............................................................................

148

Modes of Operation ..........................................................................................

149

Timer/Counter Timing Diagrams.......................................................................

154

8-bit Timer/Counter Register Description .....................................

156

Output Compare Modulator (OCM1C2)..........................................

160

Overview...........................................................................................................

160

Description........................................................................................................

160

Serial Peripheral Interface – SPI.....................................................

162

SS Pin Functionality..........................................................................................

166

Data Modes ......................................................................................................

169

USART ..............................................................................................

170

Overview...........................................................................................................

170

Clock Generation ..............................................................................................

172

Frame Formats .................................................................................................

175

USART Initialization..........................................................................................

176

Data Transmission – The USART Transmitter .................................................

177

Data Reception – The USART Receiver ..........................................................

180

Asynchronous Data Reception .........................................................................

184

Multi-processor Communication Mode .............................................................

187

USART Register Description ............................................................................

189

Examples of Baud Rate Setting........................................................................

194

Two-wire Serial Interface ................................................................

198

Features............................................................................................................

198

Two-wire Serial Interface Bus Definition...........................................................

198

Data Transfer and Frame Format .....................................................................

199

Multi-master Bus Systems, Arbitration and Synchronization ............................

201

Overview of the TWI Module ............................................................................

204

TWI Register Description..................................................................................

206

Using the TWI ...................................................................................................

209

Transmission Modes.........................................................................................

213

Multi-master Systems and Arbitration...............................................................

226

Analog Comparator .........................................................................

228

Analog Comparator Multiplexed Input ..............................................................

229

Analog to Digital Converter ............................................................

231

iii

2467M–AVR–11/04

Features............................................................................................................

231

Operation ..........................................................................................................

233

Starting a Conversion .......................................................................................

233

Prescaling and Conversion Timing ...................................................................

234

Changing Channel or Reference Selection ......................................................

236

ADC Noise Canceler.........................................................................................

237

ADC Conversion Result....................................................................................

242

JTAG Interface and On-chip Debug System .................................

248

Features............................................................................................................

248

Overview...........................................................................................................

248

Test Access Port – TAP....................................................................................

248

TAP Controller ..................................................................................................

250

Using the Boundary-scan Chain .......................................................................

251

Using the On-chip Debug System ....................................................................

251

On-chip Debug Specific JTAG Instructions ......................................................

252

On-chip Debug Related Register in I/O Memory ..............................................

253

Using the JTAG Programming Capabilities ......................................................

253

Bibliography ......................................................................................................

253

IEEE 1149.1 (JTAG) Boundary-scan................................................................

254

Features............................................................................................................

254

System Overview..............................................................................................

254

Data Registers ..................................................................................................

254

Boundary-scan Specific JTAG Instructions ......................................................

256

Boundary-scan Related Register in I/O Memory ..............................................

257

Boundary-scan Chain .......................................................................................

258

ATmega128 Boundary-scan Order...................................................................

268

Boundary-scan Description Language Files .....................................................

274

Boot Loader Support – Read-While-Write Self-Programming.....

275

Boot Loader Features .......................................................................................

275

Application and Boot Loader Flash Sections ....................................................

275

Read-While-Write and No Read-While-Write Flash Sections...........................

275

Boot Loader Lock Bits.......................................................................................

277

Entering the Boot Loader Program ...................................................................

278

Addressing the Flash During Self-Programming ..............................................

280

Self-Programming the Flash .............................................................................

281

Memory Programming.....................................................................

288

Program and Data Memory Lock Bits...............................................................

288

Fuse Bits...........................................................................................................

289

Signature Bytes ................................................................................................

291

Calibration Byte ................................................................................................

291

Parallel Programming Parameters, Pin Mapping, and Commands ..................

292

Parallel Programming .......................................................................................

294

Serial Downloading...........................................................................................

303

iv ATmega128

2467M–AVR–11/04

 

ATmega128

SPI Serial Programming Pin Mapping ..............................................................

303

Programming Via the JTAG Interface...............................................................

308

Electrical Characteristics................................................................

321

Absolute Maximum Ratings*.............................................................................

321

DC Characteristics............................................................................................

321

External Clock Drive Waveforms ......................................................................

322

External Clock Drive .........................................................................................

323

Two-wire Serial Interface Characteristics .........................................................

324

SPI Timing Characteristics ...............................................................................

325

ADC Characteristics .........................................................................................

327

External Data Memory Timing ..........................................................................

330

ATmega128 Typical Characteristics ..............................................

335

Register Summary ...........................................................................

364

Instruction Set Summary ................................................................

367

Ordering Information.......................................................................

370

Packaging Information ....................................................................

371

64A ...................................................................................................................

371

64M1.................................................................................................................

372

Errata ................................................................................................

373

ATmega128 Rev. I............................................................................................

373

ATmega128 Rev. H ..........................................................................................

374

ATmega128 Rev. G ..........................................................................................

375

ATmega128 Rev. F...........................................................................................

377

Datasheet Revision History ............................................................

379

Changes from Rev. 2467L-05/04 to Rev.

 

2467M-11/04.....................................................................................................

379

Changes from Rev. 2467K-03/04 to Rev.

 

2467L-05/04......................................................................................................

379

Changes from Rev. 2467J-12/03 to Rev.

 

2467K-03/04 .....................................................................................................

379

Changes from Rev. 2467I-09/03 to Rev.

 

2467J-12/03......................................................................................................

379

Changes from Rev. 2467H-02/03 to Rev. 2467I-09/03 ....................................

379

Changes from Rev. 2467G-09/02 to Rev. 2467H-02/03...................................

380

Changes from Rev. 2467F-09/02 to Rev. 2467G-09/02 ...................................

380

Changes from Rev. 2467E-04/02 to Rev. 2467F-09/02 ...................................

380

Changes from Rev. 2467D-03/02 to Rev. 2467E-04/02 ...................................

381

Changes from Rev. 2467C-02/02 to Rev. 2467D-03/02...................................

381

Changes from Rev. 2467B-09/01 to Rev. 2467C-02/02 ...................................

382

 

v

2467M–AVR–11/04

 

 

 

 

 

 

 

 

 

 

.................................................................................Table of Contents

i

vi ATmega128

2467M–AVR–11/04

Atmel Corporation

Atmel Operations

2325 Orchard Parkway

San Jose, CA 95131, USA

Tel: 1(408) 441-0311

Fax: 1(408) 487-2600

Regional Headquarters

Europe

Atmel Sarl

Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland

Tel: (41) 26-426-5555 Fax: (41) 26-426-5500

Asia

Room 1219

Chinachem Golden Plaza

77 Mody Road Tsimshatsui

East Kowloon

Hong Kong

Tel: (852) 2721-9778

Fax: (852) 2722-1369

Japan

9F, Tonetsu Shinkawa Bldg.

1-24-8 Shinkawa

Chuo-ku, Tokyo 104-0033

Japan

Tel: (81) 3-3523-3551

Fax: (81) 3-3523-7581

Memory

2325 Orchard Parkway

San Jose, CA 95131, USA

Tel: 1(408) 441-0311

Fax: 1(408) 436-4314

Microcontrollers

2325 Orchard Parkway

San Jose, CA 95131, USA

Tel: 1(408) 441-0311

Fax: 1(408) 436-4314

La Chantrerie

BP 70602

44306 Nantes Cedex 3, France

Tel: (33) 2-40-18-18-18

Fax: (33) 2-40-18-19-60

ASIC/ASSP/Smart Cards

Zone Industrielle

13106 Rousset Cedex, France

Tel: (33) 4-42-53-60-00

Fax: (33) 4-42-53-60-01

1150 East Cheyenne Mtn. Blvd.

Colorado Springs, CO 80906, USA

Tel: 1(719) 576-3300

Fax: 1(719) 540-1759

Scottish Enterprise Technology Park

Maxwell Building

East Kilbride G75 0QR, Scotland

Tel: (44) 1355-803-000

Fax: (44) 1355-242-743

RF/Automotive

Theresienstrasse 2

Postfach 3535

74025 Heilbronn, Germany

Tel: (49) 71-31-67-0

Fax: (49) 71-31-67-2340

1150 East Cheyenne Mtn. Blvd.

Colorado Springs, CO 80906, USA

Tel: 1(719) 576-3300

Fax: 1(719) 540-1759

Biometrics/Imaging/Hi-Rel MPU/

High Speed Converters/RF Datacom

Avenue de Rochepleine

BP 123

38521 Saint-Egreve Cedex, France

Tel: (33) 4-76-58-30-00

Fax: (33) 4-76-58-34-80

Literature Requests

www.atmel.com/literature

Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-

TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.

© Atmel Corporation 2004. All rights reserved. Atmel®, logo and combinations thereof, AVR®, and AVR Studio® are registered trademarks, and Everywhere You AreSM are the trademarks of Atmel Corporation or its subsidiaries. Microsoft®, Windows®, Windows NT®, and Windows XP® are the registered trademarks of Microsoft Corporation. Other terms and product names may be trademarks of others.

Printed on recycled paper.

2467M–AVR–11/04

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