如题,用原子战舰的485通信例程改的代码无法测试传感器,不知道测试485设备的时候代码上应该注意什么?
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "rs485.h"
void sendconfig_buff(void);
u8 modbusbuff[8]={0x01,0x03,0x00,0x00,0x00,0x01,0x84,0x0A};
u32 buff3[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// rs485buf
int main(void)
{
u8 key;
u8 i=0,t=0,j=0;
u8 cnt=0;
u8 len=7;
u8 rs485buf[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(9600);
LED_Init();
LCD_Init();
KEY_Init();
RS485_Init(9600);
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
LCD_ShowString(30,130,200,16,16,"KEY0:Send");
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(30,150,200,16,16,"Count:");
LCD_ShowString(30,170,200,16,16,"Send Data:");
LCD_ShowString(30,210,200,16,16,"Receive Data:");
delay_ms(200);
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
LED0=!LED0;
sendconfig_buff();
for(j=0;j<8;j++)
{
LCD_ShowxNum(20*j+50,300,(modbusbuff[j]),15,16,1);
}
delay_ms(50);
RS485_Receive_Data(rs485buf,len);
for(j=0;j<8;j++)
{
// buff3[j]=rs485buf[j]-'0';
buff3[j]=rs485buf[j];
// LCD_ShowxNum(30*j+100,100,buff3[j],8,16,1);
LCD_ShowxNum(150,20*j+100,(buff3[j]),10,16,1);
}
}
else
{}
}
}
void sendconfig_buff(void)
{
RS485_Send_Data(modbusbuff,8);
}
求助吧友,这个传感器24V供电,接线都没问题,在电脑上用串口助手调试是有正确读数返回的,但是用单片机和模块相连就不行了;之前看到吧友说 RS485_Receive_Data(u8 *buf,u8 *len)的参数中要把len去掉,直接用变量,两种方法我都试了 还是没效果。谁能帮帮忙?感激不尽!
当然要啊 ,太谢谢了! 我加你qq还是?
一周热门 更多>