10.
Appendix
Code examples for each use case in this technical brief.
Example 10-1. Polling VDDIO2 Status
#define F_CPU 4000000ul
#include <avr/io.h>
int main(void)
{
while (1)
{
/*Check if VDDIO2 is within acceptable range*/
if(MVIO.STATUS & MVIO_VDDIO2S_bm)
{
/* Replace with your application code */
}
}
}
Example 10-2. Interrupt on VDDIO2 Status
#define F_CPU 4000000ul
#include <avr/io.h>
#include <avr/interrupt.h>
void LED0_init(void) {
PORTF.DIRSET = PIN5_bm;
}
void LED0_toggle(void) {
PORTF.OUTTGL = PIN5_bm;
}
int main(void)
{
/*Enable the VDDIO2 interrupt*/
MVIO.INTCTRL |= MVIO_VDDIO2IE_bm;
/*Enable Global interrupts*/
sei();
LED0_init();
/* Replace with your application code */
while (1)
{
}
}
ISR(MVIO_MVIO_vect)
{
/* The VDDIO2 interrupt has been triggered */
LED0_toggle();
/* Clear the CFD interrupt flag */
MVIO.INTFLAGS |= MVIO_VDDIO2IF_bm;
}
Example 10-3. Measuring VDDIO2
#define F_CPU 4000000ul
/*Initialize ADC0*/
void adc0_init(void)
{
/*Select the 1.024V referance for ADC0*/
VREF.ADC0REF = VREF_REFSEL_1V024_gc;
TB3287
Appendix
©
2020 Microchip Technology Inc.
Technical Brief
DS90003287A-page 19