Hello every one.
I use libmodbus on my raspberry pi with modbus RS485 to create a server. I connected RPi pins with module RS485 (using IC MAX3485) like this:
TX(RPi) <-------->RX(485)
RX(RPi) <-------->TX(485)
GPIO1 <--------> EN485
I set en485 pin to high lvl for transmiting data to a slave on my PC, it work good, but the problem is i cant set en485 pin to low lvl for receiving confirmation from slave! The function
I tried edit src modbus-rtu.c:
if (mode == MODBUS_RTU_RS485) {
rs485conf.flags = SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND; //Set logical level for RTS pin equal 1 when sending
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND); //Set logical level for RTS pin equal 0 after sending
rs485conf.delay_rts_before_send = 0;
rs485conf.delay_rts_before_send = 0;
rs485conf.flags |= SER_RS485_USE_GPIO;
rs485conf.gpio_pin = en485; // need #define en485 18 //BCM code
if (ioctl(ctx->s, TIOCSRS485, &rs485conf) < 0) {
return -1;
}
but it won't work!
Is any one have idea to solve my problem or sample code, pls send me. Thank you very much.