I am using an atmega328p chip and need two extra serial ports, so was thinking to use a software serial library such as the arduino software serial. So my question is: is it possible to use the Arduino softwareSerial outside of the Arduino coding environment, and if so, how would I set this up in platformio?
If not the arduino softwareserial, is there a different serial library which could provide two extra ports (they’re not used simultaneously).
I’ve programmed arduino for a few years, but now looking to program the 328 without the arduino platform.
A bit of googling turns up the project GitHub - blalor/avr-softuart: Software UART implementation for the AVR platform which supports ATMega328P chips. The implementation is just two files, softuart.c and .h. It has code to support one further serial port at PD1 and PD2 (configurable though), but not two, and uses up the TIM0_COMPA_vect interrupt, so TIM0 is used for that. So you have to slightly re-code it. If the two software UARTs are never used at the same time, you might get away with just making some constants to variables, e.g. regarding the pin and port macros, and exchange their value at the right time in the code.
Hmm the way I see it it does that to auto-include the other implementations of the Print class which do e.g. a write with a buffer. The class then does however only implement the fundamental primitive, the write-single-byte, which all other derivatives use
So that should not be the dealbreakinger, since it’s not calling into implementations of the Print::write functions – it implements them.
Just had a quick look at the files (I started programming Attiny82 years ago before switching to the Arduino framework. In the End, I converted to follow the Arduino road, saving myself from re-writing libraries to my special application all the time…). Max’ choice looks like it would be working pretty much out of the box for you. All you need to do, is to wrap the contents in two classes (one “worker class” which does the bit-banging and one “config” class where you’ll finally construct the objects with…) But be reminded that this will be some evenings worth of work; if you want to go down that path, off you go