[STM32L0]

一直处于高电平3.3v

[复制链接]
962|24
手机看帖
扫描二维码
随时随地手机跟帖
ousj|  楼主 | 2019-3-15 12:27 | 显示全部楼层 |阅读模式
STM32F051串口问题求助
照着手册配置de
zhaoxqi| | 2019-3-15 12:30 | 显示全部楼层
没有数据发送?是不是哪里配置配错了

使用特权

评论回复
zhanghqi| | 2019-3-15 12:33 | 显示全部楼层
楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因

使用特权

评论回复
ousj|  楼主 | 2019-3-15 12:36 | 显示全部楼层

void USART_Configuration(void)//串口初始化函数
  {  

        GPIO_InitTypeDef  GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        USART_ClockInitTypeDef USART_ClockInitStructure;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);         
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);


        USART_ClockInitStructure.USART_Clock =  USART_Clock_Enable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_ClockInit(USART1, &USART_ClockInitStructure);
        
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);        

                              
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;                 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);     
        
        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_Init(USART1, &USART_InitStructure); //配置入结构体
        USART_ClearFlag(USART1, USART_IT_RXNE);                         //清中断,以免一启用中断后立即产生中断
        USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);                //使能USART1中断源
        USART_ITConfig(USART1, USART_IT_TC, ENABLE);        

        USART_Cmd(USART1, ENABLE);//使能串口1

                }                        

使用特权

评论回复
jlyuan| | 2019-3-15 12:39 | 显示全部楼层
同为新手,参考例子配置的串口,测试可用。

void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable GPIOA, GPIOB and GPIOF Peripheral clock */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOF, ENABLE);

  /* USART1(PB6->TX, PB7->RX) Pins Configuration */
  /* Connect pin to Peripheral */
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0);
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0);   
  /* Configure pins as AF pushpull */
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
        GPIO_Init(GPIOB, &GPIO_InitStructure);  
}

void USART_Configuration(void)                //´®¿Ú³õʼ»¯º¯Êý
{  
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable USART1 Peripheral clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
  /* USART1(PB6->TX, PB7->RX) Configuration(9600, 8, 1, N) */
        USART_InitStructure.USART_BaudRate = 9600;                //ÉèÖô®¿Ú²¨ÌØÂÊ
        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_Init(USART1, &USART_InitStructure);                //ÅäÖÃÈë½á¹¹Ìå
  /* Enable USART1 Receive and Transmit interrupts */
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  /* Enable the USART1 interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

/*----------------------------------------------------------------------------*/
        USART_Cmd(USART1, ENABLE);                                                //ʹÄÜ´®¿Ú1
}

使用特权

评论回复
gongche| | 2019-3-15 12:41 | 显示全部楼层

Serial(PinName tx, PinName rx, const char *name=NULL);
Serial pc(USBTX,USBRX);
那么上面第二个的TX、RX 是在哪儿指定?

使用特权

评论回复
kangzj| | 2019-3-15 12:44 | 显示全部楼层
检查硬件上是否有问题(通信电平是否匹配)

使用特权

评论回复
xxmmi| | 2019-3-15 12:48 | 显示全部楼层
发送函数是否有问题

使用特权

评论回复
gongche| | 2019-3-15 12:50 | 显示全部楼层

上位机配置是否与函数中的配置一致

使用特权

评论回复
happy_10| | 2019-3-15 12:54 | 显示全部楼层

先查查硬件上是否有问题,程序上要注意时序

使用特权

评论回复
tian111| | 2019-3-15 12:57 | 显示全部楼层
UART串口有TTL电平的串口和RS232电平,TTL电平是高电平为3.3V,低电平为0

使用特权

评论回复
chenho| | 2019-3-15 13:00 | 显示全部楼层
这个系列官方提供的有例程没,就是去官网看看有没有什么cube开发包。

使用特权

评论回复
heweibig| | 2019-3-15 13:03 | 显示全部楼层
波特率是否设置的一致

使用特权

评论回复
hu9jj| | 2019-3-15 13:03 | 显示全部楼层
用STM32CubeMX配置一下试试看。

使用特权

评论回复
lizye| | 2019-3-15 13:07 | 显示全部楼层
检查一下时序是否正确

使用特权

评论回复
liliang9554| | 2019-3-15 13:10 | 显示全部楼层

仔细检查一下初始化函数吧,可能是初始化没配置号

使用特权

评论回复
ousj|  楼主 | 2019-3-15 13:14 | 显示全部楼层
lz的151C8T6什么价格什么数量,谢谢!

使用特权

评论回复
ousj|  楼主 | 2019-3-15 13:17 | 显示全部楼层

虽然不是软件的问题 还是谢谢了

使用特权

评论回复
wyjie| | 2019-3-15 13:21 | 显示全部楼层
您的串口波特率设置为何是115200呢?

使用特权

评论回复
ousj|  楼主 | 2019-3-15 13:25 | 显示全部楼层
结贴了,多谢大家讨论这么多哈,呵呵

使用特权

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

本版积分规则

712

主题

7557

帖子

1

粉丝