{"id":19702053,"url":"https://github.com/microchiptech/atsamr34_lorawan_smart_meter","last_synced_at":"2025-07-09T22:35:57.897Z","repository":{"id":87706492,"uuid":"262000438","full_name":"MicrochipTech/atsamr34_lorawan_smart_meter","owner":"MicrochipTech","description":"“IoT Made Easy!\" - Enable pulse counting on a Low Power LoRaWAN Application","archived":false,"fork":false,"pushed_at":"2021-10-19T08:13:24.000Z","size":44568,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-29T14:33:58.767Z","etag":null,"topics":["atsamr34","lora","lorawan","wlr089u0"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MicrochipTech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-05-07T08:58:44.000Z","updated_at":"2024-02-14T13:35:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f04a256-3c63-4e9b-a483-bff2ac3ca6f6","html_url":"https://github.com/MicrochipTech/atsamr34_lorawan_smart_meter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MicrochipTech/atsamr34_lorawan_smart_meter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrochipTech%2Fatsamr34_lorawan_smart_meter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrochipTech%2Fatsamr34_lorawan_smart_meter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrochipTech%2Fatsamr34_lorawan_smart_meter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrochipTech%2Fatsamr34_lorawan_smart_meter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MicrochipTech","download_url":"https://codeload.github.com/MicrochipTech/atsamr34_lorawan_smart_meter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrochipTech%2Fatsamr34_lorawan_smart_meter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264504615,"owners_count":23618831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atsamr34","lora","lorawan","wlr089u0"],"created_at":"2024-11-11T21:13:18.964Z","updated_at":"2025-07-09T22:35:57.881Z","avatar_url":"https://github.com/MicrochipTech.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ATSAMR34_LORAWAN_SMART_METER\n\u003cimg src=\"Doc/IoT-Made-Easy-Logo.png\" width=100\u003e\n\n\u003e “Wireless Made Easy!\" - Enable pulse counting on a Low Power LoRaWAN Application\n\n\u003cp\u003e\n\u003ca href=\"https://www.microchip.com/design-centers/wireless-connectivity/low-power-wide-area-networks/lora-technology/sam-r34-r35\" target=\"_blank\"\u003e\n\u003cimg border=\"0\" alt=\"Microchip_logo\" src=\"Doc/Microchip_logo.png\" width=\"150\"\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp\n\n\u003c/p\u003e\n\u003c/a\u003e\n\n## ⚠ Disclaimer\n\n\u003cp\u003e\u003cspan style=\"color:red\"\u003e\u003cb\u003e\nTHE SOFTWARE ARE PROVIDED \"AS IS\" AND GIVE A PATH FOR SELF-SUPPORT AND SELF-MAINTENANCE.\u003c/br\u003e\u003c/br\u003e\nThis repository contains unsupported example code intended to help accelerate client product development. It is not validated for production nor audited for security best-practices.\u003c/br\u003e\u003c/br\u003e\nNote that while this repository is unsupported, Microchip welcome community contributions, and all pull-requests will be considered for inclusion into the repository.\n\u003c/span\u003e\u003c/p\u003e\u003c/b\u003e\n\n\u003e Interact with peers in the community at [LoRa Forum](https://www.microchip.com/forums/f512.aspx).\n\n## Abstract\n\n**Based on LoRaWAN Application generated from ASFv3, this sample code demonstrates how to enable a power-efficient pulse counting while device is placed in standby mode, useful for battery-powered applications used in Smart Metering**\n\nThe main application consists into transmitting the counter value to a LoRaWAN network provider cloud thru a Gateway.\nFor the purpose of this demo, TTN and TTI with a pre-provisioned Secure Element have been used.\n\n## Sample Applications\n\n[Clone/Download](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) the current repo to get the software.\n\n## A la carte\n\n1. [Material required](#step1)\n2. [Software](#step2)\n3. [Hardware setup](#step3)\n4. [Sleep modes](#step4)\n5. [Power Management Module](#step5)\n6. [Asynchronous pulse counter in standby mode](#step6)\n7. [Run the demo](#step7)\n\n## Material required \u003ca name=\"step1\"\u003e\u003c/a\u003e\n\nMust:\nPurchase the \u003ca href=\"https://www.microchip.com/Developmenttools/ProductDetails/DM320111\" target=\"_blank\"\u003eSAM R34 Xplained Pro Evaluation Kit\u003c/a\u003e\n\u003c/br\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/ATSAMR34Xpro.png\" width=\u003e\n\u003c/p\u003e\n\n\u003c/br\u003e\n\nPurchase the \u003ca href=\"https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/EV23M25A\" target=\"_blank\"\u003eWLR089U0 Xplained Pro Evaluation Kit\u003c/a\u003e\n\u003c/br\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/WLR089U0Xpro.png\" width=\u003e\n\u003c/p\u003e\n\u003c/br\u003e\n\nMust:\nPurchase a LoRa(r) Gateway (e.g. from \u003ca href=\"https://www.thethingsindustries.com/technology/hardware#gateway\" target=\"_blank\"\u003eThe Things Industries\u003c/a\u003e)\n\u003c/br\u003e\n![](Doc/TTI_Hardware.png)\n\u003c/br\u003e\n\nOptional:\nPurchase samples of the \u003ca href=\"https://www.microchipdirect.com/product/search/all/ATECC08A-TNGLORA\" target=\"_blank\"\u003eATECC608A-TNGLORA\u003c/a\u003e\nsecure element \nand the \u003ca href=\"https://www.microchipdirect.com/product/search/all/AT88CKSCKTUDFN-XPRO\" target=\"_blank\"\u003eCryptoAuthentication UDFN Socket Kit\u003c/a\u003e\n\u003c/br\u003e\n\n## Software \u003ca name=\"step2\"\u003e\u003c/a\u003e\n\n- Download and install [Microchip Studio 7.0 IDE](https://www.microchip.com/mplab/microchip-studio).\n- Open Microchip Studio 7.0 IDE.\n- From **Tools - \u003e Extensions and updates**, install Advanced Software Framework (ASFv3) v3.49.1 release or upper release.\n- Restart Microchip Studio\n\n- Download and install a serial terminal program like [Tera Term](https://osdn.net/projects/ttssh2/releases/).\n\n## Hardware setup \u003ca name=\"step3\"\u003e\u003c/a\u003e\n\nTo extract the SAM R34 current consumption, the board requires to be configured as explained below:\n- MCU Jumper : MEASURE\n- I/O Jumper: BYPASS\n- Vbat Jumper: PB03/VCC\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/setup.png\" width=520\u003e\n\u003c/p\u003e\n\n\n\u003e In case you are using TTI servers and a ATECC608A-TNGLORA secure element, refer to \u003ca href=\"https://github.com/MicrochipTech/atsamr34_ecc608a_tti#step3\" target=\"_blank\"\u003ethis repo for the setup.\u003c/a\u003e\n\n\u003e WLR089 Xplained Pro requires hardware modification to use the application code. \nBy default inductor L301 (10uH) and capacitor C316 (100nF) are not mounted on the WLR089 Xplained Pro. Both need to be mounted to use the demo application and select Buck converter as the main voltage regulator in active mode.\\\nCheck out the [WLR089 Xplained Pro documentation](https://www.microchip.com/Developmenttools/ProductDetails/EV23M25A) for more details.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/WLR089Xpro_modification_01.png\" width=720\u003e\n\u003cimg src=\"Doc/WLR089Xpro_modification_02.png\" width=720\u003e\n\u003cimg src=\"Doc/setup_wlr089.png\" width=520\u003e\n\u003c/p\u003e\n\n## Sleep Modes \u003ca name=\"step4\"\u003e\u003c/a\u003e\n\nThe SAMR34/R35 devices have accurate low power external and internal oscillators. Different clock domains can be independently configured to run at different frequencies, enabling power-saving by running each peripheral at its optimal clock frequency, thus maintaining a high CPU frequency while reducing power consumption.\u003c/br\u003e\nThe SAM R34/R35 devices have four software-selectable sleep modes: Idle, Standby, Backup and Off.\u003c/br\u003e\nIn **Idle mode**, the CPU is stopped while all other functions may be kept running.\u003c/br\u003e\nIn **Standby mode**, all clocks and functions are stopped except those selected to continue running. In this mode all RAMs and logic contents are retained. The device supports SleepWalking, which allows some peripherals to wake-up from sleep based on predefined conditions, thus allowing some internal operations like DMA transfer and/or the CPU to wake-up only when needed; for example, when a threshold is crossed, or a result is ready. The event system supports synchronous and asynchronous events, allowing peripherals to receive, react to and send events even in Standby mode.\u003c/br\u003e\nIn **Backup mode**, most of logic and analog cells are powered off. Only few features are available (RTC, backup registers, wake-up from external pins).\u003c/br\u003e\n**Off mode** is not advised, as high impedance on the internal SPI bus results in metastability.\u003c/br\u003e\n\nThe SAM R34/R35 devices have two software-selectable performance levels (PL0 and PL2) allowing the user to scale the lowest core voltage level that supports the operating frequency. To further minimize current consumption, specifically leakage dissipation, the devices utilize a power domain gating technique with retention to turn off some logic areas while keeping their logic state. This technique is fully handled in hardware.\u003c/br\u003e\n\n## Power Management Module (PMM) \u003ca name=\"step5\"\u003e\u003c/a\u003e\n\nThe Microchip LoRaWAN Stack (MLS) provides a Power Management Module (PMM) in the stack. An application running on top of MLS can choose to use PMM to save power during idle times. Besides saving power during idle, PMM tries to reduce power consumption even during a transaction. Power saving is done by switching the MCU to one of the available low-power modes. Currently, PMM is supported only on SAM R34 MCU and it can be configured either in STANDBY or BACKUP Sleep mode.\u003c/br\u003e\n\n**STANDBY mode:**\n- Retains the RAM content\n- Wakeup source can be EXTINT or RTC timer\n\n**BACKUP mode:**\n- RAM content is lost\n- Device can wakeup through RESET or EXTWAKE pins\n\nPMM is enabled via the MACRO `CONF_PMM_ENABLE`. This macro controls the addition and removal of PMM in the application and in the stack.\nAfter enabling the PMM features in the application code, all portions of code located between the following section will be compiled and executed:\n```\n#ifdef CONF_PMM_ENABLE\n.. \n#endif\n```\n\nThe current application (`lorawan_app.c` file) already implements all the code required for using PMM features. And the following details are given for information. \u003c/br\u003e\nTo use PMM in an application, it is required to include the following header files:\n```\n#ifdef CONF_PMM_ENABLE \n  #include \"pmm.h\" \n  #include \"conf_pmm.h\" \n  #include \"sleep_timer.h\" \n  #include \"sleep.h\"\n#endif\n```\n\nBy default, application sleep time is configured for 30 seconds and can be changed to the desired values. Application sleep request time is configured by the macro:\n```\n#define DEMO_CONF_DEFAULT_APP_SLEEP_TIME_MS     30000\t// Sleep duration in ms\n```\nBut the sleep duration must fall within the acceptable range which is givin in the following table.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/pmm_table.png\" width=720\u003e\n\u003c/p\u003e\n\nThe sleep timer module must be initialized for enabling the RTC module: \n```\n#ifdef CONF_PMM_ENABLE \n  SleepTimerInit() ; \n#endif\n```\nThe file `rtc_count.h` contains the available clock sources for the RTC module.\n```\n#ifdef FEATURE_RTC_CLOCK_SELECTION\n/**\n * \\brief Available clock source for RTC.\n * RTC clock source.\n */\nenum rtc_clock_sel {\n\t/** 1.024KHz from 32KHz internal ULP oscillator */\n\tRTC_CLOCK_SELECTION_ULP1K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP1K_Val,\n\t/** 32.768KHz from 32KHz internal ULP oscillator */\n\tRTC_CLOCK_SELECTION_ULP32K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP32K_Val,\n#if !(SAML22)\n\t/** 1.024KHz from 32KHz internal oscillator */\n\tRTC_CLOCK_SELECTION_OSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC1K_Val,\n\t/** 32.768KHz from 32KHz internal oscillator */\n\tRTC_CLOCK_SELECTION_OSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC32K_Val,\n#endif\n\t/** 1.024KHz from 32KHz external oscillator */\n\tRTC_CLOCK_SELECTION_XOSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC1K_Val,\n\t/** 32.768KHz from 32.768KHz external crystal oscillator */\n\tRTC_CLOCK_SELECTION_XOSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC32K_Val,\n};\n#endif\n```\n\nFor this application, the RTC module will be clocked from external 32kHz clock. Using the internal 32kHz Ultra Low Power oscillator as the RTC clock source is possible but requires different clock settings. Using XOSC32 will result in better performance, less frequency drift and consequently higher stability.\n\u003c/br\u003e\n\n\n## Standby mode \u003ca name=\"step6\"\u003e\u003c/a\u003e\n\nIn standby mode, all clock sources are stopped, except those where the RUNSTDBY (Run in Standby) bit for the module is set or have the ONDEMAND bit set to zero. \nBy default the regulator operates in Low Power mode when using STANDBY sleep mode. \nBefore entering Standby mode it must be made sure that significant amount of clocks and peripherals are disabled, so that the voltage regulator is not overloaded. \nTo avoid overloading, the peripherals should be configured so that the total power consumption supplied by the internal regulator in low power mode should be less than 50μA. \nIf the peripherals required to run in STANDBY mode consumes more than 50uA, the regulator should be configured to operate in normal mode, and this can be done from software by setting the RUNSTDBY bit in SYSCTRL -\u003e VREG.\n\n- The buck Converter is more efficient for a reduce Power supply range (compare to the LDO mode)\n- Regulator Low Power Mode efficiency mode targeted to be used in certain conditions (Low frequencies, Power supply range reduced…)\n- Apply SAM L21 Errata (force the run in STDBY and PL0) to be more efficient\n\nThe application implement the following power optimization function enabling the benefit of the ultra-low power architecture of the SAM R34 device. \n```\nstatic void configure_sleep(void)\n{\n\t/* Disable BOD33 */\n\tSUPC-\u003eBOD33.reg \u0026= ~(SUPC_BOD33_ENABLE);\n\n\t/* Select BUCK converter as the main voltage regulator in active mode */\n\tSUPC-\u003eVREG.bit.SEL = SUPC_VREG_SEL_BUCK_Val;\n\t/* Wait for the regulator switch to be completed */\n\twhile(!(SUPC-\u003eSTATUS.reg \u0026 SUPC_STATUS_VREGRDY));\n\n\t/* Set Voltage Regulator Low power Mode Efficiency */\n\tSUPC-\u003eVREG.bit.LPEFF = 0x1;\n\n\t/* Apply SAM L21 Erratum 15264 */\n\tSUPC-\u003eVREG.bit.RUNSTDBY = 0x1;\n\tSUPC-\u003eVREG.bit.STDBYPL0 = 0x1;\n\t\n\t/* SRAM configuration in standby */\n\tPM-\u003eSTDBYCFG.reg = PM_STDBYCFG_BBIASHS(1) | PM_STDBYCFG_VREGSMOD_LP ;\n}\n```\n\nRefer to the SAM L21 Family product Datasheet for more details about the Low Power Architecture of the Microcontroller.\nhttps://www.microchip.com/wwwproducts/en/ATSAML21J18B\n\n## Asynchronous pulse counter in standby mode \u003ca name=\"step6\"\u003e\u003c/a\u003e\n\nIn general, the flow sensor converts the kinetic energy from rotation into electrical digital signals in the form of pulses.\u003c/br\u003e\n\nIn this application, the SAM R34 device counts the number of pulses while staying in standby mode.\nThanks to the Event System (EVSYS) features available within the SAM R34 device to enable inter-peripheral communications thus helps to Lower CPU load and power consumption of the system.\nIt allows for autonomous control of peripherals without any use of CPU bandwidth and it can remain in standby mode for longer periods.\u003c/br\u003e\nSome peripherals can continue to operate in standby mode, where the source clock is running, and this is the case of the Timer Counter (TC) or the Timer Counter for Control Applications (TCC).\n\nThe Event System is comprised of the following two event resources:\n- Event Generator: input events of a peripheral that will generate the events signal.\n- Event Users: connected to peripherals that will receive events as they are generated\n\nIn the current application, the Event System has been configured as below.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/event_system.png\" width=720\u003e\n\u003c/p\u003e\n\nThis application aims to count the pulses coming from a pulse source and to transmit over the LoRaWAN RF protocol.\n\u003c/br\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/block_diagram.png\" width=720\u003e\n\u003c/p\u003e\n\nThe EXTINT8 module (physically connected to user button present on the board) is configured to generate an event when button SW0 is pushed.\nSW0 is connected to PA28, which can generate interrupts on EXTINT[8]. \n\n```\n// configure external interrupt for SW0\nvoid configure_extint(void)\n{\n\t// configure external interrupt controller\n\tstruct extint_chan_conf extint_chan_config ;\n\textint_chan_config.gpio_pin = CONF_EIC_PIN ;\n\textint_chan_config.gpio_pin_mux = CONF_EIC_MUX ;\n\textint_chan_config.gpio_pin_pull = EXTINT_PULL_UP ;\n\textint_chan_config.detection_criteria = EXTINT_DETECT_RISING ;\n\textint_chan_config.filter_input_signal = true ;\n\textint_chan_set_config(CONF_EIC_CHAN, \u0026extint_chan_config) ;\n\t\n\t// configure external interrupt module to be an event generator\n\tstruct extint_events extint_event_config ;\n\textint_event_config.generate_event_on_detect[CONF_EIC_CHAN] = true ;\n\textint_enable_events(\u0026extint_event_config) ;\n}\n```\n\nThis is routed to Timer/Counter TC0 by the Event System channel 8.\n```\n// configure event system for generators and users\nvoid configure_eventsystem(void)\n{\n\t// configure event system\n\tstruct events_resource event_res ;\n\t\n\t// configure channel\n\tstruct events_config config ;\n\tevents_get_config_defaults(\u0026config) ;\n\tconfig.generator = CONF_EVENT_GENERATOR_ID ;\n\tconfig.edge_detect = EVENTS_EDGE_DETECT_RISING ;\n\tconfig.path = EVENTS_PATH_ASYNCHRONOUS ;\n\tconfig.run_in_standby = true ;\n\tevents_allocate(\u0026event_res, \u0026config) ;\n\t\n\t// configure user\n\tevents_attach_user(\u0026event_res, CONF_EVENT_USER_ID) ;\n}\n```\n\nTC0 is configured to increment a 16-bit counter on event generated from the EXTINT module.\n```\n// configure_tc\nvoid configure_tc(void)\n{\n\t// configure TC module for counting\n\tstatic struct tc_config tc_counter_config ;\n\ttc_reset(\u0026tc_counter_module) ;\n\ttc_get_config_defaults(\u0026tc_counter_config) ;\n\ttc_counter_config.clock_prescaler = TC_CLOCK_PRESCALER_DIV1 ;\n\ttc_counter_config.count_direction = TC_COUNT_DIRECTION_UP ;\n\ttc_counter_config.counter_size = TC_COUNTER_SIZE_16BIT ;\n\ttc_counter_config.on_demand = true ;\n\ttc_counter_config.run_in_standby = true ;\n\ttc_init(\u0026tc_counter_module, CONF_TC, \u0026tc_counter_config) ;\n\n\tstruct tc_events tc_event = {\n\t\t.on_event_perform_action = true,\n\t\t.event_action = TC_EVENT_ACTION_INCREMENT_COUNTER,\n\t\t.generate_event_on_overflow = false\n\t} ;\n\ttc_enable_events(\u0026tc_counter_module, \u0026tc_event) ;\n\t// enable TC module\n\ttc_enable(\u0026tc_counter_module) ;\t\n}\n```\nSince TC has ONDEMAND bit, it improve a bit the power consumption in standby mode against TCC module.\nIn `conf_pulse_counter.h`, it is possible to select to use TC or TCC as a counter.\nBoth are able to count during standby mode.\n```\n#ifndef CONF_PULSE_COUNTER_H\n#define CONF_PULSE_COUNTER_H\n\n// Counter selection\n#define USE_TC\t0\n#define USE_TCC 1\n#define COUNTER_SELECTED\t\t\tUSE_TC\n\n// EXTINT Config\n#define CONF_EIC_CHAN\t\t\t\tBUTTON_0_EIC_LINE\t// EXTINT8\n#define CONF_EIC_PIN\t\t\t\tBUTTON_0_EIC_PIN\n#define CONF_EIC_MUX\t\t\t\tBUTTON_0_EIC_MUX\n\n// EVSYS Config\n#define CONF_EVENT_GENERATOR_ID\t\tEVSYS_ID_GEN_EIC_EXTINT_8\n#if (COUNTER_SELECTED == USE_TCC)\n  #define CONF_EVENT_USER_ID\t\tEVSYS_ID_USER_TCC1_EV_0\n#else\n  #define CONF_EVENT_USER_ID\t\tEVSYS_ID_USER_TC4_EVU\t// must match with CONF_TC\n#endif\n\n// TCC\n#define CONF_TCC\t\t\t\t\tTCC1\n#define CONF_CAPTURE_CHAN_0\t\t\t0\n#define CONF_CAPTURE_CHAN_1\t\t\t1\n\n// TC\n#define CONF_TC\t\t\t\t\t\tTC4 // TC0 is already used in LoRaWAN stack (hw_timer.c, conf_hw_timer.h)\n\n#endif\n```\n\n## Run the demo \u003ca name=\"step7\"\u003e\u003c/a\u003e\n\nOpen the current project with Microchip Studio 7 IDE\u003c/br\u003e\nFrom the top menu, go to Project -\u003e \u003cProject Name\u003e Properties\u003c/br\u003e\n\nIn case a Secure Element is connected to SAM R34 Xplained Pro board, make sure the MACRO `CRYPTO_DEV_ENABLED` is defined.\nSelect Toolchain \u003e ARM/GNU C Compiler \u003e Symbols\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/crypto_symbol.png\" width=720\u003e\n\u003c/p\u003e\n\nFrom Tool settings, select your board as EDBG debugger with SWD interface\n\u003c/br\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/EDBG.png\" width=520\u003e\n\u003c/p\u003e\n\u003c/br\u003e\u003c/br\u003e\nBuild and download the project by clicking the empty green \"Run without debugging\" triangle\n\u003c/br\u003e\u003c/br\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/AtmelStudio.png\" width=520\u003e\n\u003c/p\u003e\n\u003c/br\u003e\n\nFrom the top menu, open Tools \u003e Data Visualizer\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/tools_menu.png\" width=\u003e\n\u003c/p\u003e\n\nUnder DGI Control Panel, select SAMR34 Xplained Pro and Click Connect\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/data_visualizer_01.png\" width=720\u003e\n\u003c/p\u003e\n\nWhen it is ready, select \"Power\" interface and click Start to start power analyze on the board.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/data_visualizer_02.png\" width=720\u003e\n\u003c/p\u003e\n\nThe Data Visualizer should display the power consumption of the SAM R34 device and make abstraction of the I/O and external onboard chip consumption.\n\u003c/br\u003e\n\u003c/br\u003e\n\nOpen Tera Term UART console configured at 115200 bps, 8-data bits/No parity/1-stop bit\n\u003c/br\u003e\nPress the \"Reset\" button on the SAM R34 Xplained Pro board to see output printed to the console\n\u003c/br\u003e\nIf the MACRO `CRYPTO_DEV_ENABLED` is defined and a secure element is connected to SAM R34 Xplained Pro over EXT3 connector:\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/tera_term_01.png\" width=480\u003e\n\u003c/p\u003e\n\nIf the MACRO `CRYPTO_DEV_ENABLED` is not defined, the OTAA credentials hard-coded in `lorawan_app.c` are used:\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/tera_term_02.png\" width=480\u003e\n\u003c/p\u003e\n\nWhen device successfully joined the LoRaWAN network, the application will periodically wakes-up every 60 sec and transmit an uplink message over the LoRaWAN network.\nThe message encapsulates the counter value and the temperature in °C and in °F.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/tera_term_03.png\" width=480\u003e\n\u003c/p\u003e\n\nIn active mode, on every wake up, the device will issue a transmission followed by two reception windows.\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/active_mode.png\" width=480\u003e\n\u003c/p\u003e\n\nBetween two transmission, the power consumption in standby mode is around 8uA\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/between_two_uplink.png\" width=720\u003e\n\u003c/p\u003e\n\nIn standby mode, pulse counting is possible without waking up the CPU.\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/pulse_counter.png\" width=720\u003e\n\u003c/p\u003e\n\nComparing to SAM R34 datasheet, the additional uA current is due to the fact the RF switch is always powered ON in the current Xplained Pro Board design.\n\n\u003e With WLR089U0 Xplained Pro board, the RF switch is controlled by the application and with that improvement the current consumption measured is much lower.\n\nThe result can be observed on the LoRaWAN network server console as well.\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/ttn_application_data.png\" width=640\u003e\n\u003c/p\u003e\n\nFor a Class A device; which is sleeping most of the time; it is important to take into consideration the amount of power when the device is not performing a radio transaction.\nUsing PMM with a longer sleep time parameter is a good practice to reduce the number of wake up events and reduce the overall power consumption.\nOther factors to consider when you want to optimize the overall power consumption of your device are\n- Using highest data rate\n- Transmission output power must be low\n- Payload size must be small\n- Preferred to transmit Unconfirmed message\n\n\u003e If Duty Cycle is enabled (e.g. if EU868 band is used), the duty-cycle timer is interrupting the sleep and giving unexpected wakeups.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Doc/tera_term_04.png\" width=640\u003e\n\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrochiptech%2Fatsamr34_lorawan_smart_meter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrochiptech%2Fatsamr34_lorawan_smart_meter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrochiptech%2Fatsamr34_lorawan_smart_meter/lists"}