Closed aquiot-inc closed 1 year ago
I think this has to do with the way different microcontrollers interpret the unsigned int
datatype.
With an AVR, unsinged int
is always a 16 bit variable.
On other processors, unsigned int
may be a 32 bit datatype.
In the library files, ModbusRTUSlave.h and ModbusRTUSlave.cpp, I use the datatypes uint16_t
, which specifies an unsigned 16 bit integer, regardless of processor, but in the example programs I used unsigned int
, because this is in line with the Arduino style.
I have no plans of specifically supporting STM32 or ARM microcontrollers at this time, but I will be giving some thought on how to better deal with processors that consider an unsigned int
to be a 32 bit variable.
A quick fix to your issue (I think) would be to change all the Unsigned int
s in the sketch to uint16_t
s.
Yes, ambiguous data types are the problem. These changes fix Coils_HardwareSerial.ino
so that it compiles. I have not tested it in hardware yet.
@@ -44,7 +44,7 @@ boolean toneActive = 0;
unsigned int toneFrequency = 2000;
// This is a function that will be passed to ModbusRTUSlave for reading coils.
-char coilRead(unsigned int address) {
+int8_t coilRead(uint16_t address) {
switch (address) {
case 0:
return digitalRead(ledPin);
@@ -57,7 +57,7 @@ char coilRead(unsigned int address) {
}
// This is a function that will be passed to ModbusRTUSlave for writing to coils.
-boolean coilWrite(unsigned int address, boolean value) {
+boolean coilWrite(uint16_t address, boolean value) {
switch (address) {
case 0:
digitalWrite(ledPin, value);
I'm always in favour of using unambiguous data types from stdint.h
.
There seems to be a compile problem with data types for some ARM based boards like RP2040 and STM32.
The example below is Arduino 2 using
ModbusRTUSlave
Arduino library V1.0.5 for example fileCoils_HardwareSerial.ino
for boardRaspberry Pi Pico
using theArduino Mbed OS RP2040 Boards
core:Similar compile problems also for STM32. Would be good to support the newer ARM based processors as AVR has supply chain issues and is old/expensive technology.