搜索

GD32VF103的串口发送问题(已解决)

[复制链接]
38|3
 楼主 | 2020-9-16 11:07 | 显示全部楼层 |阅读模式
本帖最后由 binbin0317 于 2020-9-16 11:24 编辑

LED测试通过了,但是第二部连用个串口都不行,用的是GD32VF103C_START开发板,串口代码直接按例子弄的。直接用示波器点PA9脚的那个脚完全没有出现发送波形(PC端敲字符,PA10是可以看到数据的)。单步调试过了,时钟有使能,IO有配置,USART0也有配置(BAUD寄存器是0x000003AA,CTL0是0x0000200C)。也有正常进入_put_char函数。这……究竟是哪里错了???更新:好了,知道什么问题了,有个跳线需要跳。
  1. /*!
  2.     \file  main.c
  3.     \brief running led demo

  4.     \version 2019-06-05, V1.0.0, demo for GD32VF103
  5. */

  6. /*
  7.     Copyright (c) 2019, GigaDevice Semiconductor Inc.

  8.     Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:

  10.     1. Redistributions of source code must retain the above copyright notice, this
  11.        list of conditions and the following disclaimer.
  12.     2. Redistributions in binary form must reproduce the above copyright notice,
  13.        this list of conditions and the following disclaimer in the documentation
  14.        and/or other materials provided with the distribution.
  15.     3. Neither the name of the copyright holder nor the names of its contributors
  16.        may be used to endorse or promote products derived from this software without
  17.        specific prior written permission.

  18.     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #include <stdio.h>
  30. #include "gd32vf103.h"
  31. #include "gd32vf103c_start.h"
  32. #include "systick.h"

  33. void usart0_config(void);
  34. /*!
  35.     \brief      main function
  36.     \param[in]  none
  37.     \param[out] none
  38.     \retval     none
  39. */
  40. int main(void)
  41. {  
  42.         usart0_config();
  43.     /* enable the LED clock */
  44.     rcu_periph_clock_enable(RCU_GPIOA);
  45.     /* configure LED GPIO port */
  46.     gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);

  47.     gpio_bit_reset(GPIOA, GPIO_PIN_7);

  48.     while(1){
  49.         /* insert 500 ms delay */
  50.         delay_1ms(500);

  51.         /* toggle the LED */
  52.         gpio_bit_write(GPIOA, GPIO_PIN_7, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_7)));
  53.         
  54.         /* insert 500 ms delay */
  55.         delay_1ms(500);
  56.         printf("123\r\n");
  57.     }
  58. }

  59. /*!
  60. \brief      USART0 configure
  61. \param[in]  none
  62. \param[out] none
  63. \retval     none
  64. */
  65. void usart0_config(void)
  66. {
  67.         /* enable USART clock */
  68.         rcu_periph_clock_enable(RCU_USART0);
  69.         #if defined USART0_REMAP
  70.         /* enable GPIO clock */
  71.         rcu_periph_clock_enable(RCU_GPIOB);
  72.         rcu_periph_clock_enable(RCU_AF);
  73.         /* USART0 remapping */
  74.         gpio_pin_remap_config(GPIO_USART0_REMAP, ENABLE);
  75.         /* connect port to USARTx_Tx */
  76.         gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
  77.         /* connect port to USARTx_Rx */
  78.         gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
  79.         #else
  80.         /* enable GPIO clock */
  81.         rcu_periph_clock_enable(RCU_GPIOA);

  82.         /* connect port to USARTx_Tx */
  83.         gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
  84.         /* connect port to USARTx_Rx */
  85.         gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
  86.         #endif

  87.         /* USART configure */
  88.         usart_deinit(USART0);
  89.         usart_baudrate_set(USART0, 115200U);
  90.         usart_word_length_set(USART0, USART_WL_8BIT);
  91.         usart_stop_bit_set(USART0, USART_STB_1BIT);
  92.         usart_parity_config(USART0, USART_PM_NONE);
  93.         usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
  94.         usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
  95.         usart_receive_config(USART0, USART_RECEIVE_ENABLE);
  96.         usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
  97.         usart_enable(USART0);
  98. }

  99. /* retarget the C library printf function to the USART */
  100. int _put_char(int ch)
  101. {
  102. usart_data_transmit(USART0, (uint8_t) ch );
  103. while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){
  104. }

  105. return ch;
  106. }
复制代码



使用特权

评论回复
| 2020-9-16 15:19 | 显示全部楼层
打PP的帖子。

使用特权

评论回复
| 2020-9-16 15:42 | 显示全部楼层

使用特权

评论回复
 楼主 | 2020-9-16 16:00 | 显示全部楼层
没办法啊,就一个原理图,文字什么的都不愿意多说几个。demo_suite的demo少得可怜。唉

使用特权

评论回复
扫描二维码,随时随地手机跟帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

我要发帖 投诉建议 创建版块 申请版主

快速回复

您需要登录后才可以回帖
登录 | 注册
高级模式

论坛热帖

在线客服 快速回复 返回顶部 返回列表