XMEGA USART | Embedded Tutorials (wordpress.com)
2021년 11월 11일 목요일
ATxmega-B1 XPLAINED: USART TUTORIAL
ATxmega128a1u /* System Clock Output Port */
/* System Clock Output Port */
typedef enum PORTCFG_CLKOUT_enum
{
PORTCFG_CLKOUT_OFF_gc = (0x00<<0), /* System Clock Output Disabled */
PORTCFG_CLKOUT_PC7_gc = (0x01<<0), /* System Clock Output on Port C pin 7 */
PORTCFG_CLKOUT_PD7_gc = (0x02<<0), /* System Clock Output on Port D pin 7 */
PORTCFG_CLKOUT_PE7_gc = (0x03<<0), /* System Clock Output on Port E pin 7 */
} PORTCFG_CLKOUT_t;
/* Peripheral Clock Output Select */
typedef enum PORTCFG_CLKOUTSEL_enum
{
PORTCFG_CLKOUTSEL_CLK1X_gc = (0x00<<2), /* 1x Peripheral Clock Output to pin */
PORTCFG_CLKOUTSEL_CLK2X_gc = (0x01<<2), /* 2x Peripheral Clock Output to pin */
PORTCFG_CLKOUTSEL_CLK4X_gc = (0x02<<2), /* 4x Peripheral Clock Output to pin */
} PORTCFG_CLKOUTSEL_t;
ATxmega clock Initialize the PLL
/*
Initialize the PLL
-> 48 MHz output frequency
-> 32 MHz internal oscillator as input
*/
OSC.CTRL |= OSC_RC32MEN_bm;
while(!(OSC.STATUS & OSC_RC32MRDY_bm));
OSC.PLLCTRL = OSC_PLLSRC_RC32M_gc | 0x06;
OSC.CTRL |= OSC_PLLEN_bm;
while(!(OSC.STATUS & OSC_PLLRDY_bm));
CCP = CCP_IOREG_gc;
CLK.CTRL = CLK_SCLKSEL_PLL_gc;
ATxmega clock Initialize the internal 32 MHz oscillator
/*
Initialize the internal 32 MHz oscillator
*/
OSC.CTRL |= OSC_RC32MEN_bm;
while(!(OSC.STATUS & OSC_RC32MRDY_bm));
CCP = CCP_IOREG_gc;
CLK.CTRL = CLK_SCLKSEL_RC32M_gc;
ATxmega clock Initialize the internal 2 MHz oscillator
/*
Initialize the internal 2 MHz oscillator
*/
OSC.CTRL |= OSC_RC2MEN_bm;
while(!(OSC.STATUS & OSC_RC2MRDY_bm));
CCP = CCP_IOREG_gc;
CLK.CTRL = CLK_SCLKSEL_RC2M_gc;
ATxmega clock Initialize the external crystal oscillator
/*
Initialize the external crystal oscillator
*/
OSC_XOSCCTRL = OSC_XOSCSEL_XTAL_16KCLK_gc | OSC_FRQRANGE_12TO16_gc;
OSC.CTRL |= OSC_XOSCEN_bm;
while(!(OSC.STATUS & OSC_XOSCRDY_bm));
CCP = CCP_IOREG_gc; CLK.CTRL = CLK_SCLKSEL_XOSC_gc;
/*
Configure the output for the system clock
-> Port C.7
*/
PORTC.DIRSET = (0x01 << 0x07);
PORTCFG.CLKEVOUT |= PORTCFG_CLKOUT_PC7_gc;