因此要定义接收使能,并默认接收模式);接着定义RS485_Receive_Data(u8 *buf,u8 *len)函数,从缓冲数组内接收数据,注意判断是否接收完成;然后关闭接收模式,开启发送模式,定义了RS485_Send_Data(u8 *buf,u8 len),本质是调用串口发送函数USART_SendData(USART2,buf[t]);来实现。
Send_Buf[2] = (InputAddr>>8); Send_Buf[3] = (InputAddr&0XFF); Send_Buf[4] = (OutVlaue>>8); Send_Buf[5] = (OutVlaue&0XFF); Temp_crc = CRC16_Fanction(Send_Buf,6); Send_Buf[6] = (Temp_crc&0XFF); Send_Buf[7] = (Temp_crc>>8); RS485_Send_Data(Send_Buf,8); ...
1. i have worked with RS485 to collect data from flow meters and RS485 enable sensors, usually that is need 8 byte request for send the data that is still now working fine but now i have checked the PLC data through modscan32 and 64 software's those are send 9 bytes data for receiv...
u8 RS485_RX_BUF[64]; //接收缓冲,最大64个字节.; void RS485_Send_Data(u8 *buf,u8 len); void RS485_Receive_Data(u8 *buf,u8 *len); #endif /* RS485_RS485_H_ */ rs485.c文件: #include "rs485.h" #include "Uart.h" volatile unsigned char RS485_REC_Flag = 0; //接收缓存区 ...
将串口接收中断中接收到的数据写到buf中,将数据长度写到m中,然后通过RS485_Send_Data函数将接收到的数据发回串口调试助手实现将上位机发来的数据原原本本发回到上位机上。但实验结果是在串口调试助手上发出的数据无法返回到串口调试助手,我后来直接在RS485_Init函数后面将控制端置高设置为发送模式然后在...
send_data = {1,2,3,4,5} SendEn() LIB_Uart1BlockSend(send_data) RecvEn() end --查询是否收到PC端发来的5字节数据,并验证 recv_flag,recv_data = LIB_Uart1Recv() if recv_flag == 1 and #recv_data == 5 then if recv_data[1] == 6 and recv_data[2] == 7 and recv_data[3]...
SendData[#SendData+1] = data[i] end --发送数据包 LIB_Uart0Send(SendData) LIB_DelayMs(100)--延时不能低于100ms,不然会有个别指令收不到回复 --查询Uart0是否收到0xaa应答 u0_flag,u0_tab = LIB_Uart0Recv() if u0_flag == 1 and u0_tab[1] == 0xaa then ...
1、在主函数中,扫描按键。一旦key0按下,首先将5个字节的数据存入rs485buf[]数组中,然后调用RS485_Send_Data(rs485buf,5);函数将5个字节的数据发送到串口。 2、进入RS485_Send_Data();函数中,先通过标志位将485设置为发送模式(RS485_TX_EN=1),然后循环5次,将这5个字节数据,通过库函数:USART_Send_Data...
extern u8 RS485_RX_BUF[64]; //接收数据缓冲 extern u8 RS485_RX_CNT; //接收到的数据长度 #define RS485_TX_EN PDout(7) //485模式控制:0接收;1发送 void RS485_Send_Data(u8 *buf,u8 len) { u8 t; RS485_TX_EN=1; for(t=0;t<len;t++) { while(USART_GetFlagStatus(USART2, USART...