I'm trying to get send data on a UART line on a custom board with a AT32UC3C2512C microcontroller. I've never used Atmel before (except Arduino) so I don't know what I'm doing.
So far, I have the UART sending data, but the data rate is slow. I put 115200 as the baudrate, but the actual signal is 642.
The board has a 20MHz crystal as XTAL0. I've tested a blinky code and it seams to run at the correct speed.
Is there something I'm missing?
#define BOARD_OSC0_HZ 20000000 #define BOARD_OSC0_STARTUP_US 142000 #define BOARD_OSC0_IS_XTAL true
#include <asf.h> #include <gpio.h> #include <delay.h> #include <usart.h> # define USART (&AVR32_USART0) # define USART_RX_PIN AVR32_USART0_RXD_2_PIN # define USART_RX_FUNCTION AVR32_USART0_RXD_2_FUNCTION # define USART_TX_PIN AVR32_USART0_TXD_2_PIN # define USART_TX_FUNCTION AVR32_USART0_TXD_2_FUNCTION # define TARGET_PBACLK_FREQ_HZ BOARD_OSC0_HZ// PBA clock target frequency, in Hz int main (void) { sysclk_init(); board_init(); static const gpio_map_t USART_GPIO_MAP = { {USART_RX_PIN, USART_RX_FUNCTION}, {USART_TX_PIN, USART_TX_FUNCTION} }; // USART options. static const usart_options_t USART_OPTIONS = { .baudrate = 115200, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = USART_NORMAL_CHMODE }; // Assign GPIO to USART. gpio_enable_module(USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); // Initialize USART in RS232 mode. usart_init_rs232(USART, &USART_OPTIONS, TARGET_PBACLK_FREQ_HZ); while (true) { usart_write_line(USART, "Hello world!"); delay_ms(200); } }
Not sure if this will make a difference, but... I always specify my defines (greater than 64K) as unsigned long.
Edit: Strike through due to post #3.
I knew I shouldn't respond to a post on a processor I have never used!
David (aka frog_jr)
Top
- Log in or register to post comments
Except that this is a 32 bit micro ;-)
Top
- Log in or register to post comments
Your system clock is still the default 115 kHz.
115200 baud desired * ( 115 kHZ actual / 20 MHz desired ) = 662 baud actual.
Something is wrong (or missing) with the #defines that sysclk_init() uses to configure the clock(s).
Top
- Log in or register to post comments
Fixed it!
The problem was in conf_clock.h. CONFIG_SYSCLK_SOURCE was defined as SYSCLK_SRC_RCSYS. I changed it to SYSCLK_SRC_OSC0 and its working now
Top
- Log in or register to post comments