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.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).
- Driver - 'HAL:Driver:Timer'
- Configure RTC CLOCKS
- RTC - 'RTC source (32.77 kHz)'
- RTC clock is sourced from 32 kHz ultra-low power internal oscillator.
- RTC - 'RTC source (32.77 kHz)'
- 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).
- Force reset RTC on initialization - 'Enable'
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.
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
- Driver - 'HAL:Driver: ADC_Async'
- CLOCKS
- ADC - 'Generic clock generator 0 (12 MHz)'
- Clock for ADC is sourced from 12 MHz clock generator
- ADC - 'Generic clock generator 0 (12 MHz)'
- 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.
- AIN/6 - 'PB04'
- 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'
- Conversion Result Resolution - '8-bit'
- 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.
Step 2.2: Configure USART and EVENT SYSTEM drivers
1
The USART is configured to display the light sensor values on serial terminal.
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.
- Driver - 'HAL:Driver:USART_Sync'
- 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.
- RX - 'PB24'
- 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'
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.e
- 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.
- Edge detection - 'No event output when using the resynchronised or synchronous path'
2.g
- 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.
- Trigger Conversion On Event - 'Enable'
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.