arduino-libraries / ArduinoModbus

252 stars 120 forks source link

Conflict with Sercom #13

Closed Ginodel closed 5 years ago

Ginodel commented 5 years ago

On a MKRZero i want to do modbus RTU slave communication using MKR485 with the ArduinoModbus library. Examples are working, so far so good. I needed an additional serial port to read information from a sensor and used for that Sercom3 on pins 0 and 1. This is also working fine.... but when i combine both .... then ModbusRTUServer.begin() is failing when i first define my sercom3 and open serial port (serial3.begin(9600)...). If i put first ModbusRTUServer.begin() in my code then this is working but serial3 (sercom3) nolonger.

I was looking into both libraries but can't find out what is causing this....

Your help is appreciated ...

thanks

Ginodel commented 5 years ago

I simplified a bit the code ..... this should show the problem ...

include

include

include // ArduinoModbus depends on the ArduinoRS485 library

Uart Serial3 (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void setup() { Serial.begin(9600); while (!Serial); Serial3.begin(9600); pinPeripheral(0, PIO_SERCOM); //Assign RX function to pin 0 pinPeripheral(1, PIO_SERCOM); //Assign TX function to pin 1

Serial3.setTimeout(2000);

// Start Modbus server if (ModbusRTUServer.begin(41,9600)) { Serial.println("Failed to start Modbus RTU Server!"); //while (1); } }

void loop() { // poll for Modbus RTU requests //ModbusRTUServer.poll(); delay(1000); }

void SERCOM3_Handler() { Serial3.IrqHandler(); }

Ginodel commented 5 years ago

Problem solved .....

if (ModbusRTUServer.begin(41,9600)) { has to be if (!ModbusRTUServer.begin(41,9600)) {

what one character can do .... hmmm