Hallo,
ich möchte bei meinem SAM4E XPlainedPro eine Uart Schnittstelle in
Betrieb nehmen, was einfach nicht funktionieren will.
Uart0 ist scheinbar für den EDGB reserviert, daher will ich den Uart1 in
Betrieb nehmen. Leider gibt es keine entsprechenden Beispiele.
Für den SAM4S habe ich folgendes gefunden:
http://stackoverflow.com/questions/14280053/atmel-sam4s-xplained-uart
die defines habe ich dann entsprechend dem SAM4E angepasst, womit dieser
(ebenfalls nicht funktionierender Code raus kommt:
1 | #include <asf.h>
|
2 |
|
3 | #include "stdio.h"
|
4 |
|
5 | #define UART_SERIAL_BAUDRATE 9600
|
6 | #define UART_SERIAL_CHANNEL_MODE UART_MR_CHMODE_NORMAL
|
7 | #define UART_SERIAL_MODE UART_MR_PAR_NO
|
8 |
|
9 | /* =============== UART1 =============== */ //(UART0 is defined but not UART1)
|
10 | #define PINS_UART1 (PIO_PA5 | PIO_PA6)
|
11 | #define PINS_UART1_FLAGS (PIO_PERIPH_C | PIO_DEFAULT)
|
12 | #define PINS_UART1_MASK (PIO_PA5 | PIO_PA6)
|
13 | #define PINS_UART1_PIO PIOC
|
14 | #define PINS_UART1_ID ID_PIOC
|
15 | #define PINS_UART1_TYPE PIO_PERIPH_C
|
16 | #define PINS_UART1_ATTR PIO_DEFAULT
|
17 |
|
18 | void uart_custom_init(void) {
|
19 | sysclk_init();
|
20 |
|
21 | // set the pins to use the uart peripheral
|
22 | pio_configure(PINS_UART1_PIO, PINS_UART1_TYPE, PINS_UART1_MASK, PINS_UART1_ATTR);
|
23 |
|
24 | //enable the uart peripherial clock
|
25 | pmc_enable_periph_clk(ID_UART1);
|
26 |
|
27 | const sam_uart_opt_t uart1_settings =
|
28 | { sysclk_get_cpu_hz(), UART_SERIAL_BAUDRATE, UART_SERIAL_MODE };
|
29 |
|
30 | uart_init(UART1,&uart1_settings); //Init UART1 and enable Rx and Tx
|
31 |
|
32 | uart_enable_interrupt(UART1,UART_IER_RXRDY); //Interrupt reading ready
|
33 | NVIC_EnableIRQ(UART1_IRQn);
|
34 |
|
35 | }
|
36 |
|
37 | void sendViaUart(uint8_t data) {
|
38 | while (!(UART1->UART_SR & UART_SR_TXRDY));
|
39 | uart_write(UART1, data);
|
40 | }
|
41 |
|
42 | void UART1_Handler() {
|
43 | uint32_t dw_status = uart_get_status(UART1);
|
44 |
|
45 | if(dw_status & UART_SR_RXRDY) {
|
46 | uint8_t received_byte;
|
47 | uart_read(UART1, &received_byte);
|
48 | //sendViaUart(received_byte);
|
49 | }
|
50 | }
|
51 |
|
52 | int main (void)
|
53 | {
|
54 | uart_custom_init();
|
55 | while (1) {
|
56 | sendViaUart('a');
|
57 | }
|
58 | }
|
Als ersten Schritt möchte ich einfach nur ein paar Bytes senden.
Überprüfen tu ich das direkt am Pin mit einem Oszi.
danke für eure Hilfe