Hi,
ich habe einen SAM4s Xplained und will UART1 benutzen, kann aber kein
Beispiel und sonst auch keine Hilfe finden. Mein eigener Versuch ist
auch fehlgeschlagen, aber ich bin mir sicher, dass es nur an einer
kleinigkeit liegt.
Hier ist mein Code:
conf_uart.h
1 | #include "asf.h" //uart.h etc. included here
|
2 | #include <sam4s_xplained.h>
|
3 |
|
4 | #define UART_SERIAL_BAUDRATE 9600
|
5 | #define UART_SERIAL_CHANNEL_MODE UART_MR_CHMODE_AUTOMATIC //UART_MR_CHMODE_NORMAL
|
6 | #define UART_SERIAL_MCK 240000000UL //CHIP_FREQ_CPU_MAX (tried both!)
|
7 | #define UART_SERIAL_MODE UART_MR_PAR_NO
|
8 |
|
9 | void uart_custom_init(void);
|
conf_uart.c
1 | #include "conf_uart.h"
|
2 |
|
3 | uint8_t received_byte;
|
4 |
|
5 | void uart_custom_init(void) {
|
6 | sysclk_init();
|
7 |
|
8 | const sam_uart_opt_t uart_console_settings = {
|
9 | UART_SERIAL_BAUDRATE,
|
10 | UART_SERIAL_CHANNEL_MODE,
|
11 | UART_SERIAL_MCK,
|
12 | UART_SERIAL_MODE
|
13 | };
|
14 |
|
15 | uart_init(UART1,&uart_console_settings); //Init UART1
|
16 |
|
17 | uart_enable_rx(UART1); //Enable RX (receiving)
|
18 | uart_enable_tx(UART1); //Enable TX (transmitting)
|
19 | uart_enable(UART1); //Enable UART1
|
20 |
|
21 | uart_enable_interrupt(UART1,UART_IER_RXRDY); //Interrupt reading ready
|
22 | NVIC_EnableIRQ(UART1_IRQn);
|
23 |
|
24 | }
|
25 |
|
26 | void UART1_Handler() {
|
27 | uint32_t dw_status = uart_get_status(UART1);
|
28 |
|
29 | if(dw_status & UART_SR_RXRDY) {
|
30 | uint8_t received_byte;
|
31 | uart_read(UART1, &received_byte);
|
32 | uart_write(UART1, received_byte);
|
33 | }
|
34 | }
|
Ich habe verschiedene Dinge versucht, z.B. habe ich automatic echo
eingestellt. Aber Ich empfange einfach nichts beim Computer oder beim
Microprozessor...
(Mit nem AVR hab ichs schon geschaft, muss aber umsteigen...)
Hoffe ihr Könnt mir helfen!
Lg
leodennis