打印

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

[复制链接]
1645|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
binbin0317|  楼主 | 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函数。这……究竟是哪里错了???更新:好了,知道什么问题了,有个跳线需要跳。
/*!
    \file  main.c
    \brief running led demo

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

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

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

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

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

void usart0_config(void);
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{  
        usart0_config();
    /* enable the LED clock */
    rcu_periph_clock_enable(RCU_GPIOA);
    /* configure LED GPIO port */
    gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);

    gpio_bit_reset(GPIOA, GPIO_PIN_7);

    while(1){
        /* insert 500 ms delay */
        delay_1ms(500);

        /* toggle the LED */
        gpio_bit_write(GPIOA, GPIO_PIN_7, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_7)));
        
        /* insert 500 ms delay */
        delay_1ms(500);
        printf("123\r\n");
    }
}

/*!
\brief      USART0 configure
\param[in]  none
\param[out] none
\retval     none
*/
void usart0_config(void)
{
        /* enable USART clock */
        rcu_periph_clock_enable(RCU_USART0);
        #if defined USART0_REMAP
        /* enable GPIO clock */
        rcu_periph_clock_enable(RCU_GPIOB);
        rcu_periph_clock_enable(RCU_AF);
        /* USART0 remapping */
        gpio_pin_remap_config(GPIO_USART0_REMAP, ENABLE);
        /* connect port to USARTx_Tx */
        gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
        /* connect port to USARTx_Rx */
        gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
        #else
        /* enable GPIO clock */
        rcu_periph_clock_enable(RCU_GPIOA);

        /* connect port to USARTx_Tx */
        gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
        /* connect port to USARTx_Rx */
        gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
        #endif

        /* USART configure */
        usart_deinit(USART0);
        usart_baudrate_set(USART0, 115200U);
        usart_word_length_set(USART0, USART_WL_8BIT);
        usart_stop_bit_set(USART0, USART_STB_1BIT);
        usart_parity_config(USART0, USART_PM_NONE);
        usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
        usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
        usart_receive_config(USART0, USART_RECEIVE_ENABLE);
        usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
        usart_enable(USART0);
}

/* retarget the C library printf function to the USART */
int _put_char(int ch)
{
usart_data_transmit(USART0, (uint8_t) ch );
while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){
}

return ch;
}



使用特权

评论回复
沙发
lvben5d| | 2020-9-16 15:19 | 只看该作者
打PP的帖子。

使用特权

评论回复
板凳
xdqfc| | 2020-9-16 15:42 | 只看该作者

使用特权

评论回复
地板
binbin0317|  楼主 | 2020-9-16 16:00 | 只看该作者
没办法啊,就一个原理图,文字什么的都不愿意多说几个。demo_suite的demo少得可怜。唉

使用特权

评论回复
5
晓伍| | 2020-10-12 10:47 | 只看该作者
我也长知识了 谢谢

使用特权

评论回复
6
zchong| | 2020-10-18 13:08 | 只看该作者
打肿打红都不解恨!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

45

帖子

3

粉丝