OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3464|回复: 0

我485接收-这个字符判断完成以后再通过485将数组里的数据发到串口 但是发出的数据b...

[复制链接]

1

主题

5

帖子

0

精华

新手上路

积分
26
金钱
26
注册时间
2020-5-9
在线时间
6 小时
发表于 2021-7-17 12:04:04 | 显示全部楼层 |阅读模式
#include "sys.h"                    
#include "rs485.h"         
#include "delay.h"
#include "js.h"
extern u16 shu;
extern u8 gewei;
extern u8 shiwei;
extern u8 baiwei;
extern u8 qianwei;
extern u8 shuju[7];
#ifdef EN_USART2_RX           //èç1ûê1Äüá˽óêÕ
void USART2_IRQHandler(void)
{
        char res;       
        if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //½óêÕμ½êy¾Y
        {
                                  
                res=USART_ReceiveData(USART2);         //¶á衽óêÕμ½μÄêy¾Y
                if(res == '-')
                {
                        shu--;
                }
                        RS485_Send_Data();
                }
}  
       
#endif                                                                                  
void RS485_Init()
{  
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;                               
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOD, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;        //PA2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);  

RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,ENABLE);//¸′λ′®¿ú2
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,DISABLE);//í£Ö1¸′λ

       
#ifdef EN_USART2_RX                          //èç1ûê1Äüá˽óêÕ
        USART_InitStructure.USART_BaudRate = 115200;//2¨ìØÂêéèÖÃ
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8λêy¾Y3¤¶è
        USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
        USART_InitStructure.USART_Parity = USART_Parity_No;///ÆæÅ¼D£Ñéλ
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//êÕ·¢Ä£ê½

  USART_Init(USART2, &USART_InitStructure); ; //3õê¼»ˉ′®¿ú
        USART_Cmd(USART2, ENABLE);                    //ê1Äü′®¿ú `
       
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //ê1Äü′®¿ú2ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ÏèÕ¼óÅÏè¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //′óóÅÏè¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
        NVIC_Init(&NVIC_InitStructure);
         


#endif

  RS485_TX_EN=0;                        //ĬèÏÎa½óêÕÄ£ê½

}
void RS485_Send_Data()
{
        u8 t;
        //u8 shuzhi[3]={0x01,0x02,0x03};
        RS485_TX_EN=1;        //éèÖÃÎa·¢ËíÄ£ê½
  jishu_Init();
          for(t=0;t<7;t++)               
        {                  
               
                while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);          
                USART_SendData(USART2,shuju[t]);
        }         

        while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);                          
        RS485_TX_EN=0;                                //éè&#214;&#195;&#206;a&#189;óê&#213;&#196;£ê&#189;       
}

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-24 01:36

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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