temperature logger with the tinyavr® 1-series and sd...

25
AN2543 AVR42780: Temperature Logger with ATtiny817 and SD Card-v2 Features Supported by all Microchip AVR ® devices with the required peripherals (TWI, SPI, RTC) Reusable modules for other applications SD card FAT file system access specifically for devices with limited available memory TWI Master driver AT30TSE75x temperature sensor driver Using the RTC and predefined GCC macros for keeping track of real time Introduction This application note describes the implementation of a temperature logger demonstrating the use of several peripherals of the tinyAVR ® 1-series. The TWI peripheral is used to communicate with a Microchip AT30TSE digital temperature sensor. The asynchronous RTC module is used to generate a timestamp for each temperature measurement and the data is written to an SD card via an SPI interface using the ELM- Chan Petit FAT file system library. The example code can be used with either an ATtiny817 Xplained Pro or an ATtiny817 Xplained Mini (with some modifications; see the Required Hardware chapter for more information), and an I/O1 Xplained Pro Extension Kit. It is possible to reuse parts of the code for other applications requiring SD card file system access, using the TWI module in master mode, interfacing with an AT30TSE temperature sensor, or using the RTC to keep track of real time. © 2018 Microchip Technology Inc. Application Note DS00002543B-page 1

Upload: lydung

Post on 27-Jun-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • AN2543 AVR42780: Temperature Logger with ATtiny817 and SD

    Card-v2

    Features

    Supported by all Microchip AVR devices with the required peripherals (TWI, SPI, RTC) Reusable modules for other applications SD card FAT file system access specifically for devices with limited available memory TWI Master driver AT30TSE75x temperature sensor driver Using the RTC and predefined GCC macros for keeping track of real time

    Introduction

    This application note describes the implementation of a temperature logger demonstrating the use ofseveral peripherals of the tinyAVR 1-series. The TWI peripheral is used to communicate with a MicrochipAT30TSE digital temperature sensor. The asynchronous RTC module is used to generate a timestamp foreach temperature measurement and the data is written to an SD card via an SPI interface using the ELM-Chan Petit FAT file system library. The example code can be used with either an ATtiny817 Xplained Proor an ATtiny817 Xplained Mini (with some modifications; see the Required Hardware chapter for moreinformation), and an I/O1 Xplained Pro Extension Kit. It is possible to reuse parts of the code for otherapplications requiring SD card file system access, using the TWI module in master mode, interfacing withan AT30TSE temperature sensor, or using the RTC to keep track of real time.

    2018 Microchip Technology Inc. Application Note DS00002543B-page 1

  • Table of Contents

    Features.......................................................................................................................... 1

    Introduction......................................................................................................................1

    1. Relevant Devices.......................................................................................................41.1. tinyAVR 0-Series.........................................................................................................................41.2. tinyAVR 1-Series.........................................................................................................................41.3. megaAVR 0-Series..................................................................................................................... 5

    2. TWI for Temperature Sensor Interfacing................................................................... 62.1. Floating Point Values with vfprintf for AVR................................................................................... 62.2. Buffer Construction.......................................................................................................................6

    3. Using the RTC for Real Time Tracking...................................................................... 73.1. Predefined Macros for Time Initialization..................................................................................... 93.2. RTC for Time Stamping of Temperature Measurements............................................................10

    4. Petit FAT File System...............................................................................................114.1. Petit FatFs Limitations................................................................................................................ 114.2. SPI for SD Card Interfacing........................................................................................................ 114.3. Preparing an SD Card for use with Petit FatFs.......................................................................... 124.4. SD Card Disk I/O Layer for AVR................................................................................................ 12

    5. Required Hardware................................................................................................. 135.1. Changing Operating Voltage on the ATtiny817 Xplained Mini....................................................135.2. Mounting the I/O1 Xplained Pro Extension Kit onto the ATtiny817 Xplained Mini......................15

    6. Get Source Code from Atmel | START.................................................................... 196.1. Configuration of Accompanying Code........................................................................................196.2. Example Output..........................................................................................................................19

    7. Revision History.......................................................................................................21

    The Microchip Web Site................................................................................................ 22

    Customer Change Notification Service..........................................................................22

    Customer Support......................................................................................................... 22

    Microchip Devices Code Protection Feature................................................................. 22

    Legal Notice...................................................................................................................23

    Trademarks................................................................................................................... 23

    Quality Management System Certified by DNV.............................................................24

    AN2543

    2018 Microchip Technology Inc. Application Note DS00002543B-page 2

  • Worldwide Sales and Service........................................................................................25

    AN2543

    2018 Microchip Technology Inc. Application Note DS00002543B-page 3

  • 1. Relevant DevicesThis chapter lists the relevant devices for this document.

    1.1 tinyAVR 0-SeriesThe figure below shows the tinyAVR 0-series, laying out pin count variants and memory sizes:

    Vertical migration is possible without code modification, as these devices are fully pin- and featurecompatible.

    Horizontal migration to the left reduces the pin count and therefore the available features.

    Figure 1-1.tinyAVR 0-Series Overview

    8 14 20 24Pins

    Flash

    16 KB

    8 KB

    4 KB

    2 KB

    ATtiny1607

    ATtiny807

    ATtiny1606

    ATtiny806

    ATtiny1604

    ATtiny804

    ATtiny402

    ATtiny202

    ATtiny404

    ATtiny204

    ATtiny406

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    1.2 tinyAVR 1-SeriesThe figure below shows the tinyAVR 1-series devices, illustrating pin count variants and memory sizes.

    Vertical migration upwards is possible without code modification, as these devices are pincompatible and provide the same or more features. Downward migration may require codemodification due to fewer available instances of some peripherals.

    Horizontal migration to the left reduces the pin count and therefore the available features.

    AN2543Relevant Devices

    2018 Microchip Technology Inc. Application Note DS00002543B-page 4

  • Figure 1-2.tinyAVR 1-Series Device Overview

    32KB

    16KB

    8KB

    4KB

    2KB

    8 14 20 24Pins

    Flash

    ATtiny816 ATtiny817ATtiny814

    ATtiny417

    ATtiny1616 ATtiny1617

    ATtiny414 ATtiny416ATtiny412

    ATtiny214ATtiny212

    ATtiny1614

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    1.3 megaAVR 0-SeriesFigure 1-3 shows the feature compatible devices in the megaAVR device family, including pinout variantsand memory variants.

    Vertical migration is possible without code modification, as these devices are fully pin and featurecompatible.

    Horizontal migration to the left reduces the pin count and therefore the available features.

    Figure 1-3.Device Family Overview

    48KB

    32KB

    16KB

    8KB

    4KB

    28/32 48Pins

    Flash

    ATmega3208

    ATmega4808

    ATmega3209

    ATmega4809

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    AN2543Relevant Devices

    2018 Microchip Technology Inc. Application Note DS00002543B-page 5

  • 2. TWI for Temperature Sensor InterfacingThe accompanying code to this application note provides a driver for use of an AT30TSE temperaturesensor, which depends on the TWI master driver, which is also provided. Using these drivers, theconfiguration of the TWI and temperature sensor is very simple:

    The pin location of the TWI module should be checked and if necessary, the alternate pin locationselected in the PORTMUX peripheral

    Initialize the temperature sensor (requires an already defined TWI master variable)

    Note: An ISR should be defined for the TWI Master interrupt vector (TWI0_TWIM_vect), which calls theTWI Master Interrupt handler function. This is required to complete a TWI transaction.

    Note: If using a device with more than one TWI module and TWI0 is not the desired module to use forthe temperature sensor, certain symbols should be defined, refer to 'at30tse75x.c'.

    2.1 Floating Point Values with vfprintf for AVRThe default implementation of vfprintf and its variants for AVR devices does not include floating pointconversions, for the purpose of decreasing code compile size. One option is to use linker options toinclude support for floating point values as seen here*, but it should be kept in mind that this will require asignificant amount of extra memory, which may not be available in devices with small memories. Anotheroption, which is used in this application note, is to perform calculations on the floating point value to givethe integer and fraction parts to the desired number of decimal places and treat both parts as integerswith a decimal point in between in the character string.

    Note: * http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html.

    2.2 Buffer ConstructionThe function to read temperature uses a double precision floating point argument for loading thetemperature into, but for the purposes of buffer construction using sprintf, the integer and fraction partsare both treated like integers, as mentioned above. This buffer also includes a time stamp, by using theRTC.

    AN2543TWI for Temperature Sensor Interfacing

    2018 Microchip Technology Inc. Application Note DS00002543B-page 6

    http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.htmlhttp://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html
  • 3. Using the RTC for Real Time TrackingThe RTC peripheral can be used to keep track of real time. The period is configurable, so it is notnecessary to generate an interrupt every second; this enables a decrease in power consumption. Anoverflow need only be generated when the current time is required e.g. for time stamp generation. Theperiod can be changed from anywhere between one second to more than 18 hours.

    Note: Ideally, this method requires that an accurate oscillator is connected to the TOSC pins and thenecessary oscillator design considerations have been adhered to. The Significant error is introducedwhen the oscillator used as the RTC clock source has low accuracy. For the purposes of demonstration,the available oscillators on the Xplained Pro and Mini kits are used. However, in practice, these may notbe accurate enough.

    The RTC should be configured as follows:

    Note: Because the RTC and the CPU run asynchronously, the STATUS register of the RTC should beused to verify synchronization of register settings before moving on.

    The required oscillator should be enabled in the CLKCTRL module and selected as the RTC clocksource (ideally a highly accurate 32.768 kHz oscillator)

    The RTC should be allowed to run in standby The prescaler should be set to an appropriate value, to give a count increment once per second

    (e.g. for a 32.768 kHz oscillator, choose DIV32768) The period should be set to the desired overflow interval The RTC interrupt flags should be cleared and the overflow interrupt enabled Finally, the RTC should be enabled to start counting

    Additionally, an ISR should be defined for the RTC overflow interrupt vector (RTC_CNT_vect), tocomplete the time update and any other required periodic tasks such as a sensor measurement and timestamp string generation. Two subroutines are used to update the time. They use a time struct as definedbelow.

    typedef struct{ uint8_t second; uint8_t minute; uint8_t hour; uint8_t date; uint8_t month; uint16_t year;}time;

    The 'update time' subroutine increments the 'second' by the defined number of seconds in the period, andchecks for the necessity to increment the higher value members, i.e. 'minute' is incremented if 'second' islarger than or equal to 60, and so on. The complete functionality of the subroutine is depicted in the figurebelow.

    AN2543Using the RTC for Real Time Tracking

    2018 Microchip Technology Inc. Application Note DS00002543B-page 7

  • Figure 3-1.Update Time Subroutine

    Hour = 24?

    Date++Hour = 0

    N

    N

    N

    Y

    Y

    Y

    N

    N

    N

    N

    N

    Y

    Y

    Y

    Y

    Y

    Update time

    Second += Period

    Second >= 60?

    Minute++Second -= 60

    Minute = 60?

    Hour++Minute = 0

    Date = 31? & Month = 4,6,9,11?

    Date = 32?

    Date = 30? & Month = 2?

    Date = 29? & Month = 2? &

    not_a_leap_year?

    Month++Date = 1

    Month = 13?

    Year++Month = 1

    End

    AN2543Using the RTC for Real Time Tracking

    2018 Microchip Technology Inc. Application Note DS00002543B-page 8

  • The 'not a leap year?' subroutine is used by the 'update time' subroutine when checking whether 'month'needs to be incremented during February. It returns true if it is not a leap year, i.e. February has 28 days,and false if it is a leap year, i.e. February has 29 days. Its calculations can be seen in the figure below.

    Figure 3-2.Leap Year Check Subroutine

    Not a leap year?

    Year divisible by 100?

    Year divisible by 400?

    Return FALSE(leap year)

    N

    Y

    Year divisible by 4?

    Return TRUE(not a leap year)

    Return FALSE(leap year)

    Return TRUE(not a leap year)

    Y

    N

    Y

    N

    3.1 Predefined Macros for Time InitializationWhen using the RTC to generate a time stamp, there is a necessity for a correct initial time. Instead ofmanually entering the initial value of the time struct, it is possible to use predefined GCC macros forapplication compilation date and time. It should be noted that a fresh compilation must be completedimmediately before flashing the device. If there is a delay between compilation and flashing, the initialtime will be incorrect, and therefore also the generated time stamp. As can be seen here*, there arestrings defined as follows, which can be processed accordingly into the predefined time struct members:

    AN2543Using the RTC for Real Time Tracking

    2018 Microchip Technology Inc. Application Note DS00002543B-page 9

    https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
  • __DATE__ string, of the format "Feb 12 1996" for date, month, and year __TIME__ string, of the format "23:59:01" for hour, minute, and second

    Note: * https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html.

    3.2 RTC for Time Stamping of Temperature MeasurementsIn this application note, the RTC is used to keep track of real time in order to take a temperaturemeasurement at defined intervals and generate a corresponding time stamp. In this case, a flag "tick" israised to indicate that the subroutine "tock" should be called from the main while loop. This is doneinstead of calling "tock" directly from the ISR to ensure that the procedure does not have interrupt priority.The TWI module used to interface with the temperature sensor requires an interrupt to completeoperation; this means a deadlock may occur from an interrupt being generated inside another interrupt iftheir respective priorities are not correctly configured. In the given example, the "tock" subroutine is calledfrom the main loop for simplicity, and therefore the configuration of interrupt priorities is not necessary.The functionality of the "tock" subroutine includes taking a temperature measurement, updating the time,and sending the updated buffer to the SD card.

    AN2543Using the RTC for Real Time Tracking

    2018 Microchip Technology Inc. Application Note DS00002543B-page 10

    https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
  • 4. Petit FAT File SystemAn SD card is a very convenient way to store large amounts of non-volatile data. A file system isgenerally used to allow the data to be portable and easily accessible from a PC. An industry standard,widely used file system is FAT. Many AVR applications require optimized usage of flash memory andSRAM; when only limited interfacing is needed or insufficient resources are available, a normal FAT filesystem module may be unsuitable, hence the need for the subset Petit FAT file system module (PetitFatFs), available from ELM-ChaN*. It is specifically designed for 8-bit microcontrollers such as AVR 8-bitmicrocontrollers, and enable basic interfacing with an FAT file system formatted MMC or SD card whilerequiring limited resources. It is platform independent and so requires a lower disk I/O layer to befunctional, but sample drivers are available.

    The functionality provided by the Petit FatFs library includes: Mounting a volume with a FAT file system Opening a file Read a file Write to a file (with some restrictions) Move R/W pointer Open a directory Read a directory item

    Configuration regarding inclusion or exclusion of any function is defined in the configuration header file(pffconf.h), in order to minimize compile size.

    Note: *http://elm-chan.org/fsw/ff/00index_p.html.

    4.1 Petit FatFs LimitationsPetitfs specifically uses as little flash and stack as possible. This, however, comes at the expense ofsome functionality. Files are not able to be created or increased in size, and only one file can beaccessed at a time. The mode of sector access is limited in terms of efficiency, and therefore there aresignificant periods where the SDC/MMC is busy. This busy period occurs for every partial sector accessoperation, so in applications where an entire sector cannot be read or written at once, the maximumaccess frequency further decreases.

    4.2 SPI for SD Card InterfacingControl of multimedia and SD cards without a native host interface is possible by using the card's SPImode. The communication protocol is relatively simple, as described in detail here (http://elm-chan.org/docs/mmc/mmc_e.html) by ELM-Chan. It is possible to use an AVR SPI peripheral for this with ease. Thenecessary configuration for SD card initialization is as follows:

    The desired pin locations should be checked, and the alternate location selected, if necessary, inthe PORTMUX peripheral

    The MOSI, CS, SCK pin directions should be set as output A pull-up should be enabled on the MISO pin (the SD card DO pin - this is very important

    specifically for SD cards; without it, they will fail to initialize) Master SPI mode should be enabled

    AN2543Petit FAT File System

    2018 Microchip Technology Inc. Application Note DS00002543B-page 11

    http://elm-chan.org/fsw/ff/00index_p.htmlhttp://elm-chan.org/fsw/ff/00index_p.htmlhttp://elm-chan.org/docs/mmc/mmc_e.htmlhttp://elm-chan.org/docs/mmc/mmc_e.htmlhttp://elm-chan.org/docs/mmc/mmc_e.html
  • An SPI prescaler should be selected to result in a frequency between 100 and 400 kHz (this is alsovery important for SD card initialization). This will vary depending on the peripheral clock frequency.More information can be found in the device data sheet CLKCTRL chapter.

    Buffer mode should be enabled to make flags available for transmit and receive complete Wait for Receive should be enabled to allow data to go directly to the shift register The slave select line should be disabled (this should be controlled by software) SPI Mode 0 (default setting, recommended) or SPI Mode 3 (will work in most cases) should be

    selected Finally, the SPI should be enabled

    After initialization, the SPI clock prescaler and 2X setting can be changed to result in a faster SPI clock.

    4.3 Preparing an SD Card for use with Petit FatFsThe write function of Petit FatFs is unable to create files or expand the size of files that already exist.Therefore, before starting to use an SD card with Petit FatFs, it is necessary to first insert it into a PC,format it to FAT file system, and create a file of the desired size, with a known name.

    4.4 SD Card Disk I/O Layer for AVRThe disk I/O layer code for AVR used in this application note (diskio_avr.c) is a modified version of asample file available from ELM-Chan*. The SD card settings described above are included in theinitialization routine. The hash defines for SPI pins and the functions for SPI initialization, transmit, andreceive should be reviewed for use with a device other than the tinyAVR 1-series and modified ifnecessary. Use of the Petitfs library is demonstrated in the 'init_sd_card()' and 'send_buffer()' functions inthe main file.

    Note: * http://elm-chan.org/fsw/ff/pfsample.zip

    Note: File read is not used in this application, so its functionality has been disabled in the 'pffconf.h' fileto save memory.

    AN2543Petit FAT File System

    2018 Microchip Technology Inc. Application Note DS00002543B-page 12

    http://elm-chan.org/fsw/ff/pfsample.ziphttp://elm-chan.org/fsw/ff/pfsample.zip
  • 5. Required HardwareIn order to use the example code for this application note on an ATtiny817 Xplained Pro, simply connectthe I/O1 Xplained Pro Extension kit to extension header 1 (EXT 1).

    In order to use an ATtiny817 Xplained Mini instead of an Xplained Pro, a few modifications are necessary,as described below.

    5.1 Changing Operating Voltage on the ATtiny817 Xplained MiniThe ATtiny817 Xplained Mini has a default VCC of 5V. Many extension kits require 3.3V; in order to enablethe boards to communicate effectively, they need to operate at the same voltage. It is possible to changethe operating voltage on the Xplained Mini with only a few steps. Figure ATtiny817 Xplained Mini PowerSupply Circuitry Schematic shows the schematic for the power supply circuitry on the Xplained Mini. Byremoving the 0 resistor R100, and making the 3.3V connection outlined in figure ATtiny817 XplainedMini Supply Voltage Choices, the operating voltage will be changed from 5V to 3.3V.

    Figure 5-1.ATtiny817 Xplained Mini Power Supply Circuitry Schematic

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 13

  • Figure 5-2.ATtiny817 Xplained Mini Supply Voltage Choices

    R100 Remove thisResistorVCC

    VCC

    3V3 5V0

    ORMake this

    connectionfor 3.3V VCC

    Make thisconnectionfor 5V VCC

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 14

  • 5.2 Mounting the I/O1 Xplained Pro Extension Kit onto the ATtiny817 Xplained MiniThe figure below shows the finished hardware modifications with the I/O1 Xplained Pro Extension Kitmounted. In order to mount it like this, it is necessary to solder a 2x10 100mil pin header, pull up resistorson the I2C lines, and strap wires to connect the relevant pins to the pin header.

    Figure 5-3.Finished Hardware Modifications with I/O1 Xplained Pro Extension Kit

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 15

  • The required connections for this project include SPI (for interfacing with the SD card), I2C (for TWIcommunication with the temperature sensor), LED (because the one on the Xplained Mini uses the samepin as SPI_SCK), power, and ground. These connections can be seen in figure Strap Wire ConnectionsFinished (see below), and are indicated more clearly in the figure Strap Wire Connections to Mount I/O1Xplained Pro Extension Kit (see further below). The boxes indicate the color of the wire in the photo andwhere there are multiple wires of the same color, a number indicates which two boxes match. The yellowboxes with an asterisk (e.g. 1*) indicate the connection should be made with a resistor (the ones used inthe photo are 2.7 k).

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 16

  • Figure 5-4.Strap Wire Connections Finished

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 17

  • Figure 5-5.Strap Wire Connections to Mount I/O1 Xplained Pro Extension Kit

    2*

    2*

    *

    SPI

    I2C

    GPIO(LED)

    GND

    VCC

    Resistor

    1 12

    1

    1

    1

    1

    2

    2

    2

    1*

    1*

    3 34 4

    3

    3

    2

    2

    AN2543Required Hardware

    2018 Microchip Technology Inc. Application Note DS00002543B-page 18

  • 6. Get Source Code from Atmel | STARTThe example code is available through Atmel | START, which is a web-based tool that enablesconfiguration of application code through a Graphical User Interface (GUI). The code can be downloadedfor both Atmel Studio 7.0 and IAR Embedded Workbench via the direct example code-link(s) below orthe BROWSE EXAMPLES button on the Atmel | START front page.

    Atmel | START web page: http://microchip.com/start

    Example Code

    AVR42780 Temperature Logger: http://start.atmel.com/#example/Atmel%3Atemp_logger%3A1.0.0%3A%3AApplication

    %3AAVR42780_Temperature_Logger%3A

    Press User guide in Atmel | START for details and information about example projects. The User guidebutton can be found in the example browser, and by clicking the project name in the dashboard viewwithin the Atmel | START project configurator.

    Atmel Studio

    Download the code as an .atzip file for Atmel Studio from the example browser in Atmel | START, byclicking DOWNLOAD SELECTED EXAMPLE. To download the file from within Atmel | START, clickEXPORT PROJECT followed by DOWNLOAD PACK.

    Double-click the downloaded .atzip file and the project will be imported to Atmel Studio 7.0.

    IAR Embedded Workbench

    For information on how to import the project in IAR Embedded Workbench, open the Atmel | START userguide, select Using Atmel Start Output in External Tools, and IAR Embedded Workbench. A link to theAtmel | START user guide can be found by clicking About from the Atmel | START front page or Help AndSupport within the project configurator, both located in the upper right corner of the page.

    6.1 Configuration of Accompanying CodeThe accompanying code to this application note enables easy reconfiguration of the sample period. Inorder to change it from the default value of 30 seconds, all that needs to be done is change the hashdefine "SAMPLE_PERIOD" at the top of the main file. This value can be changed to any value between 1and 65535 seconds (more than 18 hours).

    If an ATtiny817 Xplained Mini is being used, change the hash define "MINI_BOARD" from "false" to"true". This affects the LED output pin and the clock source for the RTC.

    6.2 Example OutputThe output format of the example project can be seen in the figure below. This example is with the settingSAMPLE_PERIOD set to 2 (seconds).

    AN2543Get Source Code from Atmel | START

    2018 Microchip Technology Inc. Application Note DS00002543B-page 19

    http://www.microchip.com/starthttp://start.atmel.com/#example/Atmel%3Atemp_logger%3A1.0.0%3A%3AApplication%3AAVR42780_Temperature_Logger%3Ahttp://start.atmel.com/#example/Atmel%3Atemp_logger%3A1.0.0%3A%3AApplication%3AAVR42780_Temperature_Logger%3A
  • Figure 6-1.Example Output of the Temperature Logger Demo

    AN2543Get Source Code from Atmel | START

    2018 Microchip Technology Inc. Application Note DS00002543B-page 20

  • 7. Revision HistoryDoc. Rev. Date Comments

    B 02/2018 Chapter "Relevant Devices" has been updated to include tinyAVR 0-series andmegaAVR 0-series

    A 09/2017 Converted to Microchip format and replaced the Atmel document number"42780A".

    Added Relevant Devices for tinyAVR 1-series Updated Required Hardware

    42780A 10/2016 Initial document release

    AN2543Revision History

    2018 Microchip Technology Inc. Application Note DS00002543B-page 21

  • The Microchip Web Site

    Microchip provides online support via our web site at http://www.microchip.com/. This web site is used asa means to make files and information easily available to customers. Accessible by using your favoriteInternet browser, the web site contains the following information:

    Product Support Data sheets and errata, application notes and sample programs, designresources, users guides and hardware support documents, latest software releases and archivedsoftware

    General Technical Support Frequently Asked Questions (FAQ), technical support requests,online discussion groups, Microchip consultant program member listing

    Business of Microchip Product selector and ordering guides, latest Microchip press releases,listing of seminars and events, listings of Microchip sales offices, distributors and factoryrepresentatives

    Customer Change Notification Service

    Microchips customer notification service helps keep customers current on Microchip products.Subscribers will receive e-mail notification whenever there are changes, updates, revisions or erratarelated to a specified product family or development tool of interest.

    To register, access the Microchip web site at http://www.microchip.com/. Under Support, click onCustomer Change Notification and follow the registration instructions.

    Customer Support

    Users of Microchip products can receive assistance through several channels:

    Distributor or Representative Local Sales Office Field Application Engineer (FAE) Technical Support

    Customers should contact their distributor, representative or Field Application Engineer (FAE) for support.Local sales offices are also available to help customers. A listing of sales offices and locations is includedin the back of this document.

    Technical support is available through the web site at: http://www.microchip.com/support

    Microchip Devices Code Protection Feature

    Note the following details of the code protection feature on Microchip devices:

    Microchip products meet the specification contained in their particular Microchip Data Sheet. Microchip believes that its family of products is one of the most secure families of its kind on the

    market today, when used in the intended manner and under normal conditions. There are dishonest and possibly illegal methods used to breach the code protection feature. All of

    these methods, to our knowledge, require using the Microchip products in a manner outside theoperating specifications contained in Microchips Data Sheets. Most likely, the person doing so isengaged in theft of intellectual property.

    Microchip is willing to work with the customer who is concerned about the integrity of their code.

    AN2543

    2018 Microchip Technology Inc. Application Note DS00002543B-page 22

    http://www.microchip.com/http://www.microchip.com/http://www.microchip.com/support
  • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of theircode. Code protection does not mean that we are guaranteeing the product as unbreakable.

    Code protection is constantly evolving. We at Microchip are committed to continuously improving thecode protection features of our products. Attempts to break Microchips code protection feature may be aviolation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your softwareor other copyrighted work, you may have a right to sue for relief under that Act.

    Legal Notice

    Information contained in this publication regarding device applications and the like is provided only foryour convenience and may be superseded by updates. It is your responsibility to ensure that yourapplication meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS ORWARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORYOR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITSCONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE.Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in lifesupport and/or safety applications is entirely at the buyers risk, and the buyer agrees to defend,indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resultingfrom such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectualproperty rights unless otherwise stated.

    Trademarks

    The Microchip name and logo, the Microchip logo, AnyRate, AVR, AVR logo, AVR Freaks, BeaconThings,BitCloud, CryptoMemory, CryptoRF, dsPIC, FlashFlex, flexPWR, Heldo, JukeBlox, KeeLoq, KeeLoq logo,Kleer, LANCheck, LINK MD, maXStylus, maXTouch, MediaLB, megaAVR, MOST, MOST logo, MPLAB,OptoLyzer, PIC, picoPower, PICSTART, PIC32 logo, Prochip Designer, QTouch, RightTouch, SAM-BA,SpyNIC, SST, SST Logo, SuperFlash, tinyAVR, UNI/O, and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the U.S.A. and other countries.

    ClockWorks, The Embedded Control Solutions Company, EtherSynch, Hyper Speed Control, HyperLightLoad, IntelliMOS, mTouch, Precision Edge, and Quiet-Wire are registered trademarks of MicrochipTechnology Incorporated in the U.S.A.

    Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BodyCom,chipKIT, chipKIT logo, CodeGuard, CryptoAuthentication, CryptoCompanion, CryptoController,dsPICDEM, dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit SerialProgramming, ICSP, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, Mindi, MiWi,motorBench, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, OmniscientCode Generation, PICDEM, PICDEM.net, PICkit, PICtail, PureSilicon, QMatrix, RightTouch logo, REALICE, Ripple Blocker, SAM-ICE, Serial Quad I/O, SMART-I.S., SQI, SuperSwitcher, SuperSwitcher II, TotalEndurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA aretrademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

    SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

    Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries.

    GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary ofMicrochip Technology Inc., in other countries.

    All other trademarks mentioned herein are property of their respective companies.

    AN2543

    2018 Microchip Technology Inc. Application Note DS00002543B-page 23

  • 2018, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

    ISBN: 978-1-5224-2543-4

    Quality Management System Certified by DNV

    ISO/TS 16949Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and waferfabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in Californiaand India. The Companys quality system processes and procedures are for its PIC MCUs and dsPIC

    DSCs, KEELOQ code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory andanalog products. In addition, Microchips quality system for the design and manufacture of developmentsystems is ISO 9001:2000 certified.

    AN2543

    2018 Microchip Technology Inc. Application Note DS00002543B-page 24

  • AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPECorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200Fax: 480-792-7277Technical Support:http://www.microchip.com/supportWeb Address:www.microchip.comAtlantaDuluth, GATel: 678-957-9614Fax: 678-957-1455Austin, TXTel: 512-257-3370BostonWestborough, MATel: 774-760-0087Fax: 774-760-0088ChicagoItasca, ILTel: 630-285-0071Fax: 630-285-0075DallasAddison, TXTel: 972-818-7423Fax: 972-818-2924DetroitNovi, MITel: 248-848-4000Houston, TXTel: 281-894-5983IndianapolisNoblesville, INTel: 317-773-8323Fax: 317-773-5453Tel: 317-536-2380Los AngelesMission Viejo, CATel: 949-462-9523Fax: 949-462-9608Tel: 951-273-7800Raleigh, NCTel: 919-844-7510New York, NYTel: 631-435-6000San Jose, CATel: 408-735-9110Tel: 408-436-4270Canada - TorontoTel: 905-695-1980Fax: 905-695-2078

    Australia - SydneyTel: 61-2-9868-6733China - BeijingTel: 86-10-8569-7000China - ChengduTel: 86-28-8665-5511China - ChongqingTel: 86-23-8980-9588China - DongguanTel: 86-769-8702-9880China - GuangzhouTel: 86-20-8755-8029China - HangzhouTel: 86-571-8792-8115China - Hong Kong SARTel: 852-2943-5100China - NanjingTel: 86-25-8473-2460China - QingdaoTel: 86-532-8502-7355China - ShanghaiTel: 86-21-3326-8000China - ShenyangTel: 86-24-2334-2829China - ShenzhenTel: 86-755-8864-2200China - SuzhouTel: 86-186-6233-1526China - WuhanTel: 86-27-5980-5300China - XianTel: 86-29-8833-7252China - XiamenTel: 86-592-2388138China - ZhuhaiTel: 86-756-3210040

    India - BangaloreTel: 91-80-3090-4444India - New DelhiTel: 91-11-4160-8631India - PuneTel: 91-20-4121-0141Japan - OsakaTel: 81-6-6152-7160Japan - TokyoTel: 81-3-6880- 3770Korea - DaeguTel: 82-53-744-4301Korea - SeoulTel: 82-2-554-7200Malaysia - Kuala LumpurTel: 60-3-7651-7906Malaysia - PenangTel: 60-4-227-8870Philippines - ManilaTel: 63-2-634-9065SingaporeTel: 65-6334-8870Taiwan - Hsin ChuTel: 886-3-577-8366Taiwan - KaohsiungTel: 886-7-213-7830Taiwan - TaipeiTel: 886-2-2508-8600Thailand - BangkokTel: 66-2-694-1351Vietnam - Ho Chi MinhTel: 84-28-5448-2100

    Austria - WelsTel: 43-7242-2244-39Fax: 43-7242-2244-393Denmark - CopenhagenTel: 45-4450-2828Fax: 45-4485-2829Finland - EspooTel: 358-9-4520-820France - ParisTel: 33-1-69-53-63-20Fax: 33-1-69-30-90-79Germany - GarchingTel: 49-8931-9700Germany - HaanTel: 49-2129-3766400Germany - HeilbronnTel: 49-7131-67-3636Germany - KarlsruheTel: 49-721-625370Germany - MunichTel: 49-89-627-144-0Fax: 49-89-627-144-44Germany - RosenheimTel: 49-8031-354-560Israel - RaananaTel: 972-9-744-7705Italy - MilanTel: 39-0331-742611Fax: 39-0331-466781Italy - PadovaTel: 39-049-7625286Netherlands - DrunenTel: 31-416-690399Fax: 31-416-690340Norway - TrondheimTel: 47-7289-7561Poland - WarsawTel: 48-22-3325737Romania - BucharestTel: 40-21-407-87-50Spain - MadridTel: 34-91-708-08-90Fax: 34-91-708-08-91Sweden - GothenbergTel: 46-31-704-60-40Sweden - StockholmTel: 46-8-5090-4654UK - WokinghamTel: 44-118-921-5800Fax: 44-118-921-5820

    Worldwide Sales and Service

    2018 Microchip Technology Inc. Application Note DS00002543B-page 25

    FeaturesIntroductionTable of Contents1.Relevant Devices1.1.tinyAVR 0-Series1.2.tinyAVR 1-Series1.3.megaAVR 0-Series2.TWI for Temperature Sensor Interfacing2.1.Floating Point Values with vfprintf for AVR2.2.Buffer Construction3.Using the RTC for Real Time Tracking3.1.Predefined Macros for Time Initialization3.2.RTC for Time Stamping of Temperature Measurements4.Petit FAT File System4.1.Petit FatFs Limitations4.2.SPI for SD Card Interfacing4.3.Preparing an SD Card for use with Petit FatFs4.4.SD Card Disk I/O Layer for AVR5.Required Hardware5.1.Changing Operating Voltage on the ATtiny817 Xplained Mini5.2.Mounting the I/O1 Xplained Pro Extension Kit onto the ATtiny817 Xplained Mini6.Get Source Code from Atmel | START6.1.Configuration of Accompanying Code6.2.Example Output7.Revision HistoryThe Microchip Web SiteCustomer Change Notification ServiceCustomer SupportMicrochip Devices Code Protection FeatureLegal NoticeTrademarksQuality Management System Certified by DNVWorldwide Sales and Service