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

[复制链接]
133|1
 楼主 | 2017-12-29 10:54 | 显示全部楼层 |阅读模式
谁能给我一个usart1可以正常收发的keil工程文件,谢谢~!新手,usart2可能传,但USart1怎么怎么滴也不能传~!求同情,求关怀!
 楼主 | 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;
}

扫描二维码,随时随地手机跟帖
*滑动验证:
您需要登录后才可以回帖 登录 | 注册 手机登录

本版积分规则

快速回复

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

论坛热帖

分享 快速回复 返回顶部 返回列表