Hi, everyone!
I’m upgrading my device (MBED based, NXP LPC1768) to use standard Modbus RTU protocol instead of custom ASCII serial protocol.
My device can be connected to a PC/PLC via RS485 or serial port (via USBSerial).
I’ve started testing Rajit Singh’s Modbus library, a port for MBED of FreeModbus library.
I’ve tested on MBED board using the Serial port, and it worked.
I’ve added to my system using the RS485 interface and it worked.
I’ve switched to USBSerial interface, and I can’t get it wokring properly.
The basic idea behind this library is to have an infinite loop in the main that calls eMBPoll(), a function that checks incoming messages and execute functions, “triggering” ISR to send answers.
When a message arrive via USB I can intercept and decode it, prepare the answer and start to putc(). USBSerial putc() calls USBCDC::send() that calls USBDevice::write(). The method does an endpointWrite(), and then waits for write completion in an infinite loop.
do {
result = endpointWriteResult(endpoint);
} while ((result == EP_PENDING) && configured());
The problem is that this loop never ends, since results is always EP_PENDING.
Does anyone know what can prevent the success of the USBDevice::write function?
Is there anyone that managed to use Modbus via USB serial? (with this Modbus library or a diferent one)