@felmue Hi, felix i got it working finally. The issue is, on platformIO the library Arduinomodbus library and ArduinoRS485 library are the arduino ones and not the m5stack ones which is why i was getting error.
A fix to this was to just replace the internal files of library to the m5stack ones from github.
Thank you for the help.