tjhbwjk 发表于 2015-5-14 15:35:01

我感觉是没有发出数据来,我的发送数据有问题吗?

Winddddd 发表于 2015-5-14 15:53:45

tjhbwjk 发表于 2015-5-14 14:59
还是不行,

可以看看我前段时间弄串口时写的笔记
http://blog.sina.com.cn/s/blog_d2edb6010102vewi.html

为什么是EEFOCUS小白 发表于 2015-5-14 16:47:13

不懂帮顶

lkl0305 发表于 2015-5-14 16:54:45

tjhbwjk 发表于 2015-5-14 14:58
还是不行,你有代码?能给参考一下吗?谢谢了

不知道你用的是哪个库,里面官网应该提供有实例,你可以参考下

tjhbwjk 发表于 2015-5-15 15:25:17

lkl0305 发表于 2015-5-14 16:54
不知道你用的是哪个库,里面官网应该提供有实例,你可以参考下

我改好了帅哥,谢谢了

tjhbwjk 发表于 2015-5-15 15:26:43

结贴

#include "stm32f30x.h"
#define uint unsigned int

        uint i,j,k;

void Delay(i)
                {
                for(j=0;j<=i;j++)
                        ;
                }


int main()
{
   
          GPIO_InitTypeDef GPIO_InitStructure;
          USART_InitTypeDef USART_InitStructure;
                RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//enable clk
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
                GPIO_DeInit(GPIOA);
          USART_DeInit(USART1);
       
          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
       
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);
       
          GPIO_InitStructure.GPIO_Pin= GPIO_Pin_9;//TX
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
       
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
       
          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;//LED
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
               
                GPIO_Init(GPIOA, &GPIO_InitStructure);
       
                USART_InitStructure.USART_BaudRate = 115200;//UART
                USART_InitStructure.USART_WordLength = USART_WordLength_8b;
                USART_InitStructure.USART_StopBits = USART_StopBits_1;
                USART_InitStructure.USART_Parity = USART_Parity_No ;
                USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
                USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
          
                USART_Init(USART1, &USART_InitStructure);
               
                USART_Cmd(USART1, ENABLE);//EN UART
                USART_ClearFlag(USART1,USART_FLAG_TC);
                       
               
                while(1)
                {
                USART_SendData(USART1, 0X55);
                while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==1)
                {
               
                GPIO_SetBits(GPIOA, GPIO_Pin_5);
                Delay(500);
                       
                GPIO_ResetBits(GPIOA, GPIO_Pin_5);
                        Delay(500);
                }
               
        }
       
}

沐紫 发表于 2015-5-15 15:49:29

恭喜楼主!

tjhbwjk 发表于 2015-5-15 16:29:24

沐紫 发表于 2015-5-15 15:49
恭喜楼主!

同喜 同喜

Lovely_STM32 发表于 2015-5-15 17:35:26

1)USART配置;
2)对应的IO配置;
3)USART异常清除;
4)USART打开运行;

mark0668 发表于 2015-5-16 00:20:19

不会用库爱莫能肋
页: 1 [2]
查看完整版本: 求助:帮忙看下我的串口程序