打印
[STM32F1]

STM32串口不断发送数据0,发送管脚是低电平吗

[复制链接]
5677|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
电子过客|  楼主 | 2014-9-23 13:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
是这样的我的stm32能接收到数据,但是好像发送不出数据
我用示波器观察始终是低电平,
我硬件仿真的时候串口发送数据0,不是发送管脚的电压时低电平啊
沙发
weihe123| | 2014-9-23 16:49 | 只看该作者
发送的代码和配置发上来看看啊

使用特权

评论回复
板凳
wyde518| | 2014-9-23 17:25 | 只看该作者
即使你一直发送数据0,每个字节也有起始位,停止位

使用特权

评论回复
地板
电子过客|  楼主 | 2014-9-23 17:37 | 只看该作者
weihe123 发表于 2014-9-23 16:49
发送的代码和配置发上来看看啊

找了一天的原因没找到,现在的情况我用示波器测量接收有信号,而发送电平始终是搞电平好像没发送出去
用到的2个串口,串口3负责和外界通讯,串口1用于监测数据接收或发送的数据,监测到的发送接收的数据正常
请教大家指点那里有问题
//主程序
#define  RXBUFFERSIZE  25               //接收数组的个数 也是发送数组的个数
uint8_t  TxBuffer[RXBUFFERSIZE];      //·发送数组
int main(void)
{
          USART3_Config();
          USART1_Config();
          NVIC_Configuration();
          NVIC_Configuration1();        
        while(1)
         {
         UART3_Send_TxBuffer(TxBuffer,RXBUFFERSIZE );        
          }
         
}
                                                                                                  
//串口3配置
void USART3_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        
        /* config USART3 clock */
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE);
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO , ENABLE);
               
         
        /* USART3 GPIO config */
        /* Configure USART3 Tx (PB.10) as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);   
        /* Configure USART3 Rx (PB.11) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        
        /* USART3 mode config */
        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(USART3, &USART_InitStructure);
        USART_ClearFlag(USART3,USART_FLAG_TC);
        
        /*使能串口3中断 */
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART3, ENABLE);
}
//串口3的优先级               
void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure the NVIC Preemption Priority Bits */  
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        
        /* Enable the USARTy Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;         
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}
//串口1配置
void USART1_Config(void)
{
                GPIO_InitTypeDef GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
               
                /* config USART1 clock */
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
               
                /* USART1 GPIO config */
                /* Configure USART1 Tx (PA.09) as alternate function push-pull */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
        
                /* Configure USART1 Rx (PA.10) as input floating */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
                        
                /* USART1 mode config */
                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);
                USART_Cmd(USART1, ENABLE);
}
//串口1的优先级        
void NVIC_Configuration1(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure the NVIC Preemption Priority Bits */  
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        
        /* Enable the USARTy Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;         
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}
//配置发送函数
void UART3_Send_TxBuffer(uint8_t TxBuffer[],uint8_t len )
{
     uint8_t  i=0;
         
             for(i=0;i< RXBUFFERSIZE-1;i++)
                    {
        USART_SendData(USART3,TxBuffer);
        while( USART_GetFlagStatus(USART3,USART_FLAG_TC)!= SET);  
                          i++;  //加1
                }
      

}
示波器检测TX发送是没有信号,时钟高电平,而且如果通讯成功接收的信号也会发生   

使用特权

评论回复
5
mmuuss586| | 2014-9-23 18:59 | 只看该作者
不管发送还是接收,都是高电平;

使用特权

评论回复
6
mmuuss586| | 2014-9-23 19:01 | 只看该作者

说的是发送完以后;
你看串口的标准,有起始位和停止位;

如果一直是0,发送的是0的数据,那从机就无法判断了;

使用特权

评论回复
7
mmuuss586| | 2014-9-23 19:10 | 只看该作者
串口3,发送和接收都不行吗?
看了你的代码没啥问题,确认下,你现在用的型号有没有串口3;

使用特权

评论回复
8
电子过客|  楼主 | 2014-9-23 20:09 | 只看该作者
mmuuss586 发表于 2014-9-23 19:10
串口3,发送和接收都不行吗?
看了你的代码没啥问题,确认下,你现在用的型号有没有串口3; ...

串口3能接收到数据,发送用示波器观察tx始终是高电平
我用的是野火开发板STM32F103ZET6

使用特权

评论回复
9
mmuuss586| | 2014-9-24 08:39 | 只看该作者
电子过客 发表于 2014-9-23 20:09
串口3能接收到数据,发送用示波器观察tx始终是高电平
我用的是野火开发板STM32F103ZET6 ...

:)
哦,实在不行就程序打包上传吧,周5前有空帮你看看;
今天有事要出去了,没时间看;

使用特权

评论回复
10
电子过客|  楼主 | 2014-9-24 08:54 | 只看该作者
mmuuss586 发表于 2014-9-24 08:39
哦,实在不行就程序打包上传吧,周5前有空帮你看看;
今天有事要出去了,没时间看; ...

好的

gongcheng.rar

3.03 MB

使用特权

评论回复
11
电子过客|  楼主 | 2014-9-24 11:23 | 只看该作者
mmuuss586 发表于 2014-9-24 08:39
哦,实在不行就程序打包上传吧,周5前有空帮你看看;
今天有事要出去了,没时间看; ...

找到错误了,串口3的tx设置成端口A的了,感谢

使用特权

评论回复
12
bobde163| | 2014-9-24 13:22 | 只看该作者
本帖最后由 bobde163 于 2014-9-24 13:23 编辑

真是个细活儿,楼主说找到问题所在,可喜可贺:D

使用特权

评论回复
13
mryw| | 2014-9-24 14:27 | 只看该作者
这种错误真不好找

使用特权

评论回复
14
mmuuss586| | 2014-9-25 08:29 | 只看该作者
电子过客 发表于 2014-9-24 11:23
找到错误了,串口3的tx设置成端口A的了,感谢

:loveliness:
解决了就好,谢谢分享;
这说明程序一般不会有什么问题,就是一些细节设置错误;

使用特权

评论回复
15
wqp1111| | 2017-8-12 12:27 | 只看该作者
我也遇到了这个问题,请高手列出解决问题的细节

使用特权

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

本版积分规则

54

主题

205

帖子

2

粉丝