Cygnet issue with ModbusMaster

I’m running into an issue where our Cygnet is freezing when using ModbusMaster. The same code works well when testing in on the Swan (switched the platformIO board/env).

It looks like there’s a line of code in ModbusMasterTransaction() that the code is freezing on, “ _serial->flush();

Any ideas what can be going wrong or how to correct it?

int writeModbusRegister(uint16_t regAddress, uint16_t regValue, int regType)

{

uint8_t result;

uint16_t data;

int numRead = 1;

Serial.print(“Writing Modbus Register at address: 0x”);

Serial.print(regAddress, HEX);

Serial.print(" ");

Serial.print(regValue);

if (regType == 6){

result = node.writeSingleRegister(regAddress, regValue);

}

else {

result = node.writeSingleCoil(regAddress, regValue);

}

if (result == node.ku8MBSuccess){

Serial.print("    Response Bytes: ");

for (uint8_t i = 0; i < numRead; i++) {

  Serial.print(node.getResponseBuffer(i), HEX);

  Serial.print(" ");

}

Serial.println();



//Serial.print("Response Dec: ");

for (uint8_t i = 0; i < numRead; i++) {

  //Serial.print(node.getResponseBuffer(i), DEC);

  //Serial.print(" ");

}

//Serial.println();



data = node.getResponseBuffer(0);



//Serial.print("Input Register Value: ");

}

else {

Serial.print("     Error writing input register " + String(regAddress) +  ". Error code: ");

Serial.println(result, HEX);

}

delay(0);

return result;

}

The process is freezing within writeSingleRegister(), then within ModbusMasterTransaction(), on

_serial->flush();

How are you connecting to ModBus?

Can you share an image of your setup?

This is the circuit schematic of the MCU and RS485 converter. I have this all on a PCB, and the Swan board is attached to female header pins. I’m just swapping the Swan with the Cygnet, using the same code, but it’s freezing in that one section.

Hello @rfadell3 ,

Thanks for sharing the schematic, that definitely helped.

Unfortunately, there is no UART available on pins A4/A5 on the Cygnet. The Swan and Cygnet are only guaranteed pin-for-pin compatibility based on the Adafruit Feather specification.

The Swan is a much more powerful MCU with more peripherals available than the Cygnet.

If you’re willing, we would love to better understand why you chose the Cygnet over the Swan, so we can apply it as input for making future improvements to the Swan.

~Zak

Hi Zak,

Ok, so to clarify the A4/A5 pins on the Swan are UART compatible, but the same pins are not on the Cygnet? Are there any pins on the Cygnet (besides Rx/Tx) that are UART compatible? We are using the Rx/Tx pins for Notecard communication.

We primarily switched because we don’t need some of the expanded features of the Swan (2MB flash, 640KKB SRAM, etc.), but I guess we need the UART capabilities.