Softwareserial Library Download

Mon Apr 27, 2015 1:50 pm
With 3 hardware serial ports on the Maple, it is unlikely that SoftwareSerial would be needed until one realizes that some Arduino libraries (Adafruit’s GPS, for example) inherit from SoftwareSerial. If you are just out for a day’s playing, modifying the GPS library may not be something you really wish to do.

Library to easily make HTTP GET, POST and PUT requests to a web server. HueDino: Philips Hue library for Arduino. HV518: Arduino library to control Microchip HV518: HX711: Arduino library for HX711 loadcell amplifier: HX711 Arduino Library: Library to interface the Avia Semiconductor HX711 ADC. HX711ADC: Library for the HX711 24-bit ADC for. ESP8266 12E NodeMCU & SoftwareSerial. To verify the operation of the softwareserial library.

Teensy3.1 had already faced this delima here: https://forum.pjrc.com/threads/17461-So … 3-it-seems

I took Paul’s changes and adapted it to the Maple STM32. This was a quick hack, but I can run the Adafruit GPS code on the Maple Mini without issues from SoftwareSerial. I have attached the .h and .cpp files that compile; additional modifications may be required for other 3rd party libraries.

The final bench project is here: http://www.hackster.io/rayburne/color-b … time-clock

Ray

Mon Apr 27, 2015 2:41 pm
Great job, Ray!
I’m currently found a mess on (arduino) sketches or libs including this “SW serial” and it was annoying to eliminate those lines from every sketch!
thank you!
Fri May 01, 2015 1:35 am
Neat stuff …

One question. I noticed you are using . instead of ./ for your #includes ..

... much deleted
-I/mnt/vbox/shared/Arduino_STM32_Sketch/hardware/Arduino_STM32/STM32F1/libraries/SPI/src -I/mnt/vbox/shared/Arduino_STM32_Sketch/hardware/Arduino_STM32/STM32F1/libraries/Wire /tmp/build2989123648752632366.tmp/Adafruit_GPS.cpp -o /tmp/build2989123648752632366.tmp/Adafruit_GPS.cpp.o
/tmp/build2989123648752632366.tmp/Adafruit_GPS.cpp:6:28: fatal error: .Adafruit_GPS.h: No such file or directory
#include '.Adafruit_GPS.h'
^
compilation terminated.
Error compiling.

Fri May 01, 2015 9:32 am
I’ve spotted that problem a few times in the past, it usually simple to fix. It would be better however if the Linux version of the Arduino IDE handled this for you. Might be worth mentioning it on the Arduino IDE dev or bug pages.
Sun May 10, 2015 5:21 pm
On the Arduino forum I did some investigations to replace the hard coded lookup tables with formulas.
Could also be useful for STM32 as you can do any baud rate then

See discussion – http://forum.arduino.cc/index.php?topic=138497.0 –

Mon May 11, 2015 12:57 am
I’m not sure how feasible this would be, but why not create a SoftwareSerial class that just calls the internal Hardware serial

I don’t see any point in doing true software serial with the number of hardware ports on the board, apart from you can’t specify the pins you want to use.

At least stuff would compile.

Ray, so you have an example of a class that inherits from SoftwareSerial that we could look at ?

Mon May 11, 2015 2:00 am
RogerClark wrote:I’m not sure how feasible this would be, but why not create a SoftwareSerial class that just calls the internal Hardware serial

I don’t see any point in doing true software serial with the number of hardware ports on the board, apart from you can’t specify the pins you want to use.

At least stuff would compile.

Ray, so you have an example of a class that inherits from SoftwareSerial that we could look at ?

Mon May 11, 2015 9:25 am
Ray,

It looks like you are just passing a pointer to the Serial class, (actually a pointer to an instance of the HardwareSerial class), rather than using a library that inherits from Software Serial

What we have at the moment works fine for this, doesn’t it ?

Mon May 11, 2015 2:48 pm
RogerClark wrote:Ray,
It looks like you are just passing a pointer to the Serial class, (actually a pointer to an instance of the HardwareSerial class), rather than using a library that inherits from Software Serial

What we have at the moment works fine for this, doesn’t it ?

Mon May 11, 2015 10:14 pm
Ray

That sounds like a good solution

I like the way it switches port based on pin selection.

Though you would need to know that’s what it’s doing, but at least it returns null if you specify a pin it can’t use

Mon Sep 21, 2015 10:48 pm
One of the reasons I’m using STM32 is more hardware serial but I’m currently working on a project I originally wrote for ATMEGA328 which uses 4 serial outputs, 2 inputs, plus the hardware serial port. So arduino newsoftserial worked perfectly since each input and output was only used one at a time (except the hardware port).

Anyhow, before I dive in, has anyone ported a software serial to STM32 yet? The simple modification mentioned in this thread obviously won’t work for my application since I need the equivalent of 5 independent serial ports to get all the outputs I need.

Thanks!

Wed Sep 23, 2015 6:14 am
I dont recall it being ported. I think people just wrote wrappers and use Hardware serial, rather than truely having software serial
Wed Sep 23, 2015 7:01 am
RogerClark wrote:I dont recall it being ported. I think people just wrote wrappers and use Hardware serial, rather than truely having software serial
Wed Sep 23, 2015 8:04 am
Thanks Ron

Software serial could be handy, especially if it will operate at low speeds e.g. 1200 baud, as I recall someone else having issues on low speeds because it was not possible to set the serial clock dividers to a value that would give really low baud rates

Re: Folder organisation

Its got bloated over time.

I think I could ditch the F3 stuff, no one is using it at all.

I did think of having everything core as a separate sub module on GitHub, but I’ve realised that GitHub doesnt automatically put submodules in the zip file

So I now think that it would be better to use the GitHub “Releases” system to script up individual downloads eg. for the F1 and for the GD32 etc separately, and probably do a Boards Manager package

When I have time…

Thu Sep 24, 2015 2:51 pm
Gee,

I thought I did… for the Adafruit GPS lib stuff…
I need to check.

Ray

Yes,
Originally posted here:
http://www.stm32duino.com/viewtopic.php?t=6

The lesson to learn here is that this forum is now large enough that a Google search by site is highly recommended before asking a question… even those of us here since the dark ages cannot remember everything. If you do notknow how to search Google by site, just ask Google.

It is downloadable from here: https://www.hackster.io/rayburne/color- … time-clock

the STM32 Maple Mini board and microcontroller. The current directory name is GPS_Time_Baro

Untitled file
/*Please review License.h tab for use/rights information regarding included libraries
GPS_Time_Baro based on original sketch by M. Ray Burnette 3/02/2014
Arduino 1.6.1 - Maple Mini Port STM32F103 by Ray Burnette 3/09/2015 PUBLIC DOMAIN by Author
Sketch uses 46,360 bytes (42%) of program storage space. Maximum is 108,000 bytes.
Global variables use 5,752 bytes of dynamic memory.
*/

#include <SPI.h> // DocumentsArduinohardwareSTM32STM32F1librariesSPI
#include <Wire.h> // I2C DocumentsArduinohardwareSTM32STM32F1librariesWire (legacy)
#include <Streaming.h> // DocumentsArduinolibrariesStreaming (legacy)

#include '.BMP085.h' // #include 'I2Cdev.h' is pulled in also
#include '.Adafruit_GPS.h'
#include '.Adafruit_GFX.h'
#include '.Adafruit_ILI9341.h'
#include '.SoftwareSerial.h' // faux version only for STM32 Maple
#include '.Utilities.h'

Wed Oct 07, 2015 4:32 am
mrburnette wrote:Gee,

I thought I did… for the Adafruit GPS lib stuff…
I need to check.

Ray

Yes,
Originally posted here:
http://www.stm32duino.com/viewtopic.php?t=6

The lesson to learn here is that this forum is now large enough that a Google search by site is highly recommended before asking a question… even those of us here since the dark ages cannot remember everything. If you do notknow how to search Google by site, just ask Google.

Mon Nov 07, 2016 8:16 pm
I would like to refresh this topic. Someone has got fully working/ported SoftwareSerial library? I’ve spotted this : https://github.com/wingspinner/SoftSerialIntAP but didn’t tried that one yet. I have only few pins left on my maple mini and I need to get the software serial working.
Mon Nov 07, 2016 9:13 pm
Very interesting.

I have never seen that before. Its a shame that people write libraries like this and publish them, but dont tell anyone.

Tue Nov 08, 2016 7:55 pm
Tue Nov 08, 2016 8:52 pm
ok.

there are a lot of side projects, and I dont seem to be able to remember them all

Tue Nov 08, 2016 8:57 pm
I was able to get this running with this one: https://github.com/wingspinner/SoftwareSerialSTM32
Fri Dec 02, 2016 12:35 pm
Another problems :/

There is some kind of problem with this library. It seems that it relay on the cpu cycles or whatever. Sometimes it is working and sometimes not. Sometimes it is enough to add 1 line to the code in main loop and sometimes a delay need to be added. For example this code is working:

#include <SoftSerialSTM32.h>
#include <string.h>
#include <SPI.h>

#define SIM800_TX_PIN PC14
#define SIM800_RX_PIN PC15
SoftSerialSTM32 mySerial(SIM800_RX_PIN, SIM800_TX_PIN);

#define RFID_TX_PIN PA4
#define RFID_RX_PIN PA5
SoftSerialSTM32 mySerialRFID(RFID_RX_PIN, RFID_TX_PIN);

int x = 100;

void setup() {

Serial.begin(115200);
mySerial.begin(9600);
//mySerialRFID.begin(9600);

}

void loop() {
delay(x);

String strsim = ';

if (mySerial.available () > 0) {

strsim = mySerial.readStringUntil('n');

Serial.print('SIM800L: ');
for (int xi=0; xi<strsim.length(); xi++) {
Serial.print(char(strsim[xi]));
}
Serial.print('n');

}

String strser = ';

while (Serial.available () > 0) {
strser += char(Serial.read ());
}
if (strser != '){
if (strser.startsWith('test')){ //check hw serial response
Serial.println('serial ok');
// } else if (strser.startsWith('D')){ //change delay
// strser.replace('n',');
// strser.replace('r',');
// strser.replace('D',');
// int outint = strser.toInt();
// x = outint;
// Serial.println('New delay: '+String(outint));
// mySerial.print('AT'); //send command after delay change and wait for answer
} else {
mySerial.print(strser); //send command
}
}

}

Fri Dec 09, 2016 3:04 pm
Sat Dec 10, 2016 12:10 am
Does SoftwareSerial rely on timers and/or interrupts for the accuracy of its bps, if so, then you may be attempting to use the same timer/interrupt twice. Just a thought, and since its nine minutes past midnight here, probably not one of my better thoughts…
Sat Dec 10, 2016 12:19 am
Just as a matter of interest…

Why do you need to use software serial. There are plenty of hardware serial ports available.

Sat Dec 10, 2016 8:10 am

Download Softwareserial Library For Arduino

RogerClark wrote:Why do you need to use software serial. There are plenty of hardware serial ports available.
Sat Dec 10, 2016 9:25 am
I have plenty of sensors and devices to communicate with. When I use TFT ILI9341 with touch screen and SD, nrf24l01+, SIM800L, ESP8266, BMP085, Humidity sensor, energy monitor, 433 RF, RFID, etc etc … then using only one maple is not enough. Second thing is that I’m trying to use hardware interfaces to get highest available speed because longer sketch code means slower speed of maple and maple is not able to receive everything from devices like UART at high speed. But sometimes it is impossible to use only hardware as in my case. That is why I’m trying to get the software serial working and also I2C and other stuff. As in this thread http://www.stm32duino.com/viewtopic.php?f=13&t=864 I’m using the first one delay driven software serial because interrupt driven was not working not only for me.
Sat Dec 10, 2016 2:24 pm
konczakp wrote:I have plenty of sensors and devices to communicate with. When I use TFT ILI9341 with touch screen and SD, nrf24l01+, SIM800L, ESP8266, BMP085, Humidity sensor, energy monitor, 433 RF, RFID, etc etc … then using only one maple is not enough.
Sat Dec 10, 2016 7:04 pm
I was using multiprocessors platform with Atmega128P and I don’t want to do that again. I’m porting all my code from that multiprocessors platform to maple because making changes was an horror for me. Changing one thing was bringing other changes on other processors etc. Maybe I had badly designed platform … i don’t know. Maybe I could go up with the architecture to get more I/O pins but unfortunately at the time I’ve started to port my project I didn’t have that knowledge. So now I have to stick what I have chosen. So now I have a problem with this software serial so If anyone could help I will appreciate that

BTW : Now I’m also using multiprocessors with I2C communication (trying to use as it can be seen in other thread) but this time in different way

Sat Dec 10, 2016 7:28 pm
If you want to use that code, you might be able to replace the tunedDelay() function with something that uses the approach I posted about here:

Although I’m sure using a timer would be a better approach if you really want more than 3 uarts. How many uarts do you actually need?

-rick

Sat Dec 10, 2016 7:35 pm
@konczakp did you try this one?

https://github.com/wingspinner/SoftSerialIntAP
or
https://github.com/wingspinner/SoftSerialIntCC/

Sat Dec 10, 2016 9:30 pm
Yes I did. And none of them were working for me. And not only for me according to this thread: http://www.stm32duino.com/viewtopic.php … 4&start=10
Sat Dec 10, 2016 9:32 pm
So for grins I tried changing out the tunedDelay() with one that uses the dwt_timer:
... and someplace else I defined cycle_timer as dwt_timer and initialized it

inline void SoftSerialSTM32::tunedDelay(uint32_t delay) {
cycle_timer.delay_cycles(delay);
}

Sat Dec 10, 2016 10:11 pm
So @konczakp , how many UARTS do you actually need?

I could imagine the solution above using the dwt_timer maybe working. You could use software serial for devices that are output only. Devices that use a command response protocol where you send data and then wait for a response might also be OK. If you limit the hardware UARTs to those peripherals that send you unsolicited data, like say a user typing data in a terminal, it might all work.

-rick

Sat Dec 10, 2016 11:16 pm
konczakp wrote:I was using multiprocessors platform with Atmega128P and I don’t want to do that again. I’m porting all my code from that multiprocessors platform to maple because making changes was an horror for me. Changing one thing was bringing other changes on other processors etc. Maybe I had badly designed platform … i don’t know. Maybe I could go up with the architecture to get more I/O pins but unfortunately at the time I’ve started to port my project I didn’t have that knowledge. So now I have to stick what I have chosen. So now I have a problem with this software serial so If anyone could help I will appreciate that

BTW : Now I’m also using multiprocessors with I2C communication (trying to use as it can be seen in other thread) but this time in different way

Sun Dec 11, 2016 6:00 pm
konczakp wrote:Yes I did. And none of them were working for me. And not only for me according to this thread: http://www.stm32duino.com/viewtopic.php … 4&start=10
Mon Dec 12, 2016 1:44 pm
I don’t know how You are doing this I cannot get this working. Here is my test code :

#include <SoftSerialIntCC.h>
//#include <SoftSerialSTM32.h>

#define TX_PIN PC14
#define RX_PIN PC15

SoftSerialInt mySerial(RX_PIN, TX_PIN, 4);
//SoftSerialSTM32 mySerial(RX_PIN, TX_PIN);

unsigned long previousMillis = 0;

const long interval = 2000;

void setup() {
Serial.begin(115200);
mySerial.begin(9600);
}

void loop() {

unsigned long currentMillis = millis();

if (mySerial.available() > 0){
Serial.println(mySerial.readStringUntil('n'));
}

if (currentMillis - previousMillis >= interval) {

previousMillis = currentMillis;

mySerial.println('AT');
Serial.println('Sent');

}
}

Mon Dec 12, 2016 2:01 pm
konczakp wrote:<…>
If I use softserialSTM it is working while if I change to softserialCC it is not. I’ve tried all 4 timers. Where is the problem? Does it mean that I can use only those pins which has a timer attached to them and PWM option? Then It should work with UART 1 which I’ve tried and I also cannot get this working.
<…>?
Mon Dec 12, 2016 3:17 pm
@mrburnette Since a few posts You are saying how wrong I am and how badly is my project designed in a sarcastic way which is impolite IMO. While You have nothing to say in the subject of this topic! As You wrote there are many brilliant people on this forum, with a very good programming skills, willing to help. I’m also helping If I have a knowledge on that particular problem. As I wrote earlier the problem is not that I have one working code and I need another solution but the problem is that it is not working well and I did some tests asking for help. You would know that If You would read whole topic. And yes maybe someone will point me something that is obvious but I’m trying with this since few days and I’ve stuck. Maybe some day someone will show You something that is obvious for everyone but not You! Will that change anything? But IMO forum is a place to help each other without being impolite. Moreover here are also people with a basic skills willing to build something and asking as You said “obvious” questions. With Your attitude I would rather say that You think this forum is for hi level skilled programmers only. I don’t want to waste Your time so simply unsubscribe from this topic unless You have something to say in a topic of SoftwareSerial.
Mon Dec 12, 2016 3:22 pm
konczakp wrote:I don’t know how You are doing this I cannot get this working. Here is my test code :
Mon Dec 12, 2016 4:45 pm
konczakp wrote:@mrburnette Since a few posts You are saying how wrong I am and how badly is my project designed in a sarcastic way which is impolite IMO. While You have nothing to say in the subject of this topic!
<…>
Mon Dec 12, 2016 4:50 pm
FWIW: Using a bluepill stm32 board as an arduino is not for newbies.

Your best path to success is to start with a maple mini board. The original maple arduino core was written for the maple mini and its big brother. The configuration and most problems have been worked out by the people long before we ever arrived here. When there are problems with the maple mini, it is most likely your code. The stm32duino core started with the maple core code and was ported to Arduino 1.5.x. Along the way we might have created new problems however that is less likely with the maple mini than any other board that is supported.

If this is your first rodeo with an stm32, your first step should be to obtain a maple mini clone. Once you move to the next level of using a generic stm32 (bluepill/redpill any other board) you are going to be much more on your own. As a community we are hoping people will become subject matter experts on the things near and dear to their hearts and come here more to share how you fixed something than to ask for questions.

I find the software serial a somewhat interesting problem and it is why I’ve bothered to delve into the issues.

-rick

Mon Dec 12, 2016 5:12 pm
@rick:
I find the software serial a somewhat interesting problem and it is why I’ve bothered to delve into the issues.
With 3 physical USARTS there is little need in the past. The current problem seems to be that one of Ron’s version does not support multi-instance – or the Op has had issues configuring a multi-instance, leaving one serial port short for the port.

I am having a difficult time with the port because every step appears to involve some critical issue to be solved and the Op is having to rely solely upon the forum since this is their first experience with the STM32. It appears from posts that the Op has a Maple Mini from Baite but also is using a Blue Pill which seems to be the final target. But precious little is being provided in the overall port process except on a Q/A piecemeal basis.

I want every STM32 project to be successful; extending that to even AVR and ESP8266.

Ray

Mon Dec 12, 2016 5:53 pm
mrburnette wrote:@rick:
With 3 physical USARTS there is little need in the past. The current problem seems to be that one of Ron’s version does not support multi-instance – or the Op has had issues configuring a multi-instance, leaving one serial port short for the port.
Mon Dec 12, 2016 6:41 pm
Rick Kimball wrote:mrburnette wrote:
<…>
The examples provided by @RonC only work for some unknown board. To get this stuff to work with a bluepill or any other board you have to pick specific pins as I outlined in that longish post about the pin_map table. There doesn’t seem to be anything wrong with multiple instance as long as you are picking the right pins and timers.

This multi instance example works fine:
<…>
The code above works for me and shows you can use different instances and even different speeds without failing.

This SoftSerialIntCC timer based code actually works quite nicely. I looked at the pulses on a scope and the bit times are right on the money. However, this code does chew up a bunch of timers and timer channels (1,2, and 3). Making it work properly requires an understanding of the pin map table for your board and how timer capture / compare works on the STM32. Knowing where to look in stm32f103 datasheet is also important to make sure your pin map table is using the right timer and channel for each pin.

-rick

Mon Dec 12, 2016 8:30 pm
Thank You very mych Rick ! Now everything is clear. I thought that You were saying about softserialSTM and not softserialCC because I asked about both. Now I know how to choose pin number to get it working. I really appreciate that! Thank You very much for help.
Tue Dec 13, 2016 5:06 am
Here is a wrapper to make the SoftSerialIntCC easier to use:
/*
TimerSerial.h - simple wrapper for SoftSerialIntCC.h

As SoftSerialIntCC only works on specific pins and timer combinations
this header declares the valid TimerxSerial pins that work on both the
bluepill and the maple_mini

The 'x' indicates which timer is being used. SoftSerialIntCC
uses 3 of the timer channels (1,2, and 3)
Channel 1 must be the tx pin
Channel 2 must be the rx pin,
Channel 3 is used for a timeout

Seeo:
https://github.com/wingspinner/SoftSerialIntCC/

*/

#ifndef _TIMERSERIAL_H_
#define _TIMERSERIAL_H_

#include <SoftSerialIntCC.h>

SoftSerialInt Timer1Serial(PA9, PA8, 1); // 26, 27 on maple mini
SoftSerialInt Timer2Serial(PA1, PA0, 2); // 10, 11 on maple mini
SoftSerialInt Timer3Serial(PA7, PA6, 3); // 4, 5 on maple mini
SoftSerialInt Timer4Serial(PB7, PB6, 4); // 15, 16 on maple mini

#endif

Tue Dec 13, 2016 11:41 am
It’s working like a charm! Thank You one more time. You have helped me much and I think not only me This topic is the first one in google when someone will enter stm32 software serial.
Tue Dec 13, 2016 12:24 pm
As lot of GPIOs are used for software serial, next step would be to implement software SPI, USB, CAN and I2C, because the HW-SPI,-USB, -CAN and-I2C pins are used for software serial…
Wed Mar 01, 2017 3:54 pm
Hi guys new little problem for me… im getting a not found error…
Its there and the location that says its not found the library has the library in there… Im a bit stumped.
Any ideas?
Wed Mar 01, 2017 3:56 pm
check the properties file ? restricted platform ?
stephen
Wed Mar 01, 2017 4:24 pm
I also have the problem not receiving signls from space…
Wed Mar 01, 2017 4:45 pm
Softwareserial Library Download
wheres the properties file? cant find it for the library
Wed Mar 01, 2017 5:00 pm
library.properties – in the libraries folder; in my case /home/stephen/sketchbook/libraries/Adafruit_GFX/library.properties
contents are
name=Adafruit GFX Library
version=1.1.5
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
paragraph=Install this library in addition to the display library for your hardware.
category=Display
url=https://github.com/adafruit/Adafruit-GFX-Library
architectures=*
Thu Mar 02, 2017 11:32 am
im not suing the gfx library… just trying to get softwareserial to be recognised as installed… its really strange
Thu Mar 02, 2017 4:43 pm
i wasn’t saying that, i just put that in to show the architecture line in the library.properties file
srp
Thu Dec 21, 2017 4:50 am
This multi instance example works fine:…

It does not work correctly. The example showed a corner case where it did work. However if you try to test it the other way around where the other port are trying to receive data it does not work.

Thu Dec 21, 2017 5:04 am
Thu Dec 21, 2017 9:31 pm
I have tried the AT and CC drivers, all have issues. Some software Uarts can receive but not transmit, other can transmit but not receive.Here is one simple example that demonstrates the problem. One implementation I tested worked for 19 characters and then stopped working. The code I have posted below code may work for a short period of time (a few minutes) but normally just does not work.

The platform I am using is a BluePill STM32F103 running at 72MHz.

In this example I have used a single hardware Uart (Serial 1) and one software UART. I have added LED on and off statements and a 100ms delay so that you can see when a character has been received by the respective UART.

The symptoms of this example is when the processor is reset, the initial start messages are correctly sent out of both Serial ports. When characters are typed on the terminal connected to the HW UART receive input, the character is echoed both to the terminal attached to the HW Uart and the Software Uart and the LED flashes appropriately indicating a character was received by the HW Uart.

When characters are typed on the terminal connected to the SW UART receive input, the character are NOT echoed to either terminal HOWEVER the LED flashes appropriately indicating a character was received by the SW Uart. My conclusion for this specific example is the timing for the SW read is broken.

#include 'TimerSerial.h'

Arduino Serial Library

#define ConsoleSerial Serial1
#define StatusLed PC13
#define StatusLedOn digitalWrite(StatusLed, LOW)
#define StatusLedOff digitalWrite(StatusLed, HIGH)

void setup()
{
pinMode(StatusLed, OUTPUT);
ConsoleSerial.begin(57600);

// set the data rate for the SoftwareSerial port
Timer2Serial.begin(9600); // (PA1,PA0)
}

void loop() // run over and over
{
ConsoleSerial.println(');
ConsoleSerial.println('ConsoleSerial is active');
Timer2Serial.println('Timer2Serial is active');

while (1) {
if (ConsoleSerial.available()) {
digitalWrite(StatusLed, LOW);
int c = ConsoleSerial.read();
ConsoleSerial.write(c);
Timer2Serial.write(c);
delay(100);
digitalWrite(StatusLed, HIGH);
}

if (Timer2Serial.available()){
digitalWrite(StatusLed, LOW);
int c = Timer2Serial.read();
Timer2Serial.write(c);
ConsoleSerial.write(c);
delay(100);
digitalWrite(StatusLed, HIGH);
}
}
}

Tue Feb 06, 2018 5:22 am

Softwareserial Arduino Library Download

I made some slight changes to your code. I don’t echo the Timer4Serial . To test I used the local echo option on the putty terminal for Timer4Serial. This allows you to send lots of data without it being overrun.

Download Arduino Softwareserial Library

I also looped until I exhaust the available input instead of grabbing one character at a time from each. I’m assuming your real world usage of this will be a command send and then a response type of situation. Adjust for your case if it isn’t
#include 'TimerSerial.h'

#define ConsoleSerial Serial
#define SlaveSerial Timer4Serial
#define StatusLed PC13
#define StatusLedOn digitalWrite(StatusLed, LOW)
#define StatusLedOff digitalWrite(StatusLed, HIGH)

void setup()
{
pinMode(StatusLed, OUTPUT);
ConsoleSerial.begin(115200);
// set the data rate for the SoftwareSerial port
SlaveSerial.begin(115200); // (PB7,PB6)

Arduino Softwareserial Download

while(!ConsoleSerial.isConnected());

}

void loop() // run over and over
{
ConsoleSerial.println(');
ConsoleSerial.println('ConsoleSerial is active');
SlaveSerial.println('SlaveSerial is active');

while (1) {
if (ConsoleSerial.available()) {
//digitalWrite(StatusLed, LOW);
int c;
while((c = ConsoleSerial.read()) != -1 ) {
SlaveSerial.write(c&0xff);
ConsoleSerial.write(c&0xff);
}
//digitalWrite(StatusLed, HIGH);
}

if (SlaveSerial.available()){
digitalWrite(StatusLed, LOW);
int c;
while( (c=SlaveSerial.read()) != -1 ) {
//SlaveSerial.write(c);
ConsoleSerial.write(c);
}
digitalWrite(StatusLed, HIGH);
}
}
}

Fri Feb 09, 2018 2:17 am
Thanks Rick however this was not my production code, this was my code to demonstrate the problem.

The testing was done by manually by slowing typing characters on the keyboard. There was no chance to overflow a buffer. The LED code and delay was added to flash a LED when a character was processed. This showed me a character was received from the receive logic. The reason I echoed the character was to specifically see if the echo character was the same as the transmitted character – it was not.

I found the code to be very flacky, sometimes it worked for a a few minutes, sometimes it failed quickly.