Forum: Mikrocontroller und Digitale Elektronik SAMD21 UART SERCOM ASF


von Werner P. (Gast)


Lesenswert?

Hallo zusammen,

bastle grad mit einem SAMD21 an der Ausgabe einer UART.

Verwende Atmel Studio 7.
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
}

Bis auf die UART Ausgabe funktioniert soweit alles. Denke es liegt an 
der Konfiguration der UART.

TX = PA00, RX = PA01

Danke im voraus.

von Werner P. (Gast)


Lesenswert?

nach etwas Suche zum Laufen gebracht.

TX = PA10
RX = PA11

neue Config:
1
void configure_usart(void)
2
{
3
  
4
  struct usart_config config_usart;
5
  usart_get_config_defaults(&config_usart);
6
7
  config_usart.baudrate    = 9600;
8
  config_usart.mux_setting = USART_RX_3_TX_2_XCK_3;
9
  config_usart.pinmux_pad2 = PINMUX_PA10C_SERCOM0_PAD2;
10
  config_usart.pinmux_pad3 = PINMUX_PA11C_SERCOM0_PAD3;
11
  config_usart.pinmux_pad0 = PINMUX_UNUSED;
12
  config_usart.pinmux_pad1 = PINMUX_UNUSED;
13
  config_usart.generator_source = GCLK_GENERATOR_0;
14
  
15
  while (usart_init(&usart_instance,SERCOM0, &config_usart) != STATUS_OK) {
16
  }
17
18
  usart_enable(&usart_instance);
19
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.