之前谢了一个串口程序,能够成功实现数据的发送和接收,后来想用max485来实现与电脑串口助手的通信,串口配置没有问题,但是一直不能实现485通信,下边是485引脚初始化和上位机发送函数的程序,麻烦原子大哥给解答下问题,谢谢
#define USART_RT_pinclock RCC_AHBPeriph_GPIOA //′®¿úòy½Åê±Öó
#define USARTclock1 RCC_APB2Periph_USART1 //′®¿úê±Öó
#define USART_RT_pinport GPIOA //½óêÕòy½Å¶Ë¿ú
#define USART1_T_pin GPIO_Pin_9 //·¢Ëíòy½Å
#define USART1_R_pin GPIO_Pin_10 //½óêÕòy½Å
#define USART_Enablepinlock RCC_APB2Periph_GPIOE //485ê1Äüòy½Åê±Öó
#define USART_Enablepinport GPIOE //485ê1Äüòy½Å¶Ë¿ú
#define RS485_Enablepin1 GPIO_Pin_14 //éÏλ»ú485ê1Äüòy½Å
#define RS485_Sendenable1 GPIO_SetBits(USART_Enablepinport,RS485_Enablepin1) //485·¢Ëíê1Äü
#define RS485_Receiveenable1 GPIO_ResetBits(USART_Enablepinport,RS485_Enablepin1) //485½óêÕê1Äü
void RS485Enable_GPIO_Configuration(void) //485使能引脚
{
GPIO_InitTypeDef GPIO_InitStructure;
/* ê1ÄüGPIOEê±Öó */
RCC_AHBPeriphClockCmd(USART_Enablepinlock, ENABLE);
GPIO_InitStructure.GPIO_Pin = RS485_Enablepin1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(USART_Enablepinport, &GPIO_InitStructure); //òy½Å3õê¼»ˉ
}
void USART1_IRQHandler(void) //串口接收中断
{
if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE )!=RESET)
{
RECEIVE_Buff[RECEIVE_Size]=USART_ReceiveData(USART1);
RECEIVE_Size++;
receive_flog=1;
if(RECEIVE_Size>10)
{
RECEIVE_Size=0;//ÅD¶Ïêy¾YêÇ·ñòç3ö
}
RS485_Receiveenable1;
}
}
void host_computer_send_PAC(void) //上位机发送函数
{
unsigned char i;
if(receive_flog==1)
{
RS485_Sendenable1;
if((RECEIVE_Buff[0]==0x01)&&(RECEIVE_Buff[1]==0x02)&&(RECEIVE_Buff[2]==0x03)) //ÅD¶Ï½óêÕÃüáîêÇ·ñÕyè·
{
for(i=0;i<10;i++)
{
SEND_Buff[i]=Send_data_Group[i];
}
SEND_Data_frame(SEND_Buff,10); //·¢Ëíêy¾Y
RS485_Receiveenable1;
receive_flog=0;
RECEIVE_Size=0;
}
}
}
谢谢原子大哥,麻烦解决下,初学者
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>