Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <asf.h>
- void usart_clock_init (void);
- void usart_pin_init (void);
- static inline void pin_set_peripheral_function (uint32_t pinmux);
- static inline void pin_set_peripheral_function (uint32_t pinmux)
- {
- uint8_t port = (uint8_t)((pinmux >> 16)/32);
- PORT->Group[port].PINCFG[((pinmux >> 16) - (port*32))].bit.PMUXEN = 1;
- PORT->Group[port].PMUX[((pinmux >> 16) - (port*32))/2].reg &= ~(0xF << (4 * ((pinmux >> 16) & 0x01u)));
- PORT->Group[port].PMUX[((pinmux >> 16) - (port*32))/2].reg |= (uint8_t)((pinmux & 0x0000FFFF) << (4 * ((pinmux >> 16) & 0x01u)));
- }
- void usart_clock_init (void)
- {
- struct system_gclk_chan_config gclk_chan_conf;
- uint32_t gclk_index = SERCOM3_GCLK_ID_CORE;
- system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, PM_APBCMASK_SERCOM3);
- system_gclk_chan_get_config_defaults(&gclk_chan_conf);
- system_gclk_chan_set_config(gclk_index, &gclk_chan_conf);
- system_gclk_chan_enable(gclk_index);
- }
- void usart_pin_init (void)
- {
- pin_set_peripheral_function(PINMUX_PA20D_SERCOM3_PAD2);
- pin_set_peripheral_function(PINMUX_PA21D_SERCOM3_PAD3);
- }
- int main (void)
- {
- system_init();
- usart_clock_init();
- usart_pin_init();
- struct usart_config usart_conf;
- struct usart_module usart_mod;
- usart_get_config_defaults (&usart_conf);
- stdio_serial_init(&usart_mod, SERCOM3, &usart_conf);
- usart_enable(&usart_mod);
- usart_write_wait(&usart_mod, (uint16_t)'a');
- usart_write_wait(&usart_mod, (uint16_t)'b');
- usart_write_wait(&usart_mod, (uint16_t)'c');
- usart_write_wait(&usart_mod, (uint16_t)'d');
- usart_write_wait(&usart_mod, (uint16_t)'e');
- usart_write_wait(&usart_mod, (uint16_t)'f');
- usart_write_wait(&usart_mod, (uint16_t)'g');
- usart_write_wait(&usart_mod, (uint16_t)'h');
- usart_write_wait(&usart_mod, (uint16_t)'i');
- usart_write_wait(&usart_mod, (uint16_t)'j');
- usart_write_wait(&usart_mod, (uint16_t)'k');
- usart_write_wait(&usart_mod, (uint16_t)'l');
- usart_write_wait(&usart_mod, (uint16_t)'m');
- usart_write_wait(&usart_mod, (uint16_t)'n');
- usart_write_wait(&usart_mod, (uint16_t)'o');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement