arduino-nRF5 icon indicating copy to clipboard operation
arduino-nRF5 copied to clipboard

SoftwareSerial

Open andriyadi opened this issue 8 years ago • 23 comments

Is it possible to use SoftwareSerial? I have a requirement to communicate with a serial module. While the main/hardware serial is used for debugging, need another serial port to communicate with that module.

Please advice. Thanks.

andriyadi avatar Feb 22 '17 23:02 andriyadi

Maybe? I am not if anyone has tried using a Soft serial port yet.

What type of debugging are you trying to do? Just console line prints?

dlabun avatar Feb 24 '17 00:02 dlabun

Certainly not, because softserial relies on pinchange Interrupts, which itself use pin mapping. This works only on specified ports and Pins.

Diese Nachricht wurde von meinem Android Mobiltelefon mit WEB.DE Mail gesendet.Am 24.02.17, 01:44, dlabun [email protected] schrieb:

  Maybe? I am not if anyone has tried using a Soft serial port yet.


  What type of debugging are you trying to do? Just console line prints?


  —
  You are receiving this because you are subscribed to this thread.
  Reply to this email directly, view it on GitHub, or mute the thread.

MartinRobotz avatar Feb 24 '17 06:02 MartinRobotz

Hi @dlabun Yes, forgot to say that what I meant by "debugging" is "Serial.print" kind of stuff, to see what's going on. I read about RTT. Anyone has experience with it, if using RTT from Arduino environment/framework? As it seem it requires including code from Segger.

@MartinRobotz do you mean for specialized pins that supports pin interrupt, Software Serial works?

Thanks guys!

andriyadi avatar Feb 24 '17 09:02 andriyadi

For these pins it will work, but you need to know their mapping and the corresponding interrupt vector number PCINT0,1,2.... Then you have to adapt the SoftSerial library and put these interrupt vectors in the ISR. Every arduino uses different PCINT vectors for pin change interrupt. In theory that should be enough. Have a try.

MartinRobotz avatar Feb 24 '17 17:02 MartinRobotz

@andriyadi What I use do to with Microchip PICs when I ran out of UARTs is run all of my debugging information out over an I2C to UART bridge. It could be an option for you, check out the NXP website below.

http://www.nxp.com/products/signal-chain/bridges/single-uart-with-i2c-bus-spi-interface-64-bytes-of-transmit-and-receive-fifos-irda-sir-built-in-support:SC16IS740_750_760#featuresExpand

dlabun avatar Feb 24 '17 21:02 dlabun

SoftwareSerial is not supported at the time.

However, I believe it should be possible to port the AVR SoftwareSerial and CurieSoftwareSerial (Arduino 101) SoftwareSerial libs to nRF5x boards. Pull requests welcome.

sandeepmistry avatar Feb 25 '17 14:02 sandeepmistry

@dlabun SC16IS740 could be one option, thanks for the idea.

Found a breakout something like this and Arduino library like this. The library seems easy to port. Hope I can get my hands on it soon and will report the progress.

andriyadi avatar Mar 06 '17 04:03 andriyadi

In case its any use.

@rayburnette ported the PJRC version of SoftwareSerial STM32

See http://www.stm32duino.com/viewtopic.php?f=13&t=6

(Pauls original post was here https://forum.pjrc.com/threads/17461-SoftwareSerial-doesn-t-compile-for-Teensy-3-it-seems but there may be an updated version somewhere else)

Edit,

The ESP8266 guys also now have software serial, so that may also be a good starting point in terms of porting....

rogerclarkmelbourne avatar Mar 06 '17 04:03 rogerclarkmelbourne

I finally went to SC16IS740/50/60 route. Forked this library and add some convenient methods. Here's my repo: https://github.com/andriyadi/UART_Bridge

I'm using Sparkfun's breakout to test it out.

andriyadi avatar Apr 06 '17 18:04 andriyadi

I am fairly familiar with the SoftwareSerial library, and this looks like a pretty up to date port : https://github.com/arduino-org/arduino-core-nrf52/tree/master/libraries/SoftwareSerial

It needed a slight mod as the attachInterrupt function doesnt return the bitMask, but the problem is that it didnt work for me using this core. I tried the simple hardware/software serial echo example and it stalled after the first software print.

Very wierd as the cores are very similar, and i assume it works for the arduino core

micooke avatar Oct 09 '17 09:10 micooke

@micooke can confirm this! - Have done the same. but it doesen't work correctly. I swichted then over to Adafruit nRF52, because they have done the same and it does also not work (on my side)) I I asked in the Adafruit forum. I don't know but for hattach it does work - we couldn't solve it at the moment. By the way - the original Arduino Primo SoftwareSerial on their HAL is fully functionall at all!

prjh avatar Oct 09 '17 17:10 prjh

@prjh - thanks for the confirmation. I might have a look at it today. The only thing i can think of it a conflict with the interrupt, which makes no sense as there isnt anything using the gpiote as far as i can tell.

Yes, im working with the adafruit one as well - the arduino-org one seems identical

micooke avatar Oct 09 '17 20:10 micooke

Looking at WInterrupts.h, it looks fine. I would make a couple minor changes, but everything I've tried hasnt worked. I might try to resolve this with a simpler pinchange test first, but two three things stand out.

  • GPIOTE interrupt is stupidly high priority(1), it should probably be 3 or lower
  • (minor) interrupts are asynchronous, so in the Handler the for loop should break when it sees its first set interrupt and free itself up
  • (minor) in attachInterrupt the configuration should be set prior to enabling the interrupt handler

I've made these changes locally (only the first one should affect a simple example), no dice.

~~Having said this, I2C doesn't work for me at the moment so it's possible (read likely) that my local software/hardware configuration is stuffed.~~ (i had allocated sda, scl to pins 16,17 of the Taida board - they are not connected :unamused: )

micooke avatar Oct 13 '17 00:10 micooke

@dlabun, @sandeepmistry - the issue is in Arduino.h, three #defines are incorrect.

//#define digitalPinToPort(P)        ( &(NRF_GPIO[P]) ) // INCORRECT - possible seg fault
#define digitalPinToPort(P)        ( NRF_GPIO )
//#define portOutputRegister(port)   ( &(port->OUTSET) ) // INCORRECT
#define portOutputRegister(port)   ( &(port->OUT) )
//#define portModeRegister(port)     ( &(port->DIRSET) ) // INCORRECT
#define portModeRegister(port)     ( &(port->DIR) )

I can create a PR with this fix. Are are you interested in supporting the SoftwareSerial library as i can pull this in at the same time?

With these fixes (@prjh - this is the same problem in the adafruit core, they have 2 incorrect), the SoftwareSerial library from Adafruit (https://github.com/adafruit/Adafruit_nRF52_Arduino/tree/master/libraries/SoftwareSerial) or Arduino (https://github.com/arduino-org/arduino-core-nrf52/tree/master/libraries/SoftwareSerial) should work fine. My local version is based off the adafruit one (the arduino one looks identical) hacked with Tx/Rx only & half-duplex options, so it will take a while to regression test these for full confirmation.

micooke avatar Oct 15 '17 23:10 micooke

@micooke Congratulation! I have tested SoftwareSerial with the attachInterrupt() changes and the above #defines well with a nRF52-DK board. Up to 38400 baud, it does work straight forward. In my tests with the Arduino Primo implementation I got baud rate up to 74880 - don't know why at the moment. Never the less it does work - Thanks for your investigation.

prjh avatar Oct 16 '17 17:10 prjh

I have created a PR for the core side without a SoftwareSerial library, but i am happy to add this in. See PR #205

micooke avatar Oct 17 '17 02:10 micooke

Just a note that ive added SoftwareSerial to the PR.

@prjh - im not sure why the primo out performs?

I will say that the tuning is very coarse for most non-avr variants of this library as they use delayMicroseconds(), whereas the avr uses _delay_loop_2() from <util/delay_basic.h> which is sub-microsecond (4 clock cycles). In other words, this library won't work at high speeds as the tuning will be off - which is what you have observed.

micooke avatar Oct 25 '17 20:10 micooke

a question: Is SoftwareSerial currently usable?

idreamsi avatar Apr 09 '18 08:04 idreamsi

Not at this time

dlabun avatar Apr 09 '18 13:04 dlabun

@idreamsi - you can always try the PR associated with this, #205. This is still waiting a merge

micooke avatar Apr 09 '18 20:04 micooke

@micooke - I tested it, It works. Thank you very much ;)

idreamsi avatar Apr 09 '18 21:04 idreamsi

You are very welcome

micooke avatar Apr 09 '18 21:04 micooke

any update or plan for out of box software serial? or some complete tutorial how do get it work now. Thank you (if not, that please write some verified I2C - UART bridge)

shajek avatar Mar 05 '19 19:03 shajek