Yeezy

What is the best way to control RS485?

4 posts in this topic

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.

Share this post


Link to post
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

Share this post


Link to post
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 */

 

 

Share this post


Link to post
Share on other sites

actually, if its a sensor, shouldnt you just be able to set the chip to receive mode and not even bother with writing to it other than once (or just pull the pin LOW) then just listen to the receive in a loop?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now