1 | #include <asf.h>
|
2 |
|
3 | #include <stdio.h>
|
4 | #include <string.h>
|
5 |
|
6 | #define SENSOR_LEFT PIN_PA14
|
7 | #define SENSOR_RIGHT PIN_PA09
|
8 |
|
9 | #define LED_TEST PIN_PA07
|
10 |
|
11 | struct usart_module usart_instance;
|
12 |
|
13 | // Function Prototypes
|
14 |
|
15 | void configure_port_pins(void);
|
16 | void configure_usart(void);
|
17 |
|
18 | // Functions
|
19 |
|
20 | void configure_port_pins(void)
|
21 | {
|
22 |
|
23 | struct port_config config_port_pin;
|
24 |
|
25 | port_get_config_defaults(&config_port_pin);
|
26 |
|
27 | // SENSOR LEFT
|
28 | config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
29 | config_port_pin.input_pull = PORT_PIN_PULL_UP;
|
30 | port_pin_set_config(SENSOR_LEFT, &config_port_pin);
|
31 |
|
32 | // SENSOR RIGHT
|
33 | config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
34 | config_port_pin.input_pull = PORT_PIN_PULL_UP;
|
35 | port_pin_set_config(SENSOR_RIGHT, &config_port_pin);
|
36 |
|
37 | // LED TEST
|
38 | config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
|
39 | port_pin_set_config(LED_TEST, &config_port_pin);
|
40 | port_pin_set_output_level(LED_TEST,false);
|
41 |
|
42 | }
|
43 |
|
44 | void configure_usart(void)
|
45 | {
|
46 |
|
47 | struct usart_config config_usart;
|
48 | usart_get_config_defaults(&config_usart);
|
49 |
|
50 | config_usart.baudrate = 9600;
|
51 | config_usart.mux_setting = USART_RX_1_TX_0_XCK_1;
|
52 | config_usart.pinmux_pad0 = PINMUX_PA00D_SERCOM1_PAD0;
|
53 | config_usart.pinmux_pad1 = PINMUX_PA01D_SERCOM1_PAD1;
|
54 | config_usart.pinmux_pad2 = PINMUX_UNUSED;
|
55 | config_usart.pinmux_pad3 = PINMUX_UNUSED;
|
56 | config_usart.generator_source = GCLK_GENERATOR_0;
|
57 |
|
58 | while (usart_init(&usart_instance,SERCOM1, &config_usart) != STATUS_OK) {
|
59 | }
|
60 |
|
61 | usart_enable(&usart_instance);}
|
62 |
|
63 | // Systick
|
64 | void SysTick_Handler (void)
|
65 | {
|
66 | static int flag = 0;
|
67 |
|
68 | if (flag) {
|
69 | flag = 0;
|
70 | port_pin_set_output_level(LED_TEST,false);
|
71 | } else {
|
72 | flag = 1;
|
73 | port_pin_set_output_level(LED_TEST,true);
|
74 | }
|
75 |
|
76 | }
|
77 |
|
78 | // Main
|
79 | int main (void)
|
80 | {
|
81 | system_init();
|
82 |
|
83 | configure_port_pins();
|
84 | configure_usart();
|
85 |
|
86 | SysTick_Config(SystemCoreClock/1200);
|
87 | system_interrupt_enable(SYSTEM_INTERRUPT_SYSTICK);
|
88 |
|
89 | uint8_t buf[] = "Hello World\r\n";
|
90 | usart_write_buffer_wait(&usart_instance, buf, sizeof(buf));
|
91 |
|
92 | while (true) {
|
93 |
|
94 |
|
95 | }
|
96 |
|
97 | }
|