打印
[STM32F0]

求教STM32F070F6 串口2初始化无数据输出问题?

[复制链接]
1625|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chinamaken|  楼主 | 2016-4-22 10:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
int main()
{
        if (SysTick_Config(SystemCoreClock / 1000))
        {
        /* Capture error */
        while (1);
        }
       
        USART_Config();//´®¿Ú2¶ÔÍâÊäÈëÊä³ö
        Senddata('a');
        //USART_SendData(USART2, 0x55);
//        printf("\n\rUSART is OK! \n\r");
//        GPIO_Contrl();//¿ØÖÆÐźŶ¨Òå;
//        printf("\n\rGPIO is OK! \n\r");
//        EXTI13_Config();//PA13Ϊ´¥ÃþÆÁ´¥ÃþÖжÏ
//        printf("\n\rEXIT is OK! \n\r");
////        USBD_Init(&USB_Device_dev,
////                        &USR_desc,
////                        &USBD_HID_cb,
////                        &USR_cb);
//        printf("\n\rUSB is OK! \n\r");
//        printf("\n\rInitialization is OK! \n\r");
        while (1)
        {
                for(index_xx=65536;index_xx>0;index_xx--){;}
                Senddata('a');       
        }
}
static void USART_Config(void)
{
        /* Enable GPIO clock */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

        /* Enable USART clock */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

        /* Connect PXx to USARTx_Tx */
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_0);

        /* Connect PXx to USARTx_Rx */
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_0);

        /* Configure USART Tx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_Init(GPIOA, &GPIO_InitStructure);

        /* Configure USART Rx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - Stop Bit = 1 Stop Bit
        - Parity = No Parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
        */
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

        /* USART configuration */
        USART_Init(USART2, &USART_InitStructure);

        /* Enable USART */
        USART_Cmd(USART2, ENABLE);
}
沙发
neeringstu| | 2016-4-22 22:59 | 只看该作者
你先将rx和tx连上,看看能自发自收吗

使用特权

评论回复
板凳
chinamaken|  楼主 | 2016-4-28 08:58 | 只看该作者
自己搞定,低级错误,失误失误

使用特权

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

本版积分规则

18

主题

87

帖子

3

粉丝