SoftwareSerial

Please do not post requests
User avatar
mrburnette
Posts: 2216
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: SoftwareSerial

Post by mrburnette » 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!
<...>
I apologize if you think I was posting in a sarcastic manner, I assure you that was not my intentions; but I was NOT posting blindly. I have read every post you have posted since joining the forum and out of the current 105, at least 80 are direct requests for personal assistance with some at-the-moment issue as you work through the port of the Atmega AVR port of your project to STM32duino. From ILI9341, to SD, to LCD backlight, to blue pill issues, to bootloader problems, to ENRF24, and now to Software serial.

I tried to help you the other day when I said you were going down the rabbit hole. In all of the 105 posts, only snippets of your code have been shared which is OK except for the continuing number of problems you are facing. In my world, the design process you are following is called "shotgunning" and what one gets is a tangled mess of spaghetti code that is going to be a freaking nightmare to maintain in the future... assuming you ever get the port working successfully at all. You have already stated that the AVR version of the project was a terrible mess to support; do you really think this STM version will be better if you are stitching piece to piece to piece to ... ?

Now while I was not trying to be sarcastic, I am saying that your approach to design is less than optimal: and I suspect time will prove me correct in saying that you are creating a support nightmare. Selecting a $2 uC appears to simply be a poor decision based upon your continuing issues.


Ray

PS: Yes, I am an ass ... I am a system architect and being an ass is part of my job description when the telling is the truth.

User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: SoftwareSerial

Post by Rick Kimball » 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
-rick

User avatar
mrburnette
Posts: 2216
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: SoftwareSerial

Post by mrburnette » 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

User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: SoftwareSerial

Post by Rick Kimball » 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.
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:

Code: Select all

// bluepill specific version that works
#include <SoftSerialIntCC.h>

SoftSerialInt softserial1(PB7, PB6, 4);
SoftSerialInt softserial2(PA1, PA0, 2);

void setup()
{
  // set the data rate for the SoftwareSerial port
  softserial1.begin(115200);
  softserial2.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() // run over and over
{
  softserial1.println("Type away");
  while (1) {
    if ( softserial1.available() ) {
      digitalWrite(LED_BUILTIN, LOW);
      int c = softserial1.read();
      softserial2.write((uint8_t)c);
      softserial1.write((uint8_t)c);
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}
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
Last edited by Rick Kimball on Tue Dec 13, 2016 4:17 am, edited 1 time in total.
-rick

User avatar
mrburnette
Posts: 2216
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: SoftwareSerial

Post by mrburnette » 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
Beautiful example, Rick. This should find it way into the WiKi since it embodies a number of blue-centric physical entities.

And too, it may be enough to help the Op over their most recent integration problem; although, I do not know if the lost of 3 timers will throw water on his parade.

So, readers: There is a take-a-way here for prospective port efforts. Create a uC resource usage map of the old environment and create a uC resource map of the port hardware environment in addition to doing a functional library comparison on availability and resource consumption: nothing comes free and changing from an AVR 8-bit world to an STM 32-bit world is more than int being 16 bits on AVR and 32 bits on STM32.

Thanks to RonC for the SoftwareSerial library and to Rick for showing advance usage in a multi-instance scenario.

Ray

konczakp
Posts: 191
Joined: Thu Jul 14, 2016 4:17 pm

Re: SoftwareSerial

Post by konczakp » 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.

User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: SoftwareSerial

Post by Rick Kimball » Tue Dec 13, 2016 5:06 am

Here is a wrapper to make the SoftSerialIntCC easier to use:

Code: Select all

/*
   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
And an example to use it:

Code: Select all

/*
   softserial broadcast - read from Timer4Serial and spew to all the others
   works with bluepill (generic_stm32f103c8) and maple mini
*/
#include "TimerSerial.h"

void setup()
{
  // set the data rate for the SoftwareSerial port
  Timer1Serial.begin(9600);    // (PA9,PA8);
  Timer2Serial.begin(9600);    // (PA1,PA0)
  Timer3Serial.begin(9600);    // (PA7,PA6)
  Timer4Serial.begin(115200);  // (PB7,PB6)

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() // run over and over
{
  Timer4Serial.println("");
  Timer4Serial.println("Type something to broadcast");

  while (1) {
    if ( Timer4Serial.available() ) {
      digitalWrite(LED_BUILTIN, LOW);
      int c = Timer4Serial.read();
      Timer1Serial.write(c);
      Timer2Serial.write(c);
      Timer3Serial.write(c);
      Timer4Serial.write(c);
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}
enjoy!

-rick
-rick

konczakp
Posts: 191
Joined: Thu Jul 14, 2016 4:17 pm

Re: SoftwareSerial

Post by konczakp » 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.

stevestrong
Posts: 2063
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: SoftwareSerial

Post by stevestrong » 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... ;)

Nutsy
Posts: 260
Joined: Sun Jul 24, 2016 4:26 pm

Re: SoftwareSerial

Post by Nutsy » 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?

Post Reply