tag:blogger.com,1999:blog-6245413346375218188.post461449678699332103..comments2024-03-15T05:42:04.481-07:00Comments on Nerd Ralph: AVR half-duplex software UART supporting single pin operationRalph Doncasterhttp://www.blogger.com/profile/00037504544742962130noreply@blogger.comBlogger99125tag:blogger.com,1999:blog-6245413346375218188.post-160619587443737352022-02-03T09:34:44.256-08:002022-02-03T09:34:44.256-08:00Hi Ralph,
Revisiting this 8 years later. Fascinati...Hi Ralph,<br />Revisiting this 8 years later. Fascinating mechanism.<br />Any thoughts on using a N-MOSFET?Anonymoushttps://www.blogger.com/profile/05336124456832255698noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-28765350066735091002021-12-05T02:04:05.563-08:002021-12-05T02:04:05.563-08:00Hi Ralph,
Adding a schottky diode from NPN transi...Hi Ralph,<br /><br />Adding a schottky diode from NPN transistor base to collector transforms it into a schottky transistor. This change made my circuit perform well over 1M baud rate with TTL. This change also reduces the need to iterate through different base resistor value for the specific system.<br /><br />What the schottky diode does is to provide a feedback loop that prevents the NPN deep into saturation. Low base resistor value can drive NPN into saturation, which significantly increased recovery time from ON state to OFF state.<br /><br />My application: using a 5V TTL FTDI cable to test drive a serial "smart" servo that uses a 1-wire-like communication bus. when a valid packet sent in over 1M baud 5V TTL, the servo replies a packet in 30 us. I have attempted using the RTS pin as a makeshift GPIO, but turned out I could only flip it every 50 us. <br /><br />The servo has an EEPROM that can configure response time and baud rate, but with your solution, the servo works out of box.<br /><br />Best,<br /><br />Dian<br /><br /> <br /><br /><br /><br /> Anonymoushttps://www.blogger.com/profile/01070898619038913140noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-706373351411418022018-09-12T11:15:29.008-07:002018-09-12T11:15:29.008-07:00Hi Ralph,
unfortunately I do not understand any a...Hi Ralph, <br />unfortunately I do not understand any assenly. Could you publish a version of the library with the serial levels inverted (idle is low)? Anonymoushttps://www.blogger.com/profile/05900698639817811735noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-11227792995391451952018-09-12T11:12:29.792-07:002018-09-12T11:12:29.792-07:00Hi Ralph,
would it be possible for you to publish ...Hi Ralph,<br />would it be possible for you to publish this code as Arduino library for inverted serial levels where idle is low? I guess it would not be very difficult for you. I unfortunately do not understand any assembly :(Anonymoushttps://www.blogger.com/profile/05900698639817811735noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-47710093854620240252018-04-01T16:19:40.661-07:002018-04-01T16:19:40.661-07:00I did play with an ISR Rx bit a couple years ago, ...I did play with an ISR Rx bit a couple years ago, but never finished. The main use I have found for the bitbang UART is debug output, so I haven't got a good use case and hence much motivation for making an ISR-based receive.Ralph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-88551610817847197572018-03-26T04:40:31.861-07:002018-03-26T04:40:31.861-07:00Hi Ralph, Did you ever find an opportunity to work...Hi Ralph, Did you ever find an opportunity to work on the ISR version?KevinOfOzhttps://www.blogger.com/profile/15935266228845565186noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-58325133100787506162017-09-18T06:03:02.343-07:002017-09-18T06:03:02.343-07:00There's two possible problems you might be run...There's two possible problems you might be running into. Your LED may be limiting the signal high level. Blue (and some green) LEDs turn on around 3V, and so would be best. Red LEDs turn on around 2V, which could clip the high signal level so that it is sometimes not recognized.<br />Another issue you may run into depending on the speed is a poorly calibrated internal oscillator. I have some info about adjusting OSCCAL in this post:<br />http://nerdralph.blogspot.ca/2014/04/attiny85-as-433mhz-transmitter-fail.htmlRalph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-65265492882726485032017-09-07T11:37:33.560-07:002017-09-07T11:37:33.560-07:00I breadbord'ed your circuit and installed your...I breadbord'ed your circuit and installed your example code into an ATTiny85, after switching the Rx/Tx port from PB5 (reset) to PB1. It works although I have a timing issue because I'll often, but not always, have to enter a character several times for it to be received.<br />BTW - I also tried driving an LED from the same port but I was not successful. Either the LED wouldn't light of the serial didn't work, depending on the LED's resistor value.celemhttps://www.blogger.com/profile/08902833703052607345noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-80682037042803855272017-09-06T20:43:32.184-07:002017-09-06T20:43:32.184-07:00Ralph, In looking at the schematic again, my LED c...Ralph, In looking at the schematic again, my LED connected to Tx/Rx would need to remain tied to resistive ground. The resistor's value is currently 1k to dimly light the LED but when used in conjunction with your circuit that might not be the best value. celemhttps://www.blogger.com/profile/08902833703052607345noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-63868072361145811732017-09-06T20:26:41.595-07:002017-09-06T20:26:41.595-07:00Ralph, I have no pins left on my ATTiny85 design. ...Ralph, I have no pins left on my ATTiny85 design. I have an LED (to ground through a 1k resistor) on PB1. This LED blinks hourly and also blinks patterns in response to a button press duration. Otherwise it is idle. Looking at your circuit it seems that I could use your circuit connecting your Tx/Rx to the same PB1 that the LED is on but tie the LED to Vcc through the resistor and invert the blink logic. Both functions should work but would obviously interfere if used simultaneously. That is ok with me as they won't be used together. What do you think?celemhttps://www.blogger.com/profile/08902833703052607345noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-70246712604797325102017-06-14T08:00:14.618-07:002017-06-14T08:00:14.618-07:00Hello Ralph,
Many thanks for this very small sized...Hello Ralph,<br />Many thanks for this very small sized and efficient library! <br />Is there any way to make this working with lower baud rates like 10400?<br />#define BAUD_RATE 10400<br />StefVanhttps://www.blogger.com/profile/18004133315101688492noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-27623475742468247502017-05-30T23:24:27.240-07:002017-05-30T23:24:27.240-07:00Hi Ralph,
Appreciate your awesome work. Please can...Hi Ralph,<br />Appreciate your awesome work. Please can you advise whether this can be used for communication between multiple attiny and also can hot swap functionality be added.<br />Many thanks.azimishanihttps://www.blogger.com/profile/07726471471555877888noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-78765694581256264292017-05-05T06:13:40.681-07:002017-05-05T06:13:40.681-07:00Hi Abdul, I just noticed your comment in the mode...Hi Abdul, I just noticed your comment in the moderation queue.<br />I did most of my development with avr-gcc and makefiles, and just occasionally used the Arduino IDE. I expect if you use an older version of the Arduino IDE it should still work. Or you could try making the jump to command-line development.Ralph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-7436750964105764722017-04-11T22:22:22.258-07:002017-04-11T22:22:22.258-07:00Hi Ralph,
Thank you for sharing your amazing tric...Hi Ralph, <br />Thank you for sharing your amazing trick. The library and the code you provided does not seem to be working for me (Arduino IDE 1.81; ATTiny85V @ 8Mhz). Having the additionally circuitry and connected to a FTDI's Rx-Tx-GND, I'll only see echo of what I type in but not what I serOut. Could you please give any pointer?Anonymoushttps://www.blogger.com/profile/02879109045271920515noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-62329385947512591072016-07-20T17:46:41.778-07:002016-07-20T17:46:41.778-07:00I have a tiny routine in C to convert a binary 8-b...I have a tiny routine in C to convert a binary 8-bit value to 2 hex characters.<br />https://github.com/nerdralph/nerdralph/blob/master/avr/u8tohex.h<br />I used it in my spitest code:<br />https://github.com/nerdralph/nerdralph/blob/master/avr/spitest.cRalph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-57230100187261113192016-07-19T14:49:03.499-07:002016-07-19T14:49:03.499-07:00Hi!
I'm using this code on an ATtiny13, and it...Hi!<br />I'm using this code on an ATtiny13, and it works great! Do you know how I can send integer and/or float values? The code is only made for character arrays, and I'm really flipping' the bits and bytes with this microcontroller. Is there like a super elegant and efficient way to convert lets say the number 123 into characters and send them?Hanshttps://www.blogger.com/profile/11405527793008269684noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-62069912697710182982016-02-08T13:34:46.537-08:002016-02-08T13:34:46.537-08:00I don't think I'll be supporting it with t...I don't think I'll be supporting it with the Ardruino IDE any more, as I rarely use the IDE (I do most of my development from the cli). I have been thinking about expanding http://nerdralph.blogspot.ca/2015/10/beta-picowiring-arduino-compatible.html and making it work as an Arduino Attiny core, which would include my asm soft serial implementation. The board manager seems to make this a lot easier than it used to be.Ralph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-5737300764833813242016-02-05T08:41:23.144-08:002016-02-05T08:41:23.144-08:00I have the same error. 1.6.6 do you have any news=...I have the same error. 1.6.6 do you have any news=Anonymoushttps://www.blogger.com/profile/11635573001184853758noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-60697872941713145742015-12-11T09:54:03.646-08:002015-12-11T09:54:03.646-08:00Ralph,I got it. Take your time :)
I didn't kne...Ralph,I got it. Take your time :)<br />I didn't knew about your blog until I found your serial implementation. Right now I'm in the middle of the proccess of reading all of it! <br /><br />Thanks, <br /><br />--<br />WillianDolencehttps://www.blogger.com/profile/14699143405125561266noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-59345883995328020662015-12-11T08:43:52.981-08:002015-12-11T08:43:52.981-08:00I think you'll have to wait until I get around...I think you'll have to wait until I get around to writing an ISR version. I'll need to recalculate RXSTART to compensate for the interrupt overhead as well as saving used registers on the stack. It involves counting the execution time of each instruction (in/out take 1 cycle, push/pop take 2, branch takes 2 cycles when true, 1 when false...) so it's not a short or simple answer.<br /><br />It will probably only take me a few hours once I get into it, but if you look at the rest of my blog you'll see there's lots of other irons I have in the fire...Ralph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-46412880057943091342015-12-11T05:57:58.550-08:002015-12-11T05:57:58.550-08:00Ralph, thanks for your clarifications and many man...Ralph, thanks for your clarifications and many many thanks for writing this very optmized code. <br />Yesterday, reading all the comments I noticed the other guy in similar situation. I did noticed your update version too and since I'm not skilled in assembler I could not get it working on a single pin. <br />Considering the fact I'm using Basicserial3 single pin version at 115200 what should be done to get rid of those problema? Or should I be trying to get updated version working on single pin first? <br />I read something about removing CLI and RETI calls and restoring SReg status, is that right? There is two delays delays on RX, which one should be reduced?<br />I'm sorry, I had no intention to bother you with so many questions, but I really couldn't get it working in non blocking mode using ISR. Maybe it's time to learn something new!<br /><br />Thanks again, Ralph! Dolencehttps://www.blogger.com/profile/14699143405125561266noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-88133271430612146212015-12-10T17:38:12.643-08:002015-12-10T17:38:12.643-08:00Hi Will,
If you review the comments you'll see...Hi Will,<br />If you review the comments you'll see you're not the first to ask about using the receive code in an interrupt. The delay between triggering the interrupt and calling RxByte within the ISR will throw off the timing of the routine. RxByte is intended to be called before the start bit, as it busy-loops waiting for the start bit. Depending on the baud rate and the delay between the start bit and calling RxByte, you could certainly see corruption.<br /><br />Since an interrupt-based receive routine seems to be a popular idea, I've been thinking of writing one. I'll likely do a follow-up post, since in the almost 2 years since I wrote this post, I've improved the bit-bang code and added it to my github repo.<br />https://github.com/nerdralph/nerdralph/tree/master/avr/libs/bbuart<br />This version was written for separate Rx and Tx lines, but could easily be modified for shared tx/rx.<br /><br />I'm also learning inline assembler, and may do an inline asm version of bbuart as well.<br />http://www.nongnu.org/avr-libc/user-manual/inline_asm.html<br />Ralph Doncasterhttps://www.blogger.com/profile/00037504544742962130noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-74087527469914692712015-12-10T09:57:04.475-08:002015-12-10T09:57:04.475-08:00Apparently I'm losing data in the process:
5...Apparently I'm losing data in the process:<br /><br /> 530 <br /><br /> <br /> 0 š ? 607 <br /><br /> <br /> 7 0 › ? 559 <br /><br /> <br /> 9 • š ? 316 <br /><br /> <br /> 6 ™ ? 220 <br /><br /> <br /> 0 ˜ ™ ? 456 <br /><br /> <br /> 6 š š ?Dolencehttps://www.blogger.com/profile/14699143405125561266noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-17105892834570012292015-12-10T06:58:46.982-08:002015-12-10T06:58:46.982-08:00Hi Ralph! How are you?
I'm trying to senda dat...Hi Ralph! How are you?<br />I'm trying to senda data between two micros (atmega328 <-> attiny85) using same pin. I pulled up TX/RX line and have one ISR on each microcontroller for RX. Before sending data to line I disable interrupts because I don't want micro to receive own data being transmited.<br />So far, so good... But it's not working as expected. After tiny send his packet to mega, mega send some data back and then I can't send data anymore. I don't know if I had to change something in BasicSerial.S and .h <br /><br />Could you kindly help me please? Thanks in advance, happy holydays!<br /><br />http://pastie.org/10623141Dolencehttps://www.blogger.com/profile/14699143405125561266noreply@blogger.comtag:blogger.com,1999:blog-6245413346375218188.post-90713534880338687732015-09-06T09:13:57.998-07:002015-09-06T09:13:57.998-07:00Thank you very much.Thank you very much.JB_AUhttps://www.blogger.com/profile/09946483270252331706noreply@blogger.com