Hey everyone,
hope you're all safe and sound (as possible) during these dark times.
Brief
I'm using the ArduinoModbus library and had no problem most of the time. However, recently, I tried to communicate with different hardware and the Arduino as the Slave/Server to have its input registers read. The code, Modbus RTU Server Kitchen Sink with little modifications, receives the message right (added print function to the .cpp) but doesn't the Slave/Server reply as it should.
Due to most past of the core code being in c I can't use Serial.print() to debug it and looks like print and printf doesn't work (at least not for me).
Have anyone managed to print something in the Serial Monitor with those two functions inside a .c file? What is the best way to debug those files?
This seems to do what you want (actually the suggestion above to share a char[] looks simplier) Well perhaps not as it does not print immediately, but a char[] could be used for store debug while in the method and be printed on exit.
CcodePrint.ino
#include "Cfile.h"
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for (int i=10; i>0; i--) {
Serial.print(i); Serial.print(' ');
}
Serial.println();
dummyMethod();
}
void loop() {
// put your main code here, to run repeatedly:
}
pert:
A couple possible alternatives to Serial.print() for debugging:
If you have a CMSIS-DAP debug probe, you can do true hardware debugging. The Arduino Pro IDE has support for this.
Use an LED to signal information.
Nice! I didn't know about the Arduino Pro IDE and I'll absolutely check it. ;p
jimLee:
Share a char buffer with the c++ world?
-jim lee
I've changed some functions parameters to receive a char* so I could print them outside the C functions, however as the code goes deeper the more functions I had to change, so I decided against it...
drmpf:
This seems to do what you want (actually the suggestion above to share a char[] looks simplier) Well perhaps not as it does not print immediately, but a char[] could be used for store debug while in the method and be printed on exit.
[....]
Output is
10 9 8 7 6 5 4 3 2 1
test
Thanks, i did what you told me and it worked like a charm! Just finished debugging and found the problem. I also used the method you taught me and created some nice printing functions :)!