Skip to content
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

SoftwareSerial renewal #26

Merged
merged 1 commit into from
Jul 19, 2020
Merged

SoftwareSerial renewal #26

merged 1 commit into from
Jul 19, 2020

Conversation

jg1uaa
Copy link
Contributor

@jg1uaa jg1uaa commented Jul 17, 2020

based on ArduinoCore-avr 1.8.3 code (https://github.com/arduino/ArduinoCore-avr/tree/1.8.3/libraries/SoftwareSerial/src).

There is significant difference between pre-1.6.0 and after-1.6.1.

  • added stopListening() method
  • removed delay table, use <util/delay_basic.h> with calculated delays
    from CPU clock

Some libraries (for example, RadioLib https://github.com/jgromes/RadioLib) requires stopListening() method so renewal of SoftwareSerial is mandatory.

And different from ATmega328P, LGT8F328P's SBIW instruction takes 1 clock (ATmega328P takes 2 clocks). This means we need to adjust _delay_loop_2() in <util/delay_basic.h> for lgt8fx. Currently SoftwareSerial.cpp has own _delay_loop_2() implementation.

based on ArduinoCore-avr 1.8.3 code (https://github.com/arduino/ArduinoCore-avr/tree/1.8.3/libraries/SoftwareSerial/src).

There is significant difference between pre-1.6.0 and after-1.6.1.

- added stopListening() method
- removed delay table, use <util/delay_basic.h> with calculated delays
  from CPU clock
@dbuezas
Copy link
Owner

dbuezas commented Jul 17, 2020

Impressive! Will do some testing this weekend and merge it.
The other one I tuned by brute force (searching for the values at runtime to get communication between pc and board) so I didn't dare using new versions without the hard coded tables.

@jg1uaa
Copy link
Contributor Author

jg1uaa commented Jul 18, 2020

Here is the results of test before submitting pull request.
The method is briefly running SoftwareSerialExample and typed some characters from other terminal.
I didn't run long time to evaluate stability, and not tested under low (1 and 2MHz) clock.

bps 32MHz 16MHz 8MHz 4MHz
230400 ok ok Rx failed TRx failed
115200 ok ok ok Rx failed
57600 ok ok ok ok
38400 ok ok ok ok
19200 ok ok ok ok
9600 ok ok ok ok
4800 ok ok ok ok
2400 ok ok ok ok
1200 ok ok ok ok
600 ok ok ok ok
300 ok ok ok ok

@jg1uaa
Copy link
Contributor Author

jg1uaa commented Jul 19, 2020

FYI, there is the diff with ArduinoCore-avr 1.8.3's code at https://pastebin.com/VRuLqcWa
I think core codes looks old, it's time to overhaul -> now trying.

@dbuezas
Copy link
Owner

dbuezas commented Jul 19, 2020

Yes, it is based on an older Arduino core. As stated in the readme, my starting point was Larduino_HSP v3.6c (the most Arduino compatible I found) which is 3 years old.

Looking forward to see what else you optimise!

I'm working in making the new release with all extra pull requests and a bunch of improvements at once, so it will take me a bit longer.

@seisfeld
Copy link
Contributor

@dbuezas Are you planning to make sure to not break existing functionality? That would be really appreciated. :)

@dbuezas
Copy link
Owner

dbuezas commented Jul 19, 2020 via email

@dbuezas dbuezas merged commit 0e3b035 into dbuezas:master Jul 19, 2020
@dbuezas
Copy link
Owner

dbuezas commented Jul 19, 2020

@jg1uaa, the new SoftwareSerial is 438 bytes smaller!
I tested it with 1 and 2Mhz for completeness:

bps 32MHz 16MHz 8MHz 4MHz 2MHz 1MHz
230400 ok ok Rx failed TRx failed TRx failed TRx failed
115200 ok ok ok Rx failed TRx failed TRx failed
57600 ok ok ok ok TRx failed TRx failed
38400 ok ok ok ok TRx failed TRx failed
19200 ok ok ok ok ok TRx failed
9600 ok ok ok ok ok ok
4800 ok ok ok ok ok ok
2400 ok ok ok ok ok ok
1200 ok ok ok ok ok ok
600 ok ok ok ok ok ok
300 ok ok ok ok ok ok

And 300 baud doesn't even work in the HW Serial

@tandy1
Copy link

tandy1 commented Dec 20, 2022

I want to use the LG8F328P board as an alternative for the arduino nano to make a 6 channel DMX-controller. The library DMXSerial seems not compatible with the board.
I can upload the sketch to the LG8F328P, but the sketch doesn't work. ( Sketch is working with arduino nano.
Many thanks for the support

@LaZsolt
Copy link
Collaborator

LaZsolt commented Dec 20, 2022

@tandy1
It doesn't seem like a (software)serial communication problem. Could you provide more hardware and software details?
Please start a new discussion with this topic. https://github.com/dbuezas/lgt8fx/discussions

@tandy1
Copy link

tandy1 commented Dec 20, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants