Yeezy Posted May 12, 2017 Report Share Posted May 12, 2017 I am testing infrared temperature sensor. It is connected to SP485(converter RS485 to RS232?) which is connected to ZYNQ,FPGA. 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. should I control this by software?(controlling gpio) or Hardware? Let me know the best way, approach.. Thank you. Quote Link to comment Share on other sites More sharing options...
alvieboy Posted May 14, 2017 Report Share Posted May 14, 2017 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 Quote Link to comment Share on other sites More sharing options...
Felix Posted May 20, 2017 Report Share Posted May 20, 2017 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 */ Quote Link to comment Share on other sites More sharing options...
Felix Posted May 20, 2017 Report Share Posted May 20, 2017 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.