- void wk_usart1_init(void)
- {
- crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
- crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
- crm_periph_clock_enable(CRM_USART1_PERIPH_CLOCK, TRUE);
-
- gpio_init_type gpio_init_struct;
- gpio_default_para_init(&gpio_init_struct);
- /* configure the TX pin */
- gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
- gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
- gpio_init_struct.gpio_pins = GPIO_PINS_9;
- gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- gpio_init(GPIOA, &gpio_init_struct);
- /* configure the RX pin */
- gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
- gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
- gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
- gpio_init_struct.gpio_pins = GPIO_PINS_10;
- gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
- gpio_init(GPIOA, &gpio_init_struct);
-
- /* configure param */
- usart_init(USART1, 115200U, USART_DATA_8BITS, USART_STOP_1_BIT);
- usart_transmitter_enable(USART1, TRUE);
- usart_receiver_enable(USART1, TRUE);
- #if USE_IDLE_DMA
- usart_dma_receiver_enable(USART1, TRUE);
- #endif
-
- nvic_irq_enable(USART1_IRQn, 1, 0);
-
- #if USE_IDLE_DMA
- usart_interrupt_enable(USART1, USART_IDLE_INT, TRUE);
- #else
- usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE);
- #endif
-
- usart_enable(USART1, TRUE);
- }
发送123vh,第一次能全部返回,后面再发送就辉丢失第一个字节,格式是123vh23vh23vh....
|