TA的每日心情 | 开心 2017-7-4 13:51 |
---|
签到天数: 347 天 连续签到: 1 天 [LV.8]以坛为家I
|
官方库提供了两个串口的例程
选择其中一个
编译下,看看效果
发送r
然后就是长期的卡死了,
可能程序与板子哪还存在问题,检查程序
串口显示到实现
据此修改例程,建立自己的程序
初始化串口引脚
- ioport_set_pin_peripheral_mode(USART0_RXD_GPIO,
- USART0_RXD_FLAGS);
- ioport_set_pin_peripheral_mode(USART0_TXD_GPIO,
- USART0_TXD_FLAGS);
- ioport_set_pin_peripheral_mode(PIN_USART0_SCK_IDX,PIN_USART0_SCK_FLAGS);
- ioport_set_pin_peripheral_mode(PIN_USART0_CTS_IDX,PIN_USART0_CTS_FLAGS);
进一步进行波特率UART配置等
- static void configure_console(void)
- {
- const usart_serial_options_t uart_serial_options = {
- .baudrate = CONF_UART_BAUDRATE,
- #ifdef CONF_UART_CHAR_LENGTH
- .charlength = CONF_UART_CHAR_LENGTH,
- #endif
- .paritytype = CONF_UART_PARITY,
- #ifdef CONF_UART_STOP_BITS
- .stopbits = CONF_UART_STOP_BITS,
- #endif
- };
- /* Configure console UART. */
- sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
- stdio_serial_init(CONF_UART, &uart_serial_options);
- }
进行进一步UART模式配置
- static void configure_usart(uint32_t ul_ismaster, uint32_t ul_baudrate)
- {
- sam_usart_opt_t usart_console_settings = {
- 0,
- US_MR_CHRL_8_BIT,
- US_MR_PAR_NO,
- US_MR_NBSTOP_1_BIT,
- US_MR_CHMODE_NORMAL,
- /* This field is only used in IrDA mode. */
- 0
- };
- usart_console_settings.baudrate = ul_baudrate;
- /* Enable the peripheral clock in the PMC. */
- sysclk_enable_peripheral_clock(BOARD_ID_USART);
- /* Configure USART in SYNC. master or slave mode. */
- if (ul_ismaster) {
- usart_init_sync_master(BOARD_USART, &usart_console_settings, sysclk_get_peripheral_hz());
- } else {
- usart_init_sync_slave(BOARD_USART, &usart_console_settings);
- }
- /* Disable all the interrupts. */
- usart_disable_interrupt(BOARD_USART, ALL_INTERRUPT_MASK);
- /* Enable TX & RX function. */
- usart_enable_tx(BOARD_USART);
- usart_enable_rx(BOARD_USART);
- /* Configure and enable interrupt of USART. */
- NVIC_EnableIRQ(USART_IRQn);
- }
比较奇怪的是进行具体模式配置前,ATMEL直接调用puts就可以进行串口输出了
具体puts定义如图
并没有涉及具体的寄存器,却能进行具体的串口输出,真奇怪,
具体串口相关,见datasheet第44、45章 |
|