What is the best way to control RS485?


Yeezy

Recommended Posts

I am testing infrared temperature sensor. It is connected to SP485(converter RS485 to RS232?) which is connected to ZYNQ,FPGA.

hmCPy.png

 

write(fd,"1",1); // make gpio(enable pin) high.
req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t)); //write
write(fd,"0",1);//After write(), make gpio low to receive messages from sensor.
int response_length = modbus_receive_confirmation(ctx, rsp);

This code was not working properly. Write() is not write immediately.. or the prosess is working independently.(so there is possibility that when I input Low, write() is not finished).

I don't know reason actually. it's just my assuming.

So I added usleep();

write(fd,"1",1); // make gpio(enable pin) high.
req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t)); //write
usleep(9050); //waite until write is finished
write(fd,"0",1);//After write(), make gpio low to receive messages from sensor.
int response_length = modbus_receive_confirmation(ctx, rsp);`

this code is working sometimes..... it also not the best answer. the result is here. After 1'22, it's working.

enable Pin is connected to FPGA (ZYNQ)

It is difficult to add other circuit to control enable pin. it is more convenience to make a design on the FPGA.

f7Ebg.png

should I control this by software?(controlling gpio) or Hardware?

Let me know the best way, approach.. Thank you.

Link to comment
Share on other sites

GF does not support Zynq at the moment, nor Linux interfacing.

But my 2 cents:

1 - flush the write to the GPIO control port.

2 - If you really need control over all lines, write a Linux Kernel Driver for it. Also check documentation for that "modbus" library you are using.

Alvie

Link to comment
Share on other sites

SP485 and SP3485 are 2 different voltage chips.  the 3485 is the 3v3 model where as the 485 is the 5V0 model..

the SP3485 // SP485  don't have automatic flow control, you are most likely just missing your data.

how to fix, no idea. maybe try  (note: i have never used that chip nor modbus)

and ofc listen to @alvieboy since he is 100000 times smarter than me.

 

int response_length;
int req_length
int rww;
int fauxWDT=0;

..
.. // yadda yadda //
..


write(fd,"1",1); // make gpio(enable pin) high.

req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t)); //write

usleep(50); // or just remove entirely

write(fd,"0",1);//After write(), make gpio low to receive messages from sensor.

rww = 1;

while (rww == 1)
{
	response_length = modbus_receive_confirmation(ctx, rsp);
	if (response_length == -1)
	{
		rww = 0;
	}

	/* maybe add some sort of timeout counter here..  
		fauxWDT++;
       if (fauxWDT >= 10000) { rww = 0; } 
	*/

}

/* do something with rsp here */

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.