New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soft Serial on ESP8266 is broken because of missing hw_timer functionality #1511
Comments
I'm not sure if this would work very well as the wifi could interrupt the timing of the software and the bit rates could be off. Are two hardware ports not enough? Given that you can turn off debug and the serial console anspd use wifi. |
Well I just want to know how to use this Software Serial port and If it is not possible to use with ESP8266 than I will mention this on ESP8266 page - Thats all. |
Literally just like you do with software SPI/I2C/etc:
|
Thanks, looks simple so tried immediately.
Is there something I can check to find out why s.write() causes a reboot? |
You'd have to ask someone who knows ESP8266 butter. My guess would be it's the digitalPulse implementation - either the whole thing takes too long (unlikely) or it's blocking execution because it's not using the util timer, and that means the time periods given to it get out of sync. ... maybe the time given to it ends in the past and there's no bounds checking so the negative number ends up as a big positive number, which makes it pause for too long and trip the watchdog |
Ok, so I will check digitalPulse and come back with my results. |
Sending a single char does not reboot, but send more cause reboot no matter what baud rate is chosen.
|
Where to find the function that loops over the given data? |
Got the jsiConsolePrintf active. one single char s.write works, but more than one char than it reboots |
Ok, it's using the Util Timer. The Util timer is supposed to be IRQ-based and able to preempt execution in the main thread. In ESP8266 it seems it's not. So what happens is serial write schedules a bunch of tasks and then waits for the buffer to get empty, thinking the tasks will get executed eventually. They never will. Sure, we could come up with some awful hack using delays to make software serial TX work, but it doesn't solve the underlying problem. IMO we'd be best off using the proper hardware timer (according to https://www.espressif.com/sites/default/files/documentation/2C-ESP8266_Non_OS_SDK_API_Reference__EN.pdf there's an example in Bonus is:
|
Cool, starting to work on this. I'm curious how far I will get. |
Ok, code is there and compiling is possible. this is how I understand what happens when softSerial is using write to send data:
Question: how to code code is available in branch ESP8266_hw_timer |
What you're doing there looks promising (the period may need some scaling based on the timer speed I guess). Basically you want IMO you might be better swapping the code for |
Thanks, pushed changes.
Anything else that should be added? |
Great! Does it work? What about |
It does not reboot when sending more than one char or when running digitalPulse() Have to check the Data with a logic analyser and scope. Yes sure why not test pwm too. |
I imagine waveform might work well too now as well! Thanks for this - it's one of the really big things that ESP8266 has been missing. |
I think that‘s it. |
That looks awesome - thanks! You happy to merge in what's there? Please could you just delete the comments and |
Yep, lets clean up the code :) |
Gordon, I would say it's time to merge. Cleaned code is pushed, will update CHANGELOG and docs after merge. Many Thanks to Gordon for his support to make this work even he is not payed for his effort. ESP8666 folks: If you where waiting for this feature please donate. |
Thanks for your work on this! This should make a really big difference to ESP8266's usefulness - especially with the soft PWM stuff. |
@opichals It's all gone, please check the latest version |
Try to test soft serial on ESP8266.
In ESP8266_4MB.py are two serial defines and assigned to pins and can be access is via Serial1 and Serial2.
What is necessary use a soft serial on ESP8266 and run this simple testcode?
The text was updated successfully, but these errors were encountered: