Atmel START: Using the SAM E54 Event System with RTC, ADC, USART and DMA - Step 2

Step 2.1: Configure Real-Time Counter (RTC) and Analog-to-Digital Converter (ADC) drivers

1

The RTC is configured to provide an event to ADC for every one second.

1.a

Click on 'TIMER_0' to make a configuration window appear at the bottom.

image10.png

1.b

Configure the timer with the settings below:

  • Configure COMPONENT SETTINGS
    • Driver - 'HAL:Driver:Timer'
      • Enables timer hardware abstraction layer driver.
    • Instance - 'RTC'
      • Timer is configured as real time counter (RTC).
  • Configure RTC CLOCKS
    • RTC - 'RTC source (32.77 kHz)'
      • RTC clock is sourced from 32 kHz ultra-low power internal oscillator.
  • Configure RTC BASIC SETTINGS
    • Force reset RTC on initialization - 'Enable'
      • Enabling this clears previous power down data available in RTC.
    • Prescaler Configuration - 'OFF' (Peripheral clock divided by 1)
      • The RTC 32 kHz clock is used, no need for division.
    • Compare Value - '32770' (to get an interrupt every one second)
      • Compare value is equal to RTC source clock multiplied by time (32.77 k * 1000 ms = 32770).
image11.png
Click image to enlarge.

2

Configure the ADC instance to convert the I/O1 Xplained Pro board's light sensor from analog value to digital.

2.a

Click on 'ADC_0' to make a configuration window appear at the bottom.

image12.png

The light sensor is connected to PIN3 of the I/O1 Xplained Pro board and the board is connected to Extension Header 1 (EXT1) of the SAME54 Xplained pro board. EXT1 header PIN3 is connected to ADC1/AIN[6] (PB04) of ATSAME54P20A IC. Hence, you will configure ADC for this pin.

2.b

Configure ADC with the settings below:

  • Configure COMPONENT SETTINGS
    • Driver - 'HAL:Driver: ADC_Async'
      • ADC must be used through an asynchronous path as it will be started by the RTC event. It returns immediately, even if the requested number of data is not available. Since the event system is monitoring the ADC Result register, there is no scope of the application to wait for until the ADC data is available. The system can be in sleep mode until the ADC data available event system automatically moves the result to the UART RX register.
    • Instance - 'ADC1'
      • ADC1 is selected because EXT1 header of SAM E54 Xplained board has pin connections to ADC1
  • CLOCKS
    • ADC - 'Generic clock generator 0 (12 MHz)'
      • Clock for ADC is sourced from 12 MHz clock generator
  • SIGNALS
    • AIN/6 - 'PB04'
      • The signal to convert is the one coming from the light sensor located on the I/O1 Xplained Pro extension on the PIN3 as described in the I/O1 Xplained Pro user's guide.
image13.png
  • BASIC CONFIGURATION
    • Conversion Result Resolution - '8-bit'
      • Conversion result is set to '8-bit' to get one byte value varying from 0x00 to 0xFF.
    • Reference Selection - 'VDDANA'
      • Analog reference voltage is set to 'VDDANA' because the light sensor operates between 0 to 3.3 volts.
    • Prescaler configuration - 'Peripheral clock divided by 4'
      • ADC is configured to operate at 3 MHz to start conversion (i.e., Peripheral clock / 4 => 12 M/4 = 3 MHz).
    • Free Running Mode - 'Disable'
    • Differential Mode - 'Disable'
    • Positive Mux Input Selection - 'ADC AIN6 pin'
    • Negative Mux Input Selection - 'Internal ground'
  • ADVANCED CONFIGURATION
    • Enable ADVANCED CONFIGURATION
    • Run in standby - 'Enable'
      • The peripheral will run in standby mode and will be able to respond to events even with the device in sleep mode.
    • On Demand Control - 'Enable'
      • Device will be in sleep mode and the clock is enabled on demand whenever necessary.
image14.png

Step 2.2: Configure USART and EVENT SYSTEM drivers

1

The USART is configured to display the light sensor values on serial terminal.

1.a

Click on the 'USART_0' instance to make a configuration window appear at the bottom.

image15.png

1.b

Configure USART with the following settings:

  • Configure COMPONENT SETTINGS
    • Driver - 'HAL:Driver:USART_Sync'
      • USART synchronous driver configured to transfer light data to the serial port.
    • Mode - 'UART'
    • Instance - 'SERCOM2'
      • The SAME54 Xplained pro board's virtual com port uses SERCOM2.
  • CLOCKS
    • Core - 'Generic clock generator 0 (12 MHz)'
    • Slow - 'Generic clock generator 0 (12 MHz)'
  • SIGNALS
    • RX - 'PB24'
      • The SAME54 Xplained pro board receiver pin of the virtual com port is connected to PB24.
    • TX - 'PB25'
      • The SAME54 Xplained pro board transmitter pin of virtual com port is connected to PB25.
  • BASIC CONFIGURATION
    • Receive buffer enable - 'Enable'
    • Transmitt buffer enable - 'Enable'
    • Frame Parity - 'No parity'
    • Character Size - '8 bits'
    • Stop bit - 'One stop bit'
    • Baud rate - '9600'
image16.png
Click image to enlarge.

2

The 'Event System' is configured to trigger events without CPU intervention. Configure RTC as an event generator to generate periodic (every second) events to the ADC through the 'Event System'.

2.a

Click on the 'EVENTS' image17.png tab to open the 'EVENT SYSTEM CONFIGURATOR' as shown:
image18.png

2.b

Enable RTC as an event generator.

image19.png

2.c

Click on the cog wheel image20.png, select 'EVENT SOURCES' as 'RTC COMPARE 0 (Compare 0 Event Output)' and close the window.
image21.png

2.d

Enable 'Channel 0' under 'CHANNELS'.

image22.png

2.e

Click on the cog wheel image23.png and change the settings as follows:
  • CHANNEL 0 SETTINGS
    • Edge detection - 'No event output when using the resynchronised or synchronous path'
      • Since event is triggered after the timer expires.
    • Path selection - 'Asynchronous path'
      • No blocking calls, event system triggers the configured peripheral.
    • Event generator - 'RTC Compare 0'
      • RTC is configured to generate event.
    • On demand clock - 'Enable'
      • Device will be in sleep mode, clock is enabled on demand whenever necessary.
    • Run in standby mode - 'Enable'
      • The peripheral will run in standby mode and will be able to respond to events even with the device in sleep mode.
    • Close the window.
image24.png

2.f

Enable 'ADC1' under 'USERS'.

image25.png

2.g

Click on the cog wheel image26.png and change the settings as as follows:
  • TRIGGER CONVERSION ON EVENT
    • Trigger Conversion On Event - 'Enable'
      • This configures trigger to start conversion when event occurs.
    • Channel selection for ADC1 start conversion event - 'Channel 0'
      • This allows conversion to happen in Channel 0.
    • Close the window.
image27.png

2.h

After configuration, the 'EVENT SYSTEM CONFIGURATOR' should appear as follows:

image28.png
Click image to enlarge.

Step 2.3: Configure clock system to run in standby mode

All clock modules will be configured to run in standby mode, since all tasks or operations do not need CPU intervention.

1

Click on the 'CLOCKS' image29.png tab to open the 'CLOCK CONFIGURATOR' as shown:
image30.png

2

Click on the cog wheel image33.png of 'Generic clock generator 0'.
image34.png

3

Enable 'Run in Standby' and close the window.

image35.png

4

Click on the cog wheel image33.png of 'External Crystal Oscillator 8 - 48 MHz (XOSC1).
image31.png

5

Enable 'Run in Standby' and close the window.

image32.png

Step 2.4: Generate and open the project in Atmel Studio

1

Click on GENERATE PROJECT.

image36.png

2

Atmel START downloads the project and opens 'Atmel Start Importer'. Specify the following details:
Project Name : event_based_drivers
Location : <Folder of your choice>
Solution: Create New Solution
Solution Name: event_based_drivers

image38.png

3

After clicking OK, a project will be created and finally the solution explorer should appear as follows:

image39.png



Next Step >

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site 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 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.