Hello,
I have a problem with the Custom Software Serial Library.
I use a Nano with a PZEM017 ModBus Device connected. This Device needs a Uart with 9600, 8N2.
The standard SoftwareSerial does not support 8N2 so I used the Custom Software Serial instead.
Now I need to use it in function calls. Thus I have to declare it inside the function and when I do that, then it gets instantiated a new in every function call, which eventually makes the heap and the stack mingle and do their evil thing ... the Nano crashes after 26 loops and restarts.
When I declare it in the setup, then I cannot use it in the funtion call => the compiler spits => 'PZEMSerial' was not declared in this scope
I'm at my wits end.
This is the crucial piece of code:
__ CustomSoftwareSerial* PZEMSerial; // Declare serial__
** PZEMSerial = new CustomSoftwareSerial(10, 11); // rx, tx**
** PZEMSerial->begin(9600, CSERIAL_8N2); // Baud rate: 9600, configuration: CSERIAL_8N2**
....
....
....
** PZEMSerial->end();**
I have attached the function as *.txt
- How would you declare the CustomSoftwareSerial so that it can be used globaly? In Main/loop and in all functions?
- Is there a way to use the SoftwareSerial with 8N2?
- Whatever other ideas you have.
Thanks in advance.
read function.txt (1.58 KB)