打印

谁能给我一个usart1可以正常收发的keil工程文件

[复制链接]
964|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Eric@Wei|  楼主 | 2017-12-29 10:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
谁能给我一个usart1可以正常收发的keil工程文件,谢谢~!新手,usart2可能传,但USart1怎么怎么滴也不能传~!求同情,求关怀!
沙发
Eric@Wei|  楼主 | 2017-12-29 10:58 | 只看该作者
本帖最后由 Eric@Wei 于 2017-12-29 11:00 编辑

    USART_InitPara USART_InitStructure;
    USART_DeInit( USART1 );
    USART_InitStructure.USART_BRR           = 115200;
    USART_InitStructure.USART_WL            = USART_WL_8B;
    USART_InitStructure.USART_STBits            = USART_STBITS_1;
    USART_InitStructure.USART_Parity                = USART_PARITY_RESET;
    USART_InitStructure.USART_HardwareFlowControl = USART_HARDWAREFLOWCONTROL_NONE;
    USART_InitStructure.USART_RxorTx                = USART_RXORTX_RX | USART_RXORTX_TX;

    GD_EVAL_COMInit(&USART_InitStructure);

    /* Output a message on Hyperterminal using printf function */
          printf("0x01");

void GD_EVAL_COMInit(USART_InitPara * USART_InitStruct)
{
    GPIO_InitPara GPIO_InitStructure;

    /* Enable GPIO clock */
    RCC_AHBPeriphClock_Enable(EVAL_COM1_TX_GPIO_CLK | EVAL_COM1_RX_GPIO_CLK, ENABLE);

#if defined(GD32F130_150)
    /* Enable USART clock */
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);

#elif defined(GD32F170_190)
    /* Enable USART clock */
    RCC_APB1PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);

#else
    #error "Please define GD32F130_150 or GD32F170_190"

#endif

    /* Connect PXx to USARTx_Tx */
    GPIO_PinAFConfig(EVAL_COM1_TX_GPIO_PORT, GPIO_PINSOURCE9,GPIO_AF_1);

    /* Connect PXx to USARTx_Rx */
    GPIO_PinAFConfig(EVAL_COM1_RX_GPIO_PORT, GPIO_PINSOURCE10,GPIO_AF_1);

    /* Configure USART Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin =GPIO_PIN_9 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_10MHZ;
    GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLUP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure USART Rx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin =GPIO_PIN_10;// ; EVAL_COM1_RX_PIN
    GPIO_Init(EVAL_COM1_RX_GPIO_PORT, &GPIO_InitStructure);

    /* USART configuration */
    USART_Init(USART1, USART_InitStruct);

    /* Enable USART */
    USART_Enable(USART1 , ENABLE);
}



#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */


PUTCHAR_PROTOTYPE
{
    /* Place your implementation of fputc here */
    /* e.g. write a character to the USART */
    USART_DataSend(USART1, (uint8_t) ch );

    /* Loop until transmit data register is empty */
    while (USART_GetBitState(USART1 , USART_FLAG_TBE) == RESET)
    {
    }

    return ch;
}

使用特权

评论回复
板凳
renzheshengui| | 2018-7-7 14:27 | 只看该作者
这个东西 现在官网是不是都已经有例程了啊

使用特权

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

本版积分规则

16

主题

71

帖子

0

粉丝