SMART ARM-based Microcontrollers
AT13526: ASF Manual (SAM C21)
APPLICATION NOTE
Preface
The Atmel® Software Framework (ASF) is a collection of free embeddedsoftware for Atmel microcontroller devices. It simplifies the usage of Atmelproducts, providing an abstraction to the hardware and high-value middle-ware. ASF is designed to be used for evaluation, prototyping, design, andproduction phases. ASF is integrated in the Atmel Studio IDE with agraphical user interface or available as a standalone package for severalcommercial and open source compilers. This document describes the APIinterfaces to the low level ASF module drivers of the device.
For more information on ASF, refer to the online documentation at http://www.atmel.com/asf.
Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
http://www.atmel.com/asfhttp://www.atmel.com/asf
Table of Contents
Preface............................................................................................................................ 1
1. Software License..................................................................................................... 19
2. SAM Analog Comparator (AC) Driver......................................................................202.1. Prerequisites...............................................................................................................................202.2. Module Overview........................................................................................................................20
2.2.1. Driver Feature Macro Definition...................................................................................212.2.2. Window Comparators and Comparator Pairs.............................................................. 212.2.3. Positive and Negative Input MUXes............................................................................ 212.2.4. Output Filtering............................................................................................................ 212.2.5. Input Hysteresis........................................................................................................... 212.2.6. Single Shot and Continuous Sampling Modes............................................................ 222.2.7. Events..........................................................................................................................222.2.8. Physical Connection.................................................................................................... 22
2.3. Special Considerations...............................................................................................................232.4. Extra Information........................................................................................................................ 232.5. Examples....................................................................................................................................232.6. API Overview..............................................................................................................................24
2.6.1. Variable and Type Definitions...................................................................................... 242.6.2. Structure Definitions.................................................................................................... 242.6.3. Macro Definitions......................................................................................................... 262.6.4. Function Definitions..................................................................................................... 272.6.5. Enumeration Definitions...............................................................................................36
2.7. Extra Information for AC Driver.................................................................................................. 402.7.1. Acronyms.....................................................................................................................402.7.2. Dependencies..............................................................................................................402.7.3. Errata........................................................................................................................... 402.7.4. Module History.............................................................................................................40
2.8. Examples for AC Driver..............................................................................................................402.8.1. Quick Start Guide for AC - Basic................................................................................. 402.8.2. Quick Start Guide for AC - Callback............................................................................ 44
3. SAM Analog-to-Digital Converter (ADC) Driver.......................................................493.1. Prerequisites...............................................................................................................................493.2. Module Overview........................................................................................................................49
3.2.1. Sample Clock Prescaler.............................................................................................. 503.2.2. ADC Resolution........................................................................................................... 503.2.3. Conversion Modes.......................................................................................................503.2.4. Differential and Single-ended Conversion................................................................... 503.2.5. Sample Time................................................................................................................513.2.6. Averaging.....................................................................................................................513.2.7. Offset and Gain Correction.......................................................................................... 523.2.8. Pin Scan...................................................................................................................... 523.2.9. Window Monitor........................................................................................................... 52
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
2
3.2.10. Events..........................................................................................................................523.3. Special Considerations...............................................................................................................533.4. Extra Information........................................................................................................................ 533.5. Examples....................................................................................................................................533.6. API Overview..............................................................................................................................53
3.6.1. Variable and Type Definitions...................................................................................... 533.6.2. Structure Definitions.................................................................................................... 543.6.3. Macro Definitions......................................................................................................... 563.6.4. Function Definitions..................................................................................................... 573.6.5. Enumeration Definitions...............................................................................................68
3.7. Extra Information for ADC Driver................................................................................................733.7.1. Acronyms.....................................................................................................................733.7.2. Dependencies..............................................................................................................733.7.3. Errata........................................................................................................................... 743.7.4. Module History.............................................................................................................74
3.8. Examples for ADC Driver........................................................................................................... 743.8.1. Quick Start Guide for ADC - Basic...............................................................................743.8.2. Quick Start Guide for ADC - Callback..........................................................................763.8.3. Quick Start Guide for Using DMA with ADC/DAC....................................................... 80
4. SAM Brown Out Detector (BOD) Driver...................................................................874.1. Prerequisites...............................................................................................................................874.2. Module Overview........................................................................................................................874.3. Special Considerations...............................................................................................................874.4. Extra Information........................................................................................................................ 874.5. Examples....................................................................................................................................884.6. API Overview..............................................................................................................................88
4.6.1. Structure Definitions.................................................................................................... 884.6.2. Function Definitions..................................................................................................... 884.6.3. Enumeration Definitions...............................................................................................90
4.7. Extra Information for BOD Driver................................................................................................924.7.1. Acronyms.....................................................................................................................924.7.2. Dependencies..............................................................................................................924.7.3. Errata........................................................................................................................... 924.7.4. Module History.............................................................................................................92
4.8. Examples for BOD Driver........................................................................................................... 924.8.1. Quick Start Guide for BOD - Basic.............................................................................. 924.8.2. Application Use Case for BOD - Application................................................................94
5. SAM Configurable Custom Logic (CCL) Driver....................................................... 955.1. Prerequisites...............................................................................................................................955.2. Module Overview........................................................................................................................955.3. Special Considerations...............................................................................................................955.4. Extra Information........................................................................................................................ 955.5. Examples....................................................................................................................................965.6. API Overview..............................................................................................................................96
5.6.1. Structure Definitions.................................................................................................... 965.6.2. Function Definitions..................................................................................................... 975.6.3. Enumeration Definitions...............................................................................................99
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
3
5.7. Extra Information for CCL Driver.............................................................................................. 1015.7.1. Acronyms...................................................................................................................1015.7.2. Dependencies............................................................................................................1015.7.3. Errata......................................................................................................................... 1015.7.4. Module History...........................................................................................................101
5.8. Examples for CCL Driver..........................................................................................................1015.8.1. Quick Start Guide for CCL - Basic............................................................................. 102
6. SAM Digital-to-Analog (DAC) Driver......................................................................1066.1. Prerequisites.............................................................................................................................1066.2. Module Overview......................................................................................................................106
6.2.1. Conversion Range..................................................................................................... 1076.2.2. Conversion.................................................................................................................1076.2.3. Analog Output............................................................................................................1076.2.4. Events........................................................................................................................1086.2.5. Left and Right Adjusted Values..................................................................................1086.2.6. Clock Sources............................................................................................................108
6.3. Special Considerations.............................................................................................................1096.3.1. Output Driver............................................................................................................. 1096.3.2. Conversion Time........................................................................................................109
6.4. Extra Information...................................................................................................................... 1096.5. Examples..................................................................................................................................1096.6. API Overview............................................................................................................................109
6.6.1. Variable and Type Definitions.................................................................................... 1096.6.2. Structure Definitions.................................................................................................. 1096.6.3. Macro Definitions....................................................................................................... 1106.6.4. Function Definitions....................................................................................................1116.6.5. Enumeration Definitions.............................................................................................122
6.7. Extra Information for DAC Driver..............................................................................................1236.7.1. Acronyms...................................................................................................................1236.7.2. Dependencies............................................................................................................1246.7.3. Errata......................................................................................................................... 1246.7.4. Module History...........................................................................................................124
6.8. Examples for DAC Driver......................................................................................................... 1246.8.1. Quick Start Guide for DAC - Basic.............................................................................1246.8.2. Quick Start Guide for DAC - Callback........................................................................127
7. SAM Direct Memory Access Controller (DMAC) Driver.........................................1337.1. Prerequisites.............................................................................................................................1337.2. Module Overview......................................................................................................................133
7.2.1. Driver Feature Macro Definition.................................................................................1357.2.2. Terminology Used in DMAC Transfers.......................................................................1357.2.3. DMA Channels...........................................................................................................1357.2.4. DMA Triggers.............................................................................................................1357.2.5. DMA Transfer Descriptor........................................................................................... 1357.2.6. DMA Interrupts/Events...............................................................................................136
7.3. Special Considerations.............................................................................................................1367.4. Extra Information...................................................................................................................... 1367.5. Examples..................................................................................................................................136
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
4
7.6. API Overview............................................................................................................................1367.6.1. Variable and Type Definitions.................................................................................... 1367.6.2. Structure Definitions.................................................................................................. 1377.6.3. Macro Definitions....................................................................................................... 1397.6.4. Function Definitions................................................................................................... 1397.6.5. Enumeration Definitions.............................................................................................146
7.7. Extra Information for DMAC Driver...........................................................................................1497.7.1. Acronyms...................................................................................................................1497.7.2. Dependencies............................................................................................................1497.7.3. Errata......................................................................................................................... 1497.7.4. Module History...........................................................................................................149
7.8. Examples for DMAC Driver...................................................................................................... 1507.8.1. Quick Start Guide for Memory to Memory Data Transfer Using DMAC.....................150
8. SAM Divide and Square Root Accelerator (DIVAS) Driver.................................... 1548.1. Prerequisites.............................................................................................................................1548.2. Module Overview......................................................................................................................154
8.2.1. Overload Operation................................................................................................... 1548.2.2. Operand Size.............................................................................................................1558.2.3. Signed Division.......................................................................................................... 1558.2.4. Divide By Zero........................................................................................................... 1558.2.5. Unsigned Square Root.............................................................................................. 155
8.3. Special Considerations.............................................................................................................1558.4. Extra Information...................................................................................................................... 1558.5. Examples..................................................................................................................................1568.6. API Overview............................................................................................................................156
8.6.1. Structure Definitions.................................................................................................. 1568.6.2. Function Definitions................................................................................................... 156
8.7. Extra Information for DIVAS Driver...........................................................................................1608.7.1. Acronyms...................................................................................................................1608.7.2. Dependencies............................................................................................................1608.7.3. Errata......................................................................................................................... 1608.7.4. Module History...........................................................................................................160
8.8. Examples for DIVAS Driver...................................................................................................... 1608.8.1. Quick Start Guide for DIVAS - No Overload.............................................................. 1618.8.2. Quick Start Guide for DIVAS - Overload....................................................................164
9. SAM Event System (EVENTS) Driver................................................................... 1689.1. Prerequisites.............................................................................................................................1689.2. Module Overview......................................................................................................................168
9.2.1. Event Channels......................................................................................................... 1699.2.2. Event Users............................................................................................................... 1699.2.3. Edge Detection.......................................................................................................... 1699.2.4. Path Selection............................................................................................................1699.2.5. Physical Connection.................................................................................................. 1709.2.6. Configuring Events.................................................................................................... 170
9.3. Special Considerations.............................................................................................................1719.4. Extra Information...................................................................................................................... 1719.5. Examples..................................................................................................................................171
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
5
9.6. API Overview............................................................................................................................1719.6.1. Variable and Type Definitions.................................................................................... 1719.6.2. Structure Definitions.................................................................................................. 1719.6.3. Macro Definitions....................................................................................................... 1729.6.4. Function Definitions................................................................................................... 1729.6.5. Enumeration Definitions.............................................................................................181
9.7. Extra Information for EVENTS Driver.......................................................................................1829.7.1. Acronyms...................................................................................................................1829.7.2. Dependencies............................................................................................................1829.7.3. Errata......................................................................................................................... 1829.7.4. Module History...........................................................................................................182
9.8. Examples for EVENTS Driver...................................................................................................1829.8.1. Quick Start Guide for EVENTS - Basic......................................................................1829.8.2. Quick Start Guide for EVENTS - Interrupt Hooks...................................................... 185
10. SAM External Interrupt (EXTINT) Driver............................................................... 19110.1. Prerequisites.............................................................................................................................19110.2. Module Overview......................................................................................................................191
10.2.1. Logical Channels....................................................................................................... 19110.2.2. NMI Channels............................................................................................................ 19210.2.3. Input Filtering and Detection......................................................................................19210.2.4. Events and Interrupts.................................................................................................19210.2.5. Physical Connection.................................................................................................. 192
10.3. Special Considerations.............................................................................................................19310.4. Extra Information...................................................................................................................... 19310.5. Examples..................................................................................................................................19310.6. API Overview............................................................................................................................193
10.6.1. Variable and Type Definitions.................................................................................... 19310.6.2. Structure Definitions.................................................................................................. 19410.6.3. Macro Definitions....................................................................................................... 19510.6.4. Function Definitions................................................................................................... 19510.6.5. Enumeration Definitions.............................................................................................201
10.7. Extra Information for EXTINT Driver.........................................................................................20210.7.1. Acronyms...................................................................................................................20210.7.2. Dependencies............................................................................................................20310.7.3. Errata......................................................................................................................... 20310.7.4. Module History...........................................................................................................203
10.8. Examples for EXTINT Driver.................................................................................................... 20310.8.1. Quick Start Guide for EXTINT - Basic....................................................................... 20310.8.2. Quick Start Guide for EXTINT - Callback.................................................................. 205
11. SAM Frequency Meter (FREQM) Driver................................................................20811.1. Prerequisites.............................................................................................................................20811.2. Module Overview......................................................................................................................20811.3. Special Considerations.............................................................................................................20811.4. Extra Information...................................................................................................................... 20911.5. Examples..................................................................................................................................20911.6. API Overview............................................................................................................................209
11.6.1. Variable and Type Definitions.................................................................................... 209
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
6
11.6.2. Structure Definitions.................................................................................................. 20911.6.3. Function Definitions................................................................................................... 21011.6.4. Enumeration Definitions.............................................................................................214
11.7. Extra Information for FREQM Driver........................................................................................ 21511.7.1. Acronyms...................................................................................................................21511.7.2. Dependencies............................................................................................................21511.7.3. Errata......................................................................................................................... 21511.7.4. Module History...........................................................................................................215
11.8. Examples for FREQM Driver....................................................................................................21511.8.1. Quick Start Guide for FREQM - Basic....................................................................... 21611.8.2. Quick Start Guide for FREQM - Callback.................................................................. 218
12. SAM Non-Volatile Memory (NVM) Driver.............................................................. 22212.1. Prerequisites.............................................................................................................................22212.2. Module Overview......................................................................................................................222
12.2.1. Driver Feature Macro Definition.................................................................................22212.2.2. Memory Regions........................................................................................................22312.2.3. Region Lock Bits........................................................................................................22412.2.4. Read/Write.................................................................................................................224
12.3. Special Considerations.............................................................................................................22412.3.1. Page Erasure.............................................................................................................22412.3.2. Clocks........................................................................................................................ 22412.3.3. Security Bit.................................................................................................................224
12.4. Extra Information...................................................................................................................... 22512.5. Examples..................................................................................................................................22512.6. API Overview............................................................................................................................225
12.6.1. Structure Definitions.................................................................................................. 22512.6.2. Macro Definitions....................................................................................................... 22712.6.3. Function Definitions................................................................................................... 22712.6.4. Enumeration Definitions.............................................................................................234
12.7. Extra Information for NVM Driver............................................................................................. 23912.7.1. Acronyms...................................................................................................................23912.7.2. Dependencies............................................................................................................23912.7.3. Errata......................................................................................................................... 23912.7.4. Module History...........................................................................................................239
12.8. Examples for NVM Driver.........................................................................................................24012.8.1. Quick Start Guide for NVM - Basic............................................................................ 240
13. SAM Peripheral Access Controller (PAC) Driver................................................... 24313.1. Prerequisites.............................................................................................................................24313.2. Module Overview......................................................................................................................243
13.2.1. Locking Scheme........................................................................................................ 24313.2.2. Recommended Implementation.................................................................................24413.2.3. Why Disable Interrupts.............................................................................................. 24613.2.4. Run-away Code......................................................................................................... 24713.2.5. Faulty Module Pointer................................................................................................24913.2.6. Use of __no_inline..................................................................................................... 24913.2.7. Physical Connection.................................................................................................. 249
13.3. Special Considerations.............................................................................................................249
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
7
13.3.1. Non-Writable Registers..............................................................................................24913.3.2. Reading Lock State................................................................................................... 249
13.4. Extra Information...................................................................................................................... 25013.5. Examples..................................................................................................................................25013.6. API Overview............................................................................................................................250
13.6.1. Macro Definitions....................................................................................................... 25013.6.2. Function Definitions................................................................................................... 251
13.7. Extra Information for PAC Driver.............................................................................................. 25313.7.1. Acronyms...................................................................................................................25313.7.2. Dependencies............................................................................................................25413.7.3. Errata......................................................................................................................... 25413.7.4. Module History...........................................................................................................254
13.8. Examples for PAC Driver..........................................................................................................25413.8.1. Quick Start Guide for PAC - Basic............................................................................. 254
13.9. List of Non-Write Protected Registers...................................................................................... 256
14. SAM Port (PORT) Driver....................................................................................... 25914.1. Prerequisites.............................................................................................................................25914.2. Module Overview......................................................................................................................259
14.2.1. Driver Feature Macro Definition.................................................................................25914.2.2. Physical and Logical GPIO Pins................................................................................ 26014.2.3. Physical Connection.................................................................................................. 260
14.3. Special Considerations.............................................................................................................26014.4. Extra Information...................................................................................................................... 26014.5. Examples..................................................................................................................................26014.6. API Overview............................................................................................................................261
14.6.1. Structure Definitions.................................................................................................. 26114.6.2. Macro Definitions....................................................................................................... 26114.6.3. Function Definitions................................................................................................... 26214.6.4. Enumeration Definitions.............................................................................................268
14.7. Extra Information for PORT Driver........................................................................................... 26914.7.1. Acronyms...................................................................................................................26914.7.2. Dependencies............................................................................................................26914.7.3. Errata......................................................................................................................... 26914.7.4. Module History...........................................................................................................269
14.8. Examples for PORT Driver.......................................................................................................26914.8.1. Quick Start Guide for PORT - Basic.......................................................................... 270
15. SAM RTC Count (RTC COUNT) Driver.................................................................27215.1. Prerequisites.............................................................................................................................27215.2. Module Overview......................................................................................................................272
15.2.1. Driver Feature Macro Definition.................................................................................27315.3. Compare and Overflow.............................................................................................................273
15.3.1. Periodic Events..........................................................................................................27315.3.2. Digital Frequency Correction..................................................................................... 27415.3.3. RTC Tamper Detect................................................................................................... 274
15.4. Special Considerations.............................................................................................................27515.4.1. Clock Setup............................................................................................................... 275
15.5. Extra Information...................................................................................................................... 276
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
8
15.6. Examples..................................................................................................................................27615.7. API Overview............................................................................................................................276
15.7.1. Structure Definitions.................................................................................................. 27615.7.2. Macro Definitions....................................................................................................... 27715.7.3. Function Definitions................................................................................................... 27915.7.4. Enumeration Definitions.............................................................................................292
15.8. RTC Tamper Detect..................................................................................................................29615.9. Extra Information for RTC COUNT Driver................................................................................ 296
15.9.1. Acronyms...................................................................................................................29615.9.2. Dependencies............................................................................................................29715.9.3. Errata......................................................................................................................... 29715.9.4. Module History...........................................................................................................297
15.10. Examples for RTC (COUNT) Driver......................................................................................... 29715.10.1. Quick Start Guide for RTC (COUNT) - Basic.............................................................29815.10.2. Quick Start Guide for RTC (COUNT) - Callback........................................................30015.10.3. Quick Start Guide for RTC Tamper with DMA............................................................303
16. SAM RTC Calendar (RTC CAL) Driver..................................................................30716.1. Prerequisites.............................................................................................................................30716.2. Module Overview......................................................................................................................307
16.2.1. Driver Feature Macro Definition.................................................................................30816.2.2. Alarms and Overflow................................................................................................. 30816.2.3. Periodic Events..........................................................................................................30816.2.4. Digital Frequency Correction..................................................................................... 30916.2.5. RTC Tamper Detect................................................................................................... 309
16.3. Special Considerations.............................................................................................................30916.3.1. Year Limit...................................................................................................................30916.3.2. Clock Setup............................................................................................................... 310
16.4. Extra Information...................................................................................................................... 31116.5. Examples..................................................................................................................................31116.6. API Overview............................................................................................................................311
16.6.1. Structure Definitions...................................................................................................31116.6.2. Macro Definitions....................................................................................................... 31316.6.3. Function Definitions................................................................................................... 31416.6.4. Enumeration Definitions.............................................................................................327
16.7. RTC Tamper Detect..................................................................................................................33116.8. Extra Information for RTC (CAL) Driver....................................................................................332
16.8.1. Acronyms...................................................................................................................33216.8.2. Dependencies............................................................................................................33216.8.3. Errata......................................................................................................................... 33216.8.4. Module History...........................................................................................................332
16.9. Examples for RTC CAL Driver..................................................................................................33216.9.1. Quick Start Guide for RTC (CAL) - Basic...................................................................33316.9.2. Quick Start Guide for RTC (CAL) - Callback..............................................................335
17. SAM Sigma-Delta Analog-to-Digital Converter (SDADC) Driver........................... 34017.1. Prerequisites.............................................................................................................................34017.2. Module Overview......................................................................................................................340
17.2.1. Sample Clock.............................................................................................................340
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
9
17.2.2. Gain and Offset Correction........................................................................................ 34117.2.3. Window Monitor......................................................................................................... 34117.2.4. Events........................................................................................................................341
17.3. Special Considerations.............................................................................................................34117.4. Extra Information...................................................................................................................... 34117.5. Examples..................................................................................................................................34117.6. API Overview............................................................................................................................342
17.6.1. Variable and Type Definitions.................................................................................... 34217.6.2. Structure Definitions.................................................................................................. 34217.6.3. Macro Definitions....................................................................................................... 34417.6.4. Function Definitions................................................................................................... 34417.6.5. Enumeration Definitions.............................................................................................354
17.7. Extra Information for SDADC Driver.........................................................................................35617.7.1. Acronyms...................................................................................................................35617.7.2. Dependencies............................................................................................................35717.7.3. Errata......................................................................................................................... 35717.7.4. Module History...........................................................................................................357
17.8. Examples for SDADC Driver.................................................................................................... 35717.8.1. Quick Start Guide for SDADC - Basic........................................................................35717.8.2. Quick Start Guide for SDADC - Callback...................................................................359
18. SAM Serial USART (SERCOM USART) Driver.....................................................36318.1. Prerequisites.............................................................................................................................36318.2. Module Overview......................................................................................................................363
18.2.1. Driver Feature Macro Definition.................................................................................36418.2.2. Frame Format............................................................................................................ 36418.2.3. Synchronous Mode....................................................................................................36518.2.4. Asynchronous Mode.................................................................................................. 36518.2.5. Parity..........................................................................................................................36518.2.6. GPIO Configuration................................................................................................... 366
18.3. Special Considerations.............................................................................................................36618.4. Extra Information...................................................................................................................... 36618.5. Examples..................................................................................................................................36618.6. API Overview............................................................................................................................366
18.6.1. Variable and Type Definitions.................................................................................... 36618.6.2. Structure Definitions.................................................................................................. 36618.6.3. Macro Definitions....................................................................................................... 37018.6.4. Function Definitions................................................................................................... 37118.6.5. Enumeration Definitions.............................................................................................384
18.7. Extra Information for SERCOM USART Driver........................................................................ 39018.7.1. Acronyms...................................................................................................................39018.7.2. Dependencies............................................................................................................39018.7.3. Errata......................................................................................................................... 39118.7.4. Module History...........................................................................................................391
18.8. Examples for SERCOM USART Driver....................................................................................39118.8.1. Quick Start Guide for SERCOM USART - Basic....................................................... 39218.8.2. Quick Start Guide for SERCOM USART - Callback.................................................. 39418.8.3. Quick Start Guide for Using DMA with SERCOM USART.........................................39618.8.4. Quick Start Guide for SERCOM USART LIN.............................................................402
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
10
18.9. SERCOM USART MUX Settings..............................................................................................407
19. SAM I2C Master Mode (SERCOM I2C) Driver...................................................... 40819.1. Prerequisites.............................................................................................................................40819.2. Module Overview......................................................................................................................408
19.2.1. Driver Feature Macro Definition.................................................................................40919.2.2. Functional Description............................................................................................... 40919.2.3. Bus Topology............................................................................................................. 40919.2.4. Transactions.............................................................................................................. 41019.2.5. Multi Master................................................................................................................41119.2.6. Bus States................................................................................................................. 41219.2.7. Bus Timing................................................................................................................. 41219.2.8. Operation in Sleep Modes......................................................................................... 413
19.3. Special Considerations.............................................................................................................41319.3.1. Interrupt-driven Operation..........................................................................................413
19.4. Extra Information...................................................................................................................... 41319.5. Examples..................................................................................................................................41319.6. API Overview............................................................................................................................414
19.6.1. Structure Definitions.................................................................................................. 41419.6.2. Macro Definitions....................................................................................................... 41519.6.3. Function Definitions................................................................................................... 41619.6.4. Enumeration Definitions.............................................................................................430
19.7. Extra Information for SERCOM I2C Driver............................................................................... 43219.7.1. Acronyms...................................................................................................................43219.7.2. Dependencies............................................................................................................43219.7.3. Errata......................................................................................................................... 43219.7.4. Module History...........................................................................................................432
19.8. Examples for SERCOM I2C Driver........................................................................................... 43319.8.1. Quick Start Guide for SERCOM I2C Master - Basic.................................................. 43319.8.2. Quick Start Guide for SERCOM I2C Master - Callback............................................. 43619.8.3. Quick Start Guide for Using DMA with SERCOM I2C Master....................................439
20. SAM I2C Slave Mode (SERCOM I2C) Driver........................................................ 44420.1. Prerequisites.............................................................................................................................44420.2. Module Overview......................................................................................................................444
20.2.1. Driver Feature Macro Definition.................................................................................44520.2.2. Functional Description............................................................................................... 44520.2.3. Bus Topology............................................................................................................. 44520.2.4. Transactions.............................................................................................................. 44620.2.5. Multi Master............................................................................................................... 44720.2.6. Bus States................................................................................................................. 44820.2.7. Bus Timing................................................................................................................. 44820.2.8. Operation in Sleep Modes......................................................................................... 449
20.3. Special Considerations.............................................................................................................44920.3.1. Interrupt-driven Operation..........................................................................................449
20.4. Extra Information...................................................................................................................... 44920.5. Examples..................................................................................................................................44920.6. API Overview............................................................................................................................450
20.6.1. Structure Definitions.................................................................................................. 450
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
11
20.6.2. Macro Definitions....................................................................................................... 45120.6.3. Function Definitions................................................................................................... 45320.6.4. Enumeration Definitions.............................................................................................464
20.7. Extra Information for SERCOM I2C Driver............................................................................... 46620.7.1. Acronyms...................................................................................................................46620.7.2. Dependencies............................................................................................................46620.7.3. Errata......................................................................................................................... 46620.7.4. Module History...........................................................................................................466
20.8. Examples for SERCOM I2C Driver........................................................................................... 46620.8.1. Quick Start Guide for SERCOM I2C Slave - Basic.................................................... 46720.8.2. Quick Start Guide for SERCOM I2C Slave - Callback............................................... 46920.8.3. Quick Start Guide for Using DMA with SERCOM I2C Slave......................................472
21. SAM Serial Peripheral Interface (SERCOM SPI) Driver........................................47721.1. Prerequisites.............................................................................................................................47721.2. Module Overview......................................................................................................................477
21.2.1. Driver Feature Macro Definition.................................................................................47821.2.2. SPI Bus Connection...................................................................................................47821.2.3. SPI Character Size.................................................................................................... 47921.2.4. Master Mode..............................................................................................................47921.2.5. Slave Mode................................................................................................................47921.2.6. Data Modes............................................................................................................... 47921.2.7. SERCOM Pads..........................................................................................................48021.2.8. Operation in Sleep Modes......................................................................................... 48021.2.9. Clock Generation....................................................................................................... 480
21.3. Special Considerations.............................................................................................................48021.3.1. pinmux Settings......................................................................................................... 480
21.4. Extra Information...................................................................................................................... 48121.5. Examples..................................................................................................................................48121.6. API Overview............................................................................................................................481
21.6.1. Variable and Type Definitions.................................................................................... 48121.6.2. Structure Definitions.................................................................................................. 48121.6.3. Macro Definitions....................................................................................................... 48321.6.4. Function Definitions................................................................................................... 48421.6.5. Enumeration Definitions.............................................................................................499
21.7. Extra Information for SERCOM SPI Driver...............................................................................50321.7.1. Acronyms...................................................................................................................50321.7.2. Dependencies............................................................................................................50321.7.3. Workarounds Implemented by Driver........................................................................ 50321.7.4. Module History...........................................................................................................503
21.8. Examples for SERCOM SPI Driver.......................................................................................... 50421.8.1. Quick Start Guide for SERCOM SPI Master - Polled................................................ 50421.8.2. Quick Start Guide for SERCOM SPI Slave - Polled.................................................. 50721.8.3. Quick Start Guide for SERCOM SPI Master - Callback.............................................51021.8.4. Quick Start Guide for SERCOM SPI Slave - Callback...............................................51421.8.5. Quick Start Guide for Using DMA with SERCOM SPI............................................... 517
21.9. MUX Settings............................................................................................................................52721.9.1. Master Mode Settings................................................................................................52721.9.2. Slave Mode Settings..................................................................................................528
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
12
22. SAM System (SYSTEM) Driver............................................................................. 52922.1. Prerequisites.............................................................................................................................52922.2. Module Overview......................................................................................................................529
22.2.1. Voltage Regulator...................................................................................................... 52922.2.2. Voltage References................................................................................................... 52922.2.3. System Reset Cause................................................................................................. 53022.2.4. Sleep Modes..............................................................................................................530
22.3. Special Considerations.............................................................................................................53022.4. Extra Information...................................................................................................................... 53022.5. Examples..................................................................................................................................53122.6. API Overview............................................................................................................................531
22.6.1. Structure Definitions.................................................................................................. 53122.6.2. Function Definitions................................................................................................... 53122.6.3. Enumeration Definitions.............................................................................................536
22.7. Extra Information for SYSTEM Driver.......................................................................................53722.7.1. Acronyms...................................................................................................................53722.7.2. Dependencies............................................................................................................53722.7.3. Errata......................................................................................................................... 53722.7.4. Module History...........................................................................................................537
23. SAM System Clock Management (SYSTEM CLOCK) Driver................................53923.1. Prerequisites.............................................................................................................................53923.2. Module Overview......................................................................................................................539
23.2.1. Clock Sources............................................................................................................53923.2.2. CPU / Bus Clocks...................................................................................................... 54023.2.3. Clock Masking........................................................................................................... 54023.2.4. Generic Clocks.......................................................................................................... 540
23.3. Special Considerations.............................................................................................................54223.4. Extra Information...................................................................................................................... 54223.5. Examples..................................................................................................................................54223.6. API Overview............................................................................................................................542
23.6.1. Structure Definitions.................................................................................................. 54223.6.2. Function Definitions................................................................................................... 54723.6.3. Enumeration Definitions.............................................................................................562
23.7. Extra Information for SYSTEM CLOCK Driver......................................................................... 56923.7.1. Acronyms...................................................................................................................56923.7.2. Dependencies............................................................................................................56923.7.3. Errata......................................................................................................................... 56923.7.4. Module History...........................................................................................................569
23.8. Examples for System Clock Driver...........................................................................................57023.8.1. Quick Start Guide for SYSTEM CLOCK - Basic........................................................ 57023.8.2. Quick Start Guide for SYSTEM CLOCK - GCLK Configuration.................................572
24. SAM System Interrupt (SYSTEM INTERRUPT) Driver......................................... 57624.1. Prerequisites.............................................................................................................................57624.2. Module Overview......................................................................................................................576
24.2.1. Critical Sections......................................................................................................... 57624.2.2. Software Interrupts.................................................................................................... 576
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
13
24.3. Special Considerations.............................................................................................................57724.4. Extra Information...................................................................................................................... 57724.5. Examples..................................................................................................................................57724.6. API Overview............................................................................................................................577
24.6.1. Function Definitions................................................................................................... 57724.6.2. Enumeration Definitions.............................................................................................582
24.7. Extra Information for SYSTEM INTERRUPT Driver.................................................................59724.7.1. Acronyms...................................................................................................................59724.7.2. Dependencies............................................................................................................59724.7.3. Errata......................................................................................................................... 59724.7.4. Module History...........................................................................................................597
24.8. Examples for SYSTEM INTERRUPT Driver.............................................................................59824.8.1. Quick Start Guide for SYSTEM INTERRUPT - Critical Section Use Case................59824.8.2. Quick Start Guide for SYSTEM INTERRUPT - Enable Module Interrupt Use Case. 598
25. SAM System Pin Multiplexer (SYSTEM PINMUX) Driver..................................... 60025.1. Prerequisites.............................................................................................................................60025.2. Module Overview......................................................................................................................600
25.2.1. Driver Feature Macro Definition.................................................................................60025.2.2. Physical and Logical GPIO Pins................................................................................ 60025.2.3. Peripheral Multiplexing.............................................................................................. 60125.2.4. Special Pad Characteristics.......................................................................................60125.2.5. Physical Connection.................................................................................................. 601
25.3. Special Considerations.............................................................................................................60225.4. Extra Information...................................................................................................................... 60225.5. Examples..................................................................................................................................60225.6. API Overview............................................................................................................................602
25.6.1. Structure Definitions.................................................................................................. 60225.6.2. Macro Definitions....................................................................................................... 60325.6.3. Function Definitions................................................................................................... 60325.6.4. Enumeration Definitions.............................................................................................606
25.7. Extra Information for SYSTEM PINMUX Driver........................................................................60825.7.1. Acronyms...................................................................................................................60825.7.2. Dependencies............................................................................................................60825.7.3. Errata......................................................................................................................... 60825.7.4. Module History...........................................................................................................608
25.8. Examples for SYSTEM PINMUX Driver................................................................................... 60825.8.1. Quick Start Guide for SYSTEM PINMUX - Basic...................................................... 608
26. SAM Timer/Counter (TC) Driver............................................................................ 61126.1. Prerequisites.............................................................................................................................61126.2. Module Overview......................................................................................................................611
26.2.1. Driver Feature Macro Definition.................................................................................61326.2.2. Functional Description............................................................................................... 61326.2.3. Timer/Counter Size.................................................................................................... 61326.2.4. Clock Settings............................................................................................................61426.2.5. Compare Match Operations.......................................................................................61526.2.6. One-shot Mode.......................................................................................................... 617
26.3. Special Considerations.............................................................................................................617
Atmel AT13526: ASF Manual (SAM C21) [APPLICATION NOTE]Atmel-42698A-ASF-Manual-(SAMC21)_AT13526_Application Note-09/2016
14
26.4. Extra Information...................................................................................................................... 61826.5. Examples..................................................................................................................................61826.6. API Overview............................................................................................................................618
26.6.1. Variable and Type Definitions.................................................................................... 61826.6.2. Structure Definitions.................................................................................................. 61826.6.3. Macro Definitions....................................................................................................... 62126.6.4. Function Definitions................................................................................................... 62326.6.5. Enumeration Definitions.............................................................................................632
26.7. Extra Information for TC Driver.................................................................................................63526.7.1. Acronyms...................................................................................................................63526.7.2. Dependencies............................................................................................................63526.7.3. Errata......................................................................................................................... 63526.7.4. Module History...........................................................................................................635
26.8. Examples for TC Driver............................................................................................................ 63626.8.1. Quick Start Guide for TC - Basic............................................................................... 63626.8.2. Quick Start Guide for TC - Match Frequency Wave Generation................................63926.8.3. Quick Start Guide for TC - Timer............................................................................... 64126.8.4. Quick Start Guide for TC - Callback.......................................................................... 64426.8.5. Quick Start Guide for Using DMA with TC.................................................................648
27. SAM Timer Counter for Control Applications (TCC) Driver................................... 65527.1. Prerequisites.............................................................................................................................65527.2. Module Overview......................................................................................................................655
27.2.1. Functional Description............................................................................................... 65627.2.2. Base Timer/Counter...................................................................................................65727.2.3. Capture Operations................................................................................................... 65927.2.4. Compare Match Operation........................................................................................ 66027.2.5. Waveform Extended Controls.................................................................................... 66127.2.6. Double and Circular Buffering....................................................................................66327.2.7. Sleep Mode................................................................................................................663
27.3. Special Considerations.............................................................................................................66327.3.1. Driver Feature Macro Definition.................................................................................66327.3.2. Module Features........................................................................................................66327.3.3. Channels vs. Pinouts................................................................................................. 664
27.4. Extra Information...................................................................................................................... 66427.5. Examples..................................................................................................................................66427.6. API Overview............................................................................................................................664
27.6.1. Variable and Type Definitions.................................................................................... 66427.6.2. Structure Definitions.................................................................................................. 66527.6.3. Macro Definitions....................................................................................................... 67027.6.4. Function Definitions................................................................................................... 67227.6.5. Enumeration Definitions.............................................................................................687
27.7. Extra Information for TCC Driver..............................................................................................69727.7.1. Acronyms...................................................................................................................69727.7.2. Dependencies............................................................................................................69727.7.3. Errata......................................................................................................................... 69727.7.4. Module History...........................................................................................................697
27.8. Examples for TCC Driver..........................................................................................................69727.8.1.