TB3239 JSON Decoder for PIC® and AVR® Devices

Introduction

Author: Alexandru Niculae, Microchip Technology Inc.

This document describes the use and implementation of a JSON subset decoder, aimed for embedded devices such as PIC® and AVR® microcontrollers. The decoder translates the string format of a JSON object into a C data structure representation. This way programmers can access the key-value pairs. Using JSON objects makes it easy to interconnect applications. The JSON Decoder code is available on GitHub.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 1 TB3239

Table of Contents

Introduction...... 1

1. Overview...... 3

2. API...... 4

3. Implementation...... 7 3.1. Input Buffer...... 7 3.2. Decoding...... 7 3.3. Internal Representation...... 8 3.4. Encoding...... 9

4. Demo: Controlling the Four LEDs on AVR-IoT from the PC...... 10 4.1. Instructions...... 10

5. Demo: Generic Cloud Communication with an IoT Node...... 15

6. Appendix...... 16

The Microchip Website...... 18

Product Change Notification Service...... 18

Customer Support...... 18

Microchip Devices Code Protection Feature...... 18

Legal Notice...... 18

Trademarks...... 19

Quality Management System...... 19

Worldwide Sales and Service...... 20

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 2 TB3239 Overview

1. Overview JSON is the most used data format on the web and on desktop applications. Since it has an implementation in virtually all modern , it is the perfect tool for data interchange between applications. It has a text format that is easy for humans to read and write and easy for machines to parse and generate. A JSON object is a set of key-value pairs. While keys can only be strings, values can be a lot of things. This decoder implementation supports string, number, and object values. Note: To keep this library suited for low-memory devices, only a subset of features was selected to be implemented, therefore, array, boolean, and null values are not supported. The following block of code shows an example usage of this decoder. Section 2. API describes the API functions in detail.

#define TEST_JSON "{\"main\":{\"key\" : 10,\"foo\":\"bar\"}, \"alt\":2}"

...

jsonNode_t *root, *objmain; char str[64], foo[10]; int alt;

memcpy(str, TEST_JSON, sizeof(TEST_JSON));

JSON_DECODER_fromString(str)

JSON_DECODER_getRoot(&root); JSON_DECODER_getObject(root, "main", &objmain);

JSON_DECODER_getNumber(root, "alt", &alt) JSON_DECODER_getString(objmain, "foo", sizeof(foo), foo)

Note: The outermost object in a JSON is called the root.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 3 TB3239 API

2. API Refer to this section for detailed explanation of the public functions in the JSON Decoder.

jsonDecoderStatus_t JSON_DECODER_fromString(char *str)

Description Parses a JSON string into a C representation. It supports string, number, and object values.

Parameters

Name Description str Pointer to an existing string representation of a JSON object. After parsing, the string will have been altered.

Return Value

Name Description JSON_DECODER_OK Decoding was successful JSON_DECODER_BAD_FORMAT The input is invalid

JSON_DECODER_getRoot(jsonNode_t **pNode)

Description Finds the outermost object in the JSON, called the root. This function must not be called before JSON_DECODER_fromString.

Parameters

Name Description

pNode Pointer to a jsonNode_t

Return Value

Name Description

JSON_DECODER_OK pNode now points to the root

jsonDecoderStatus_t JSON_DECODER_getObject(jsonNode_t *current, char *key, jsonNode_t **pNode)

Description Finds a JSON object by key in another JSON object. This function must not be called before JSON_DECODER_fromString.

Parameters

Name Description

current Pointer to a jsonNode_t

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 4 TB3239 API

...... continued Name Description key The key of the object to find pNode Pointer to the object, if found

Return Value

Name Description

JSON_DECODER_OK Object was found and pNode now points to it JSON_DECODER_KEY_NOT_FOUND The specified key does not

jsonDecoderStatus_t JSON_DECODER_getString(jsonNode_t *current, char *key, uint8_t size, char *pVal)

Description Finds a string by key in a JSON object. This function must not be called before JSON_DECODER_fromString.

Parameters

Name Description current The JSON object to search into key The key of the string to find size Maximum size of the string. Should not be bigger than the length of the pVal buffer pVal Pointer to the string, if found

Return Value

Name Description

JSON_DECODER_OK String was found and pVal now points to it JSON_DECODER_KEY_NOT_FOUND The specified key does not exist

jsonDecoderStatus_t JSON_DECODER_getNumber(jsonNode_t *current, char *key, int *pVal)

Description Finds a number by key in a JSON object. This function must not be called before JSON_DECODER_fromString.

Parameters

Name Description current The JSON object to search into key The key of the string to find pVal Pointer to the number, if found

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 5 TB3239 API

Return Value

Name Description

JSON_DECODER_OK Number was found and pVal now points to it JSON_DECODER_KEY_NOT_FOUND The specified key does not exist

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 6 TB3239 Implementation

3. Implementation This section describes the implementation details with the purpose of facilitating the in-depth understanding of the code. Moreover, it describes some decisions made to optimize the memory usage and implementation safety. For example, because using recursion is not recommended, a part of the algorithm was refactored.

3.1 Input Buffer The input buffer is the buffer in which the JSON string is received, by an MQTT library, a UART driver or by other communication method. This buffer will be passed to the JSON Decoder using the JSON_DECODER_parseString function. When this function returns, the buffer’s content will have been modified. To use as little memory as possible, the internal JSON object representation does not hold any strings, but holds pointers to where the strings were originally located in the input buffer. Therefore, null terminators are inserted into that buffer to isolate the strings. All the keys and the string values are inside the input buffer. Figure 3-1. String Buffer { "" f o o " : " b a r " }

JSON_DECODER_parseString

{ " f o o \0 : " b a r \0 }

jsonNode->key jsonNode->value

An important consequence is that care must be taken not to rewrite the buffer before the JSON data is consumed. If the buffer is rewritten in between the JSON_DECODE_parseString and accessing the JSON structure, this will corrupt the data.

3.2 Decoding Decoding means transforming the string format of the JSON object into a C data structure representation. This is a grammar parsing problem and it is usually solved in a two-step process: lexing and parsing. Lexing splits the input text into tokens, as well as stripping out spare characters, such as white spaces. Tokens are both single charter (curly braces, , colons) and multicharacter (strings, numbers). This implementation uses a “lazy lexer”, meaning that instead of creating the list of all the tokens, they are retrieved one by one as needed by the parser. The parser verifies that the sequence of tokens makes sense in the context of the JSON grammar. It constructs the internal representation into a C data structure. The parser is inherently recursive in nature because it deals with nested JSON objects. To avoid recursion (and possible stack overflow errors), the algorithm was refactored to use a heap stack and a while loop, instead of the actual stack.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 7 TB3239 Implementation

Figure 3-2. JSON Decoder HLD

JSON string

JSON Decoder

Request token

Nonrecursive Parser Lazy Lexer Return next token

JSON object in C representation

3.3 Internal Representation After parsing the string format, the JSON object is stored in the memory as a -like structure. Using the API functions, the tree nodes are traversed to retrieve values by key name. Each node corresponds to a key and can either be a leaf node (it has a string or number value) or an object node. Figure 3-3 shows a JSON object and its representation as a tree of jsonNode_t structures. The node structure has a type field, a key field, a value field, and two pointer fields to adjacent nodes. The h pointer points to the next key in the same JSON object and the v pointer points to the first own key, if the current node is of type object. Figure 3-3. Internal Representation

Type: LEAF Type: LEAF Type: OBJECT h Key: "myNum" h Key: "myString" Key: "myObject" Value: 0 { Value: "hello" "myObject": { "myNum": 10, "myString": "hi", v }, "myNum": 0, "myString": "hello", } Type: LEAF Type: LEAF Key: "myNum" h Key: "myString" Value: 10 Value: "hi"

Note: The maximum number of keys a JSON object may have in order to be decoded is limited by the length of an array of jsonNode_t statically defined. Dynamic memory allocation is to be avoided in embedded systems. Note: The maximum number of nested objects is determined by the size of the heap stack used by the parser.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 8 TB3239 Implementation

3.4 Encoding Although this implementation does not include the encoding counterpart, this is easy to accomplish using printf/ sprintf functions by simply using the format parameter of these functions. The following lines of code create a JSON object in string format. It can be sent over MQTT/UART/etc. to report the measured data.

char json[30]; sprintf(json, "{\"Light\":%d,\"Temp\":%d}", 10, 25);

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 9 TB3239 Demo: Controlling the Four LEDs on AVR-IoT ...

4. Demo: Controlling the Four LEDs on AVR-IoT from the PC This section demonstrates how to add the JSON Decoder into a simple MCC project and how to control the four LEDs on the AVR.IOT-WG board by sending JSON formatted commands sent from the Tera Term terminal emulator. Using JSON objects for this task brings the flexibility that a single command, having a clear format and handling logic, can control one, two, three or four LEDs at once. The following image shows the high-level architecture of this demo. Figure 4-1. JSON Decoder Simple Use Case

PC

USB AVR-IoT

neDBG CDC

UART

JSON Decoder

LEDs

4.1 Instructions An AVR-IoT board, MPLAB® X 5.25, MCC 3.85.1 with AVR® MCUs Peripheral Library 2.0.2 (older versions might also work), and Git will be needed to follow the steps in these sections.

4.1.1 Bootstrap a Project with MCC 1. Create a new MPLAB X project for the ATmega4808 device. 2. Click the MCC icon to start configuring the project. 3. In the Pin Manager: Grid View window mark pins PD0 to PD3 as outputs.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 10 TB3239 Demo: Controlling the Four LEDs on AVR-IoT ...

Figure 4-2. Pin Manager: Grid View

4. In the Pin Module window, rename pins to LED_RED, LED_YELLOW, LED_GREEN and LED_BLUE, then check INVEN for all of them. Figure 4-3. Pin Module Window

5. From the Device Resources add USART2 to the project. 6. In the Pin Manager: Grid View window make sure USART2 uses pins PF0 and PF1. 7. In the USART2 settings window make sure Printf support is checked and that all other settings are default. Figure 4-4. USART2 Settings Window

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 11 TB3239 Demo: Controlling the Four LEDs on AVR-IoT ...

8. Click generate.

4.1.2 Add json_decoder to the Project 1. Locate the project path by right clicking it in the MPLAB X Projects window, and then clicking Properties. The first element on the General tab is the Project Location. Figure 4-5. MPLAB® X Projects Window

2. Navigate to the project root using a command line, such as cmd or Power Shell. 3. Clone the json_decoder repository into the project using the following command: $ git clone https://github.com/MicrochipTech/json_decoder.git

4. In the Projects window, under the current project, right-click Source Files and select New logical folder. 5. Rename the created folder to json_decoder. 6. Right-click the json_decoder folder and select Add Existing Item…. Add all the .c source files from the json_decoder cloned folder. 7. Add a new logical folder under Header files, rename it to json_decoder and add all.h header files from jsone_decoder cloned folder. 8. In main.c include json_decoder/json_decore.h. #include “json_decoder/json_decoder.h”

9. Click the Clean and Build Main Project icon. The project will build successfully.

4.1.3 Create a Simple Application 1. Define MAX_COMMAND_LEN in main.c. #define MAX_COMMAND_LEN 64

2. Define the following variables in the main function, before the while loop. char command[MAX_COMMAND_LEN]; uint8_t index = 0; char c;

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 12 TB3239 Demo: Controlling the Four LEDs on AVR-IoT ...

3. Add the following code into the while loop.

c = USART2_Read(); if(c != '\n' && c != '\r') { command[index++] = c; if(index > MAX_COMMAND_LEN) { index = 0; } }

if(c == '\n') { command[index] = '\0'; index = 0; executeCommand(command); }

Note: To learn more about UART, see “TB3216 - Getting Started with USART ( DS90003216B)”. 4. Define the function void executeCommand(char *command) above the main function. 5. Inside the function decode the command into a JSON object and get the root.

jsonNode_t *root = 0; jsonDecoderStatus_t ret; char state[5];

ret = JSON_DECODER_fromString(command); if(JSON_DECODER_OK != ret) { printf("Invalid JSON string.\r\n"); }

JSON_DECODER_getRoot(&root);

6. Check if key “red” is present in the decoded command and based on its value turn the red LED on or off.

ret = JSON_DECODER_getString(root, "red", sizeof(state), state); if(JSON_DECODER_OK == ret) { if(strcmp(state, "on") == 0) { LED_RED_SetHigh(); } else if(strcmp(state, "off") == 0) { LED_RED_SetLow(); } }

7. Do similarly for the other three LEDs. Note: The complete code for executeCommand function is in 6. Appendix.

4.1.4 Test the Application 1. Open a terminal emulator, such as Tera Term. 2. Select the COM port of the AVR.IoT-WG plugged into the computer. 3. In the Tera Term menu go to Setup → Terminal and set it to transmit the new line as CR+LF, then enable Local .

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 13 TB3239 Demo: Controlling the Four LEDs on AVR-IoT ...

Figure 4-6. Tera Term Terminal Settings

4. Send JSON string commands, such as: {”red”:”on”}

– The red LED will turn on.

{”blue”:”on”}

– The blue LED will turn on.

{”yellow”:”on”,”blue”:”off”}

– The yellow LED will turn on. – The blue LED will turn off.

{”yellow”:”off”,”red”:”off”,”blue”:”on”,”green”:”on”}

– The yellow and red LEDs will turn off. – The blue and green LEDs will turn on.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 14 TB3239 Demo: Generic Cloud Communication with an IoT ...

5. Demo: Generic Cloud Communication with an IoT Node A typical cloud communication with an IoT node happens over a secure TLS communication. There are a variety of application protocols but the most widely used in this scenario is MQTT. Actual data are commonly JSON objects. Therefore, the JSON Decoder module is an essential piece in an IoT node. The following image demonstrates a generic high-level architecture of such an application. Figure 5-1. JSON Decoder Advanced Example

Cloud

Upstream Downstream

Wi-Fi/Ethernet/etc

Secure connection (TLS)

MQTT

JSON Decoder

Sensors Actuators

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 15 TB3239 Appendix

6. Appendix

Software License Agreement The software supplied herewith by Microchip Technology Incorporated (the “Company”) is intended and supplied to you, the Company’s customer, for use solely and exclusively with products manufactured by the Company. The software is owned by the Company and/or its supplier, and is protected under applicable copyright laws. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license. THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

void executeCommand(char *command) { jsonNode_t *root = 0; jsonDecoderStatus_t ret; char state[5];

ret = JSON_DECODER_fromString(command); if(JSON_DECODER_OK != ret) { printf("Invalid JSON string.\r\n"); }

JSON_DECODER_getRoot(&root);

ret = JSON_DECODER_getString(root, "red", sizeof(state), state); if(JSON_DECODER_OK == ret) { if(strcmp(state, "on") == 0) { LED_RED_SetHigh(); } else if(strcmp(state, "off") == 0) { LED_RED_SetLow(); } }

ret = JSON_DECODER_getString(root, "yellow", sizeof(state), state); if(JSON_DECODER_OK == ret) { if(strcmp(state, "on") == 0) { LED_YELLOW_SetHigh(); } else if(strcmp(state, "off") == 0) { LED_YELLOW_SetLow(); } }

ret = JSON_DECODER_getString(root, "green", sizeof(state), state); if(JSON_DECODER_OK == ret) { if(strcmp(state, "on") == 0) { LED_GREEN_SetHigh(); } else if(strcmp(state, "off") == 0) { LED_GREEN_SetLow(); } }

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 16 TB3239 Appendix

ret = JSON_DECODER_getString(root, "blue", sizeof(state), state); if(JSON_DECODER_OK == ret) { if(strcmp(state, "on") == 0) { LED_BLUE_SetHigh(); } else if(strcmp(state, "off") == 0) { LED_BLUE_SetLow(); } } }

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 17 TB3239

The Microchip Website

Microchip provides online support via our website at http://www.microchip.com/. This website is used to make files and information easily available to customers. Some of the content available includes: • Product Support – Data sheets and errata, application notes and sample programs, design resources, user’s guides and hardware support documents, latest software releases and archived software • General Technical Support – Frequently Asked Questions (FAQs), technical support requests, online discussion groups, Microchip design partner 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 factory representatives

Product Change Notification Service

Microchip’s product change notification service helps keep customers current on Microchip products. Subscribers will receive email notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. To register, go to http://www.microchip.com/pcn and follow the registration instructions.

Customer Support

Users of Microchip products can receive assistance through several channels: • Distributor or Representative • Local Sales Office • Embedded Solutions Engineer (ESE) • Technical Support Customers should contact their distributor, representative or ESE for support. Local sales offices are also available to help customers. A listing of sales offices and locations is included in this document. Technical support is available through the website 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 the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. • Microchip is willing to work with the customer who is concerned about the integrity of their code. • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. 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 the code protection features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or 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 for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 18 TB3239

your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights unless otherwise stated.

Trademarks

The Microchip name and logo, the Microchip logo, Adaptec, AnyRate, AVR, AVR logo, AVR Freaks, BesTime, BitCloud, chipKIT, chipKIT logo, CryptoMemory, CryptoRF, dsPIC, FlashFlex, flexPWR, HELDO, IGLOO, JukeBlox, KeeLoq, Kleer, LANCheck, LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi, Microsemi logo, MOST, MOST logo, MPLAB, OptoLyzer, PackeTime, PIC, picoPower, PICSTART, PIC32 logo, PolarFire, Prochip Designer, QTouch, SAM-BA, SenGenuity, SpyNIC, SST, SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon, TempTrackr, TimeSource, tinyAVR, UNI/O, Vectron, and XMEGA are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. APT, ClockWorks, The Embedded Control Solutions Company, EtherSynch, FlashTec, Hyper Speed Control, HyperLight Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3, Precision Edge, ProASIC, ProASIC Plus, ProASIC Plus logo, Quiet-Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub, TimePictra, TimeProvider, Vite, WinPath, and ZL are registered trademarks of Microchip Technology Incorporated in the U.S.A. Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BlueSky, BodyCom, CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController, dsPICDEM, dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial Programming, ICSP, INICnet, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, memBrain, Mindi, MiWi, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE, Ripple Blocker, SAM-ICE, Serial Quad I/O, SMART-I.S., SQI, SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks 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. The Adaptec logo, Frequency on Demand, Silicon Storage Technology, and Symmcom are registered trademarks of Microchip Technology Inc. in other countries. GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries. All other trademarks mentioned herein are property of their respective companies. © 2020, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. ISBN: 978-1-5224-5503-5

Quality Management System

For information regarding Microchip’s Quality Management Systems, please visit http://www.microchip.com/quality.

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 19 Worldwide Sales and Service

AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office Australia - Sydney India - Bangalore Austria - Wels 2355 West Chandler Blvd. Tel: 61-2-9868-6733 Tel: 91-80-3090-4444 Tel: 43-7242-2244-39 Chandler, AZ 85224-6199 China - Beijing India - New Delhi Fax: 43-7242-2244-393 Tel: 480-792-7200 Tel: 86-10-8569-7000 Tel: 91-11-4160-8631 Denmark - Copenhagen Fax: 480-792-7277 China - Chengdu India - Pune Tel: 45-4450-2828 Technical Support: Tel: 86-28-8665-5511 Tel: 91-20-4121-0141 Fax: 45-4485-2829 http://www.microchip.com/support China - Chongqing Japan - Osaka Finland - Espoo Web Address: Tel: 86-23-8980-9588 Tel: 81-6-6152-7160 Tel: 358-9-4520-820 http://www.microchip.com China - Dongguan Japan - Tokyo France - Paris Atlanta Tel: 86-769-8702-9880 Tel: 81-3-6880- 3770 Tel: 33-1-69-53-63-20 Duluth, GA China - Guangzhou Korea - Daegu Fax: 33-1-69-30-90-79 Tel: 678-957-9614 Tel: 86-20-8755-8029 Tel: 82-53-744-4301 Germany - Garching Fax: 678-957-1455 China - Hangzhou Korea - Seoul Tel: 49-8931-9700 Austin, TX Tel: 86-571-8792-8115 Tel: 82-2-554-7200 Germany - Haan Tel: 512-257-3370 China - Hong Kong SAR Malaysia - Kuala Lumpur Tel: 49-2129-3766400 Boston Tel: 852-2943-5100 Tel: 60-3-7651-7906 Germany - Heilbronn Westborough, MA China - Nanjing Malaysia - Penang Tel: 49-7131-72400 Tel: 774-760-0087 Tel: 86-25-8473-2460 Tel: 60-4-227-8870 Germany - Karlsruhe Fax: 774-760-0088 China - Qingdao Philippines - Manila Tel: 49-721-625370 Chicago Tel: 86-532-8502-7355 Tel: 63-2-634-9065 Germany - Munich Itasca, IL China - Shanghai Singapore Tel: 49-89-627-144-0 Tel: 630-285-0071 Tel: 86-21-3326-8000 Tel: 65-6334-8870 Fax: 49-89-627-144-44 Fax: 630-285-0075 China - Shenyang Taiwan - Hsin Chu Germany - Rosenheim Dallas Tel: 86-24-2334-2829 Tel: 886-3-577-8366 Tel: 49-8031-354-560 Addison, TX China - Shenzhen Taiwan - Kaohsiung Israel - Ra’anana Tel: 972-818-7423 Tel: 86-755-8864-2200 Tel: 886-7-213-7830 Tel: 972-9-744-7705 Fax: 972-818-2924 China - Suzhou Taiwan - Taipei Italy - Milan Detroit Tel: 86-186-6233-1526 Tel: 886-2-2508-8600 Tel: 39-0331-742611 Novi, MI China - Wuhan Thailand - Bangkok Fax: 39-0331-466781 Tel: 248-848-4000 Tel: 86-27-5980-5300 Tel: 66-2-694-1351 Italy - Padova Houston, TX China - Xian Vietnam - Ho Chi Minh Tel: 39-049-7625286 Tel: 281-894-5983 Tel: 86-29-8833-7252 Tel: 84-28-5448-2100 Netherlands - Drunen Indianapolis China - Xiamen Tel: 31-416-690399 Noblesville, IN Tel: 86-592-2388138 Fax: 31-416-690340 Tel: 317-773-8323 China - Zhuhai Norway - Trondheim Fax: 317-773-5453 Tel: 86-756-3210040 Tel: 47-72884388 Tel: 317-536-2380 Poland - Warsaw Los Angeles Tel: 48-22-3325737 Mission Viejo, CA Romania - Bucharest Tel: 949-462-9523 Tel: 40-21-407-87-50 Fax: 949-462-9608 Spain - Madrid Tel: 951-273-7800 Tel: 34-91-708-08-90 Raleigh, NC Fax: 34-91-708-08-91 Tel: 919-844-7510 Sweden - Gothenberg New York, NY Tel: 46-31-704-60-40 Tel: 631-435-6000 Sweden - Stockholm San Jose, CA Tel: 46-8-5090-4654 Tel: 408-735-9110 UK - Wokingham Tel: 408-436-4270 Tel: 44-118-921-5800 Canada - Toronto Fax: 44-118-921-5820 Tel: 905-695-1980 Fax: 905-695-2078

© 2020 Microchip Technology Inc. Technical Brief DS90003239A-page 20