0% found this document useful (0 votes)
76 views

Atmel - START - To - MPLAB - Harmony3 - Migration - Guide - DS70005413A

The document describes the steps to migrate an embedded application from Atmel START to MPLAB Harmony 3. It covers creating a MPLAB Harmony 3 project, identifying resources used in the Atmel START project, porting driver and system configurations, porting and adapting middleware, and porting application source code. The document uses the SAM D21 IO1 Xplained demo example as a reference.

Uploaded by

Fernando Gómez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Atmel - START - To - MPLAB - Harmony3 - Migration - Guide - DS70005413A

The document describes the steps to migrate an embedded application from Atmel START to MPLAB Harmony 3. It covers creating a MPLAB Harmony 3 project, identifying resources used in the Atmel START project, porting driver and system configurations, porting and adapting middleware, and porting application source code. The document uses the SAM D21 IO1 Xplained demo example as a reference.

Uploaded by

Fernando Gómez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

User's Guide

Atmel START to MPLAB Harmony 3 Migration Guide

Introduction
®
This document describes the different steps to consider when porting an embedded application from Atmel START
®
to the MPLAB Harmony 3 framework. It covers the following migration aspects:
• How to create a MPLAB Harmony 3 project under MPLAB X IDE and navigate through the MPLAB Harmony
Configurator (MHC).
• How to identify different elements that compose a project under Atmel START.
• How to port the system/driver/middleware configuration using MPLAB Harmony Configurator.
• Important aspects to consider when porting the project application layer.
To illustrate these aspects, this document references the SAM D21 IO1 Xplained demo example available on Atmel
START. Prior starting the migration process, ensure that the following prerequisites are met:
• Internet connection with access to https://start.atmel.com
• Latest version of MPLAB X IDE https://www.microchip.com/mplab/mplab-x-ide
• Latest version of MPLAB Harmony 3 https://github.com/Microchip-MPLAB-Harmony
• SAM D21 Xplained Pro board (optional)
• I/O1 Xplained Pro board (optional)

© 2019 Microchip Technology Inc. DS70005413A-page 1


User's Guide

Table of Contents
Introduction.....................................................................................................................................................1

1. Creating MPLAB Harmony 3 Project Under MPLAB X IDE.................................................................... 3

2. Identifying the Resources Used in the Atmel START Project..................................................................8

3. Porting Driver Configuration from Atmel START................................................................................... 13

4. Porting the System PINMUX Configuration from Atmel START............................................................19

5. Porting the System Clock Configuration from Atmel START.................................................................26

6. Porting and Adapting Middleware......................................................................................................... 35

7. Porting the Application Source Code.................................................................................................... 38

The Microchip Website.................................................................................................................................41

Product Change Notification Service............................................................................................................41

Customer Support........................................................................................................................................ 41

Microchip Devices Code Protection Feature................................................................................................ 41

Legal Notice................................................................................................................................................. 41

Trademarks.................................................................................................................................................. 42

Quality Management System....................................................................................................................... 42

Worldwide Sales and Service.......................................................................................................................43

© 2019 Microchip Technology Inc. DS70005413A-page 2


User's Guide
Creating MPLAB Harmony 3 Project Under MPLAB X ...

1. Creating MPLAB Harmony 3 Project Under MPLAB X IDE


The first step in this process is creating a MPLAB Harmony 3 project under MPLAB X IDE. This new project will
enable access to the MPLAB Harmony 3 Configurator (MHC), and access the list of software modules, such as
peripheral libraries, services and middleware, which are available for the target SAM device.
Figure 1-1. MPLAB Harmony 3 Configurator Available Components

To create a project for the SAM D21J18A device, follow these steps:
1. Launch MPLAB X IDE.
2. In MPLAB X IDE, select File > New Project (or click the New Project icon).
3. In the New Project window, under Steps, select Choose Project, and then under Choose Project section,
select these options: for Categories select Microchip Embedded, and for Projects select 32-bit MPLAB
Harmony 3 Project.
Note: If the option 32-Bit MPLAB Harmony 3 Project is not available, users need to install the MPLAB
Harmony 3 Configurator plug-in by selecting Tools > Plugins > Available Plugins before continuing with this
demonstration. MPLAB Harmony 3 Configurator overview is available for download at https://
microchipdeveloper.com/harmony3:mhc-overview.

© 2019 Microchip Technology Inc. DS70005413A-page 3


User's Guide
Creating MPLAB Harmony 3 Project Under MPLAB X ...

Figure 1-2. Creating an MPLAB Harmony 3-Based New Project

4. Click Next.
5. Select Framework Selection, and under Manage Framework section, enter Framework Path (Path to the folder
in which the MPLAB Harmony 3 packages are downloaded). For this demonstration, the MPLAB Harmony 3
packages are already downloaded at D:\microchip\github\h3.
Figure 1-3. New Project - Framework Selection

6. Click Next.
7. Select Project Settings, and under Name and Location section enter MPLAB Harmony 3 new project details:
– Location: Indicates the path to the root folder of the new project. All project files will be placed inside this
folder.
– Folder: Indicates the name of the MPLAB X IDE folder.
– Name: Enter name of the project. This name will be shown in the MPLAB X IDE.
– Path: It is read-only box. It will update as and when users make changes to other entries.

© 2019 Microchip Technology Inc. DS70005413A-page 4


User's Guide
Creating MPLAB Harmony 3 Project Under MPLAB X ...

Figure 1-4. New Project Wizard Step 3

8. Click Next.
9. Select Configuration Settings, and then enter details as given below:
– Name: Enter the configuration name.
– Target Device: Choose a device name.
10. Click Finish.
Figure 1-5. New Project Wizard Step 4

The new MPLAB Harmony 3 project will be launched.


Note: After clicking the Finish button, if MHC does not launch, the user can launch it by selecting Tools > Embedded
> MPLAB® Harmony 3 Configurator from the menu bar of the MPLAB X IDE.

© 2019 Microchip Technology Inc. DS70005413A-page 5


User's Guide
Creating MPLAB Harmony 3 Project Under MPLAB X ...

Figure 1-6. New MPLAB Harmony 3 Project

The software modules associated with the project configuration are seen by selecting Tools > Embedded > MPLAB
Harmony 3 Configurator.
Figure 1-7. Accessing MPLAB Harmony 3 Configurator

The associated MPLAB Harmony 3 Configurator list will be displayed as shown in the figure below.

© 2019 Microchip Technology Inc. DS70005413A-page 6


User's Guide
Creating MPLAB Harmony 3 Project Under MPLAB X ...

Figure 1-8. MPLAB Harmony 3 Configurator - Available Component List

© 2019 Microchip Technology Inc. DS70005413A-page 7


User's Guide
Identifying the Resources Used in the Atmel ...

2. Identifying the Resources Used in the Atmel START Project


Before porting the application, users need to identify the software modules that compose the application. As both
Atmel START and MPLAB Harmony 3 frameworks provide a graphical configuration interface, hence it is simple to
identify the different drivers and middleware modules that are used by the application and compare them to the
available MPLAB Harmony 3 modules.
Figure 2-1. Atmel START Graphical Configuration Interface

• Atmel START
{}
ATSAM021JISA

'1fWCOOE •uc-• - B SAVE CONFlGURATlON


+11:etumTofrontPage I Hl."lpAndSupport:

Ct. OCPOIH PROJfCT

I
MY SOF1WARE COMPONENTS
■ N,ol.'ttlOt'
□ Jrl'odJ-.we () Add 50ftw.Jre aimponent
□ o,-
□ S:,stemdrrw'l!I'

B
IOI_UuHT_SE'6 E08G_COM

I
l2C

GCL<
11 11 11
101 XPLAINED DEMO 0
lh,� �� rea<ls the �pt11:U.-I!: wmor 1tld th!: light Sl!:l'ISOf on the 101 Xpla,ned proe,::�,on bolfd and s,i,ncts th,: valut:5 toa ti:fm1naJ conf'leCtl!!d to the EDSG CDC ,mt11ac11:.
The 101 Xplained pro must be connected ro l!Xtl!nsion he;ioe, 1 (001) on !tie devetopnent kr-� �udrace should be set to 9600 ,n the termiNI applicattOn. Main DrM!l"s and
middlewatt used ,n the l!:)l;bmple-are ADC,. USART, 12C Maste, Dela-/ and GP10

Figure 2-2. Harmony 3 Graphical Configuration Interface (MHC)

Note: Some applications include additional software functions or middleware that are not part of Atmel START.
Therefore, it is important to review the full application flowchart or project architecture to identify them.
Follow these steps while using the SAM D21 I/O1 example from Atmel START as a reference.
1. In Atmel Studio 7, open the Atmel START project to be ported by selecting Project > Re-Configure Atmel Start
Project.

© 2019 Microchip Technology Inc. DS70005413A-page 8


User's Guide
Identifying the Resources Used in the Atmel ...

Figure 2-3. Reconfiguring Atmel START Project

Note: The project can also be opened by loading its .atstart/.atzip file at https://start.atmel.com/.
Atmel START main window showing Load Project tab is displayed.
Figure 2-4. Load Project From a File Under Atmel START

2. When project is loaded, click on the Dashboard tab and identify the Atmel START drivers and its configuration.

© 2019 Microchip Technology Inc. DS70005413A-page 9


User's Guide
Identifying the Resources Used in the Atmel ...

Figure 2-5. Driver Identification Under Atmel START

3. Check the application code and application flowchart to identify whether any additional services and
middleware are required. The figure below illustrates the SAM D21 I/O1 flowchart.
Figure 2-6. Additional Service Middleware Identification Using a Flowchart

Main

Atmel Start Init

Temperature Sensor
init

UART init

ADC Enable

Delay ms System Delay ms


required
Read temperature

Read light from ADC

Print information Printf / STDIO redirect

4. If MPLAB Harmony Configurator is not opened, from MPLAB X IDE open the MPLAB Harmony 3 Configurator
by selecting Tools > Embedded > MPLAB Harmony 3 Configurator.

© 2019 Microchip Technology Inc. DS70005413A-page 10


User's Guide
Identifying the Resources Used in the Atmel ...

Figure 2-7. Accessing MPLAB Harmony 3 Configurator

5. Search for software module availability in Harmony 3 Configurator, and then drag and drop it into the Project
Graph window.
Figure 2-8. Identifying Software Module in MHC

The table below provides the drivers and middleware used for this demonstration.

© 2019 Microchip Technology Inc. DS70005413A-page 11


User's Guide
Identifying the Resources Used in the Atmel ...

Table 2-1. Drivers and Middleware

ATMEL START Module Harmony 3 Module


Drivers IO1_LIGHT_SENS ADC
I2C SERCOM2
EDBG_COM SERCOM3
Systick (implicit) SYSTEM > SYSTICK
Middleware AT30SE75X None
STDIO Redirect STDIO

Note: Specific development is required for AT30SE75X. Other drivers, system services, and middleware are
available under MPLAB Harmony 3.

© 2019 Microchip Technology Inc. DS70005413A-page 12


User's Guide
Porting Driver Configuration from Atmel ST...

3. Porting Driver Configuration from Atmel START


To port a driver from Atmel Studio to MPLAB Harmony 3 is a straightforward operation as it relies on the comparison
of Atmel START and MPLAB Harmony Configurator Graphical interfaces.
Figure 3-1. Atmel START to MPLAB X Driver Support

Follow these steps for the SAM D21 I/O1 Xplained demonstration:
1. Add peripheral library (drivers) to the MPLAB Harmony 3 project by dragging them from the Available
Component list to the Project Graph section.
Figure 3-2. Add Peripheral Driver from the Available Component List

2. Configure all the MPLAB Harmony 3 peripheral libraries according to their equivalent driver in Atmel START.
Note: Specific Atmel START driver configurations can be seen by clicking individually on each of the driver
component in the application dashboard interface.

© 2019 Microchip Technology Inc. DS70005413A-page 13


User's Guide
Porting Driver Configuration from Atmel ST...

Figure 3-3. Access Driver Configuration in Atmel START

– ADC peripheral Library (IO1_LIGHT_SENS) configuration.

© 2019 Microchip Technology Inc. DS70005413A-page 14


User's Guide
Porting Driver Configuration from Atmel ST...

Figure 3-4. Port ADC Driver Configuration

– SERCOM3 peripheral Library (EDBG_COM) configuration

© 2019 Microchip Technology Inc. DS70005413A-page 15


User's Guide
Porting Driver Configuration from Atmel ST...

Figure 3-5. Port SERCOM3 Driver Configuration

– SERCOM2 peripheral Library (I2C) configuration

© 2019 Microchip Technology Inc. DS70005413A-page 16


User's Guide
Porting Driver Configuration from Atmel ST...

Figure 3-6. Port SERCOM2 Driver Configuration

– SYSTICK Service configuration


Figure 3-7. Enable Service Under MHC

After generating the project source code from the MHC interface by clicking or selecting MHC >
Generate Code, the peripheral libraries (PLIBs) configuration can be found in the following project directories:

© 2019 Microchip Technology Inc. DS70005413A-page 17


User's Guide
Porting Driver Configuration from Atmel ST...

Figure 3-8. Generated MHC Project Architecture

PLIBs
headers

PLIBs
sources

The API function definition used by the application can be found in the peripheral library header files.
Figure 3-9. Peripheral Libraries API Location

© 2019 Microchip Technology Inc. DS70005413A-page 18


User's Guide
Porting the System PINMUX Configuration from ...

4. Porting the System PINMUX Configuration from Atmel START


Porting an application PINMUX configuration from Atmel Studio to MPLAB Harmony 3 is a straightforward operation
as it relies on comparison as each framework graphical interface offers similar capabilities.
Figure 4-1. Atmel START and MHC Pin Configuration Interface Comparison

Follow these steps for the SAM D21 IO1 Xplained demonstration:
1. In Atmel START, click on the PINMUX tab and identify which I/O pins are configured and used in the
application.

© 2019 Microchip Technology Inc. DS70005413A-page 19


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-2. Identify I/O Pins Configuration Under Atmel START

Note: The configuration of each pin is available by clicking on it in the PINMUX configurator table.
Figure 4-3. Identify I/O Pins Configuration Under Atmel START (Continued)

2. In MPLAB X IDE, select MHC > Tools > Pin Configuration to open the project pin configurator interface.

© 2019 Microchip Technology Inc. DS70005413A-page 20


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-4. Accessing MHC Under MPLAB X

Note: The following tab in the MHC interface enables the customization of the application pin configuration.
Figure 4-5. Accessing Pin Configuration Windows Under the MHC

3. Port the I/O pin configuration from Atmel Studio to the MHC Pin Setting tab.
– SERCOM 2 I/O settings

© 2019 Microchip Technology Inc. DS70005413A-page 21


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-6. SERCOM 2 I/O Settings

– SERCOM 3 I/Os settings

© 2019 Microchip Technology Inc. DS70005413A-page 22


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-7. SERCOM 3 I/O settings

– ADC I/Os settings

© 2019 Microchip Technology Inc. DS70005413A-page 23


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-8. ADC I/O Settings

4. Verify that the MHC pin diagram is aligned with the initial Atmel START project pin diagram.
Figure 4-9. Pin Configuration Verification

After regenerating the project source from the MHC interface by clicking , the port initialization routine
executed during program initialization can be found in the following project files. This initialization routine is
automatically generated by the MHC according to the user configuration entered in the graphical interface.

© 2019 Microchip Technology Inc. DS70005413A-page 24


User's Guide
Porting the System PINMUX Configuration from ...

Figure 4-10. MHC Generated Pin Configuration

Note: During application run-time, the PORT configuration can be changed by calling APIs from the MPLAB
Harmony 3 PORT PLIB.

© 2019 Microchip Technology Inc. DS70005413A-page 25


User's Guide
Porting the System Clock Configuration from ...

5. Porting the System Clock Configuration from Atmel START


The porting of an application clock configuration from Atmel Studio to MPLAB Harmony 3 is a straightforward
operation as it relies on the comparison of both framework graphical interfaces which offer similar capabilities.
Figure 5-1. Atmel START and MHC Clock Configuration Interface Comparison

1. In Atmel START, click the PINMUX tab and identify different clock elements used in the application and their
settings.

© 2019 Microchip Technology Inc. DS70005413A-page 26


User's Guide
Porting the System Clock Configuration from ...

Figure 5-2. Identify Project Clock Configuration Under Atmel START

Note: Additional information on the settings for a specific clock element can be retrieved by clicking on the
associated blue gear wheel button.
Figure 5-3. Access Clock Element Settings Under Atmel START

2. To open the project pin configurator interface, in MPLAB X IDE, select MHC > Tools > Clock Configuration.

© 2019 Microchip Technology Inc. DS70005413A-page 27


User's Guide
Porting the System Clock Configuration from ...

Figure 5-4. Access Clock Configuration Interface Under MHC

3. Port each clock component configuration from Atmel START to the MHC Clock view.
– 8 MHz Internal Oscillator (OSC8M)

© 2019 Microchip Technology Inc. DS70005413A-page 28


User's Guide
Porting the System Clock Configuration from ...

Figure 5-5. 8MHz Internal Oscillator Configuration Port

– GCLK Generator 0

© 2019 Microchip Technology Inc. DS70005413A-page 29


User's Guide
Porting the System Clock Configuration from ...

Figure 5-6. GCLK Generator 0 Configuration Port

– GCLK Generator 1

© 2019 Microchip Technology Inc. DS70005413A-page 30


User's Guide
Porting the System Clock Configuration from ...

Figure 5-7. GCLK Generator 1 Configuration Port

– ADC Peripheral clock

© 2019 Microchip Technology Inc. DS70005413A-page 31


User's Guide
Porting the System Clock Configuration from ...

Figure 5-8. ADC Peripheral Clock Configuration Port

– SERCOM2 Peripheral clock

© 2019 Microchip Technology Inc. DS70005413A-page 32


User's Guide
Porting the System Clock Configuration from ...

Figure 5-9. SERCOM2 Peripheral Configuration Port

– SERCOM3 Peripheral clocks

© 2019 Microchip Technology Inc. DS70005413A-page 33


User's Guide
Porting the System Clock Configuration from ...

Figure 5-10. SERCOM3 Peripheral Configuration Port

© 2019 Microchip Technology Inc. DS70005413A-page 34


User's Guide
Porting and Adapting Middleware

6. Porting and Adapting Middleware


The complexity behind the porting of middleware depends on its availability in the MPLAB Harmony 3 framework.
The following two approaches can be used for porting middleware:
1. If middleware is available under MPLAB Harmony 3, include the middleware in the MHC project graph and link
it to the associated driver. MPLAB Harmony 3 will be automatically generate a Hardware Abstraction Layer
customized for this driver and middleware combination.
Figure 6-1. STDIO Middleware or Service Integration Under MHC

2. If the middleware is not available under Harmony 3, the user must include the source of the middleware in the
new project, then locate and modify the Hardware Abstraction Layer to call the APIs provided in the Peripheral
Library.
The following steps illustrate the process to be followed for the SAM D21 I/O1 demonstration.
By analyzing the structure of the application (Step 1), using both the Atmel START Dashboard and the application
source code, the following middlewares are used in the Atmel START source application:
• AT30TSE75X : temperature sensor
• STDIO redirection (implicitly added)

© 2019 Microchip Technology Inc. DS70005413A-page 35


User's Guide
Porting and Adapting Middleware

Figure 6-2. Middleware Identification Under Atmel START

The AT30TSE is currently not available under MPLAB X IDE, therefore a manual source port must be created. This
step will be covered in step seven when porting the application source code.
1. In MPLAB X IDE, add the STDIO middleware to the project using the MHC Project Graph window then link the
STDIO middleware to the SERCOM3 driver.
Figure 6-3. Add STDIO Middleware Under MHC

After regenerating the project source from the MHC interface by clicking , the STDIO redirection HAL will
be generated according to the graphical configuration. The getc and putc functions will be redirected to the
SERCOM3 APIs.

© 2019 Microchip Technology Inc. DS70005413A-page 36


User's Guide
Porting and Adapting Middleware

Figure 6-4. MHC Generated STDIO Redirection

Cf MPLAB X IDE v5.20 - SAMD21_1O1_examp le_port: default □ X


file .fdit MHC Y:iew Navigate �urce Refictor Production Qebug Team Iools Window Help 10.� Search (Ctrl+J)

c5l Projects x I Active Components r;J StartP� xl�1maii.c xi Proj&tGraph l�plb_port.c •l�xc32_monitor.c xl 8=}]E)@)c:5l
1j 8-· SAt-021_IOl_exarnpe_port Sou-co Hsto,y • I©
I
Ci 1'8 • ■ · I '<l. 'i;, ¢' � '• I 'i? -!,, \h I � � I
8 El 11\1 el � 83
'¥--� Headern1es I I ii'.
34 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIE" ■ �
·l
� $-·., imp0ftant Fies •
35 • BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO TJ-
I

�-- Sou"cefies 36 • FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLl
® @fll:lLm<Fie,
RE T OF FEES, �
(ci
�� F�: !!�s :��= �
(ci
Elf.cidefaut �: : ��/:�u � �A:� ���:����I���H

:
E T c

39
U~f� . s ,�,. exceptions.c
!- - -�
!_!.nclude "d�liniti.9,.n:,. h"
j.... ti-.:--··�1::�::·'
40

lbc_syscans.c 42
nt _mon_qetc(int �I

"1I
c5] !
i--··-�starU4)xc32.c
lj}fi:l-•
1 811() stdio
L._� xc32_monitor.c I
45

volatile int c '"' 0;
while(SERCOM3_USART_Read((void•)&c, 1) ! = �);
, i 47 return c;
Lbraries
49
i .............. .
f··-·'-
SO void _mon_pntc(char c)
@(i'iLoadabie,

';,_,]
w � :,ize .. O;
53 do
54
55 :,ize .. SERCOM3_USART_Write((voidit)&c, 1);
56 )while (:,ize != l);
57 { -------------------

I
>
c5] Q_ Search ReSUt:s � OJtput Console 12:1 IINs

© 2019 Microchip Technology Inc. DS70005413A-page 37


User's Guide
Porting the Application Source Code

7. Porting the Application Source Code


After drivers, system, and middleware layers are ported to the MPLAB Harmony 3 project, all available peripheral
libraries and middleware APIs required to port the application are available in the project directory.
Figure 7-1. MPLAB Harmony 3 Drivers and Middleware APIs Location

Porting the application layer requires the review of the Atmel START main application routine and associated
application layer related functions, and modifying them to make use of the MPLAB Harmony 3 APIs instead of the
Atmel START ones.
The following figure illustrates the effort to port the application layer of the SAM D21 IO1 Xplained demo example to
MPLAB Harmony 3.

© 2019 Microchip Technology Inc. DS70005413A-page 38


User's Guide
Porting the Application Source Code

Figure 7-2. SAM D21 I/O1 Xplained Demo Application Layer Porting Effort

Main Main
Aligned
(no port needed) SYS_Initialize
Atmel Start Init

Temperature Sensor Update APIs call Temperature Sensor


init init
Done during SYS_initialize
UART init

Update APIs call


ADC Enable ADC Enable

Update APIs call


Delay ms Delay ms

Create new functions


Read temperature Read temperature

Update APIs call


Read light from ADC Read light from ADC

Print information Update APIs call


Print information

The result of the SAM D21 I/O1 Xplained demo application layer porting is shown below :

#include <stddef.h> // Defines NULL


#include <stdbool.h> // Defines true
#include <stdlib.h> // Defines EXIT_FAILURE
#include "definitions.h" // SYS function prototypes

#define AT30TSE_SENSOR_ADDRESS 0x4F


#define STR_SIZE 50

uint16_t adc_read_channel(void);
bool temperature_sensor_init(void);
float temperature_sensor_read(void);

uint16_t adc_read_channel(void)
{
/*- Start ADC channel */
ADC_ConversionStart();
/*- Wait until result is ready */
while(ADC_ConversionStatusGet() != true);

return ADC_ConversionResultGet();
}

bool temperature_sensor_init(void)
{
bool res;
uint8_t buffer[3];

/*- Configure the AT30TSE sensor */


buffer[0] = 1; // Select Configuration register
buffer[1] = (2 << 5); // Set resolution to 11-bit
buffer[2] = 0;
res = SERCOM2_I2C_Write(AT30TSE_SENSOR_ADDRESS,buffer,3);

return res;
}

© 2019 Microchip Technology Inc. DS70005413A-page 39


User's Guide
Porting the Application Source Code

float temperature_sensor_read(void)
{
uint8_t txbuffer[2];
uint8_t rxbuffer[2];
uint16_t data;
int8_t sign = 1;

/* - Read the 16-bit temperature register. */


txbuffer[0] = 0x0; // Select Temperature register
SERCOM2_I2C_WriteRead(AT30TSE_SENSOR_ADDRESS,txbuffer,1,rxbuffer,2);
/* - Convert Rx buffer content into temperature */
data = (rxbuffer[0] << 8) | rxbuffer[1];
sign -= (bool)(data & (1 << 15)) << 1;
data &= ~(1 << 15);
data = data >> (7 - 2);

return (float)data * sign * (0.5 / (1 << 2));


}
int main ( void )
{
uint16_t light_val;
uint16_t temp_result;

/*- Initialize all modules */


SYS_Initialize (NULL);
SYSTICK_TimerStart();
/*- Enable ADC */
ADC_Enable();
/*- Initialize I/O1 temperature sensor */
temperature_sensor_init();
while ( true )
{
/*- Wait 1 second */
SYSTICK_DelayMs(1000);
/*- Read light level */
light_val = adc_read_channel();
/*- Read temperature */
temp_result = temperature_sensor_read();
/*- Display Light and temperature information on Terminal */
printf("Temperature: %d Celsius, light sensor: 0x%x\r\n",
temp_result, light_val);
}
/*- Execution should not come here during normal operation */
return ( EXIT_FAILURE );
}

© 2019 Microchip Technology Inc. DS70005413A-page 40


User's Guide

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

© 2019 Microchip Technology Inc. DS70005413A-page 41


User's Guide

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.
© 2019, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.
ISBN: 978-1-5224-5403-8

Quality Management System


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

© 2019 Microchip Technology Inc. DS70005413A-page 42


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

© 2019 Microchip Technology Inc. DS70005413A-page 43

You might also like