{"action":"created","issue":{"url":"https://api.github.com/repos/arduino/Arduino/issues/2032","labels_url":"https://api.github.com/repos/arduino/Arduino/issues/2032/labels{/name}","comments_url":"https://api.github.com/repos/arduino/Arduino/issues/2032/comments","events_url":"https://api.github.com/repos/arduino/Arduino/issues/2032/events","html_url":"https://github.com/arduino/Arduino/pull/2032","id":32143466,"number":2032,"title":"SoftwareSerial improvements, fixes and optimizations","user":{"login":"matthijskooijman","id":194491,"avatar_url":"https://avatars.githubusercontent.com/u/194491?v=3","gravatar_id":"","url":"https://api.github.com/users/matthijskooijman","html_url":"https://github.com/matthijskooijman","followers_url":"https://api.github.com/users/matthijskooijman/followers","following_url":"https://api.github.com/users/matthijskooijman/following{/other_user}","gists_url":"https://api.github.com/users/matthijskooijman/gists{/gist_id}","starred_url":"https://api.github.com/users/matthijskooijman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthijskooijman/subscriptions","organizations_url":"https://api.github.com/users/matthijskooijman/orgs","repos_url":"https://api.github.com/users/matthijskooijman/repos","events_url":"https://api.github.com/users/matthijskooijman/events{/privacy}","received_events_url":"https://api.github.com/users/matthijskooijman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/arduino/Arduino/labels/Library:%20SoftwareSerial","name":"Library: SoftwareSerial","color":"000000"},{"url":"https://api.github.com/repos/arduino/Arduino/labels/Type:%20Bug","name":"Type: Bug","color":"0052cc"},{"url":"https://api.github.com/repos/arduino/Arduino/labels/Type:%20Improvement","name":"Type: Improvement","color":"0052cc"},{"url":"https://api.github.com/repos/arduino/Arduino/labels/Version:%201.5.x","name":"Version: 1.5.x","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2014-04-24T12:22:06Z","updated_at":"2015-03-06T08:09:41Z","closed_at":"2015-03-05T17:05:45Z","pull_request":{"url":"https://api.github.com/repos/arduino/Arduino/pulls/2032","html_url":"https://github.com/arduino/Arduino/pull/2032","diff_url":"https://github.com/arduino/Arduino/pull/2032.diff","patch_url":"https://github.com/arduino/Arduino/pull/2032.patch"},"body":"This pullrequest contains a bit of everything, for the SoftwareSerial library. The first couple of commits I still had lying around from last year, forgot to send a pullrequest for those earlier. They're mostly cleanups around the introduction of a `stopListening()` method, that can be made to disable RX of a SoftwareSerial instance.\r\n\r\nThe second half of the commits are a lot of optimizations and fixes, to make the SoftwareSerial code faster and more reliable, so it works again at higher baudrates. This is only partly succesful for RX, since at higher baudrates where bytes are sent back-to-back, the CPU spends most of the time in the interrupt handler. At higher baudrates, the interrupt overhead (cleanup and setup) becomes longer than than the available time (from halfway the stopbit to halfway the startbit) and reception starts to fail.\r\n\r\nThis problem is particularly evident when running at 8Mhz, or when using gcc 4.3.2 (which makes terrible register allocation choices). Using gcc 4.8.2 and running at 16Mhz, things work up to 115200 (though bytes are still regularly corrupted because of the millis() timer ISR delaying the SoftwareSerial interrupt). Using 1.5 or 2 stop bits on the other side will probably help here (though I haven't tested this, and there is no way to make SoftwareSerial do TX with longer stop bits.\r\n\r\nThere is probably some room for improvment still, but that would require the RX ISR / `recv` method to be handcoded in assembly. The upside of that would be that it's 100% deterministic, without depending on the compiler used, but it's a lot of work that I'm not going to invest right now (getting this far has cost me enough time already).\r\n\r\nThese commits also remove the delay lookup tables that were previously present, since the values can easily be calculated at runtime. This saves around 160 bytes of program memory.\r\n\r\nIn addition to making the code faster, it is also a lot smaller. Overall, a typical SoftwareSerial sketch on the Uno saves slightly over 400 bytes of program space (including the savings for the lookup table removal)."},"comment":{"url":"https://api.github.com/repos/arduino/Arduino/issues/comments/77521383","html_url":"https://github.com/arduino/Arduino/pull/2032#issuecomment-77521383","issue_url":"https://api.github.com/repos/arduino/Arduino/issues/2032","id":77521383,"user":{"login":"NicoHood","id":6888294,"avatar_url":"https://avatars.githubusercontent.com/u/6888294?v=3","gravatar_id":"","url":"https://api.github.com/users/NicoHood","html_url":"https://github.com/NicoHood","followers_url":"https://api.github.com/users/NicoHood/followers","following_url":"https://api.github.com/users/NicoHood/following{/other_user}","gists_url":"https://api.github.com/users/NicoHood/gists{/gist_id}","starred_url":"https://api.github.com/users/NicoHood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NicoHood/subscriptions","organizations_url":"https://api.github.com/users/NicoHood/orgs","repos_url":"https://api.github.com/users/NicoHood/repos","events_url":"https://api.github.com/users/NicoHood/events{/privacy}","received_events_url":"https://api.github.com/users/NicoHood/received_events","type":"User","site_admin":false},"created_at":"2015-03-06T08:09:41Z","updated_at":"2015-03-06T08:09:41Z","body":"Thanks!"}}