Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. #include <asf.h>
  2.  
  3. void usart_clock_init (void);
  4. void usart_pin_init (void);
  5.  
  6. static inline void pin_set_peripheral_function (uint32_t pinmux);
  7.  
  8. static inline void pin_set_peripheral_function (uint32_t pinmux)
  9. {
  10.   uint8_t port = (uint8_t)((pinmux >> 16)/32);
  11.   PORT->Group[port].PINCFG[((pinmux >> 16) - (port*32))].bit.PMUXEN = 1;
  12.   PORT->Group[port].PMUX[((pinmux >> 16) - (port*32))/2].reg &= ~(0xF << (4 * ((pinmux >> 16) & 0x01u)));
  13.   PORT->Group[port].PMUX[((pinmux >> 16) - (port*32))/2].reg |= (uint8_t)((pinmux & 0x0000FFFF) << (4 * ((pinmux >> 16) & 0x01u)));
  14. }
  15.  
  16. void usart_clock_init (void)
  17. {
  18.   struct system_gclk_chan_config gclk_chan_conf;
  19.   uint32_t gclk_index = SERCOM3_GCLK_ID_CORE;
  20.   system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, PM_APBCMASK_SERCOM3);
  21.   system_gclk_chan_get_config_defaults(&gclk_chan_conf);
  22.   system_gclk_chan_set_config(gclk_index, &gclk_chan_conf);
  23.   system_gclk_chan_enable(gclk_index);
  24. }
  25.  
  26. void usart_pin_init (void)
  27. {
  28.   pin_set_peripheral_function(PINMUX_PA20D_SERCOM3_PAD2);
  29.   pin_set_peripheral_function(PINMUX_PA21D_SERCOM3_PAD3);
  30. }
  31.  
  32. int main (void)
  33. {
  34.   system_init();
  35.   usart_clock_init();
  36.   usart_pin_init();
  37.  
  38.   struct usart_config usart_conf;
  39.   struct usart_module usart_mod;
  40.   usart_get_config_defaults (&usart_conf);
  41.   stdio_serial_init(&usart_mod, SERCOM3, &usart_conf);
  42.   usart_enable(&usart_mod);
  43.  
  44.   usart_write_wait(&usart_mod, (uint16_t)'a');
  45.   usart_write_wait(&usart_mod, (uint16_t)'b');
  46.   usart_write_wait(&usart_mod, (uint16_t)'c');
  47.   usart_write_wait(&usart_mod, (uint16_t)'d');
  48.   usart_write_wait(&usart_mod, (uint16_t)'e');
  49.   usart_write_wait(&usart_mod, (uint16_t)'f');
  50.   usart_write_wait(&usart_mod, (uint16_t)'g');
  51.   usart_write_wait(&usart_mod, (uint16_t)'h');
  52.   usart_write_wait(&usart_mod, (uint16_t)'i');
  53.   usart_write_wait(&usart_mod, (uint16_t)'j');
  54.   usart_write_wait(&usart_mod, (uint16_t)'k');
  55.   usart_write_wait(&usart_mod, (uint16_t)'l');
  56.   usart_write_wait(&usart_mod, (uint16_t)'m');
  57.   usart_write_wait(&usart_mod, (uint16_t)'n');
  58.   usart_write_wait(&usart_mod, (uint16_t)'o');
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement