I think there are 2 real advantages of HSERIN/OUT over the software SERIN/OUT. The first being speed. Due to the overhead involved in timing the signal in software, SERIN/OUT is limited to about 50kbaud, whereas HSER can manage a whopping 1250kbaud. That's 1.25 megabits per second. If you want to be a Top-Gun and have the "Need for Speed", it's the only way you'll get it.
But for me, the biggest advantage of HSERIN/OUT is the ability to withstand interrupts without affecting the timing of the serial data. With SERIN/OUT you'll be lucky to get over 9600 baud without even the quickest interrupts creating havoc with the data. But with HSER, as long as the interrupt takes less that 2 full "Byte periods", everything just cruises right along.
Add on the ability to respond to specific Addresses on an RS485 bus, and detecting framing errors if the signal gets a bit noisy, I think HSER comes up the Winner every time.
Hmmm, "hinky things to beware of".
Oh, wait a minute, that's Hanky.
Well, the only problem I've had with HSER, were unchecked buffer overflows, which can cause the entire program to just stop running. And while it's possible to automatically clear the errors with ...
DEFINE HSER_CLROERR 1
It doesn't give you any indication that an error occurred. So you have to be careful with the design of your program. Or resort to reading 1 byte at a time, so that you can check for errors manually before using the HSERIN. And preferably use some form error checking with the use of checksums or something similar if the data absolutely positively MUST be accurate.
But compared with SERIN which has no error checking at all, HSER still Wins.
Oh yeah, one more thing. SERIN has a bit of a problem when the signal idles at the opposite state that it's expected to. For instance, with TRUE rs232, the idle state should be HIGH. If a cable is disconnected or for any other reason the signal idles LOW, SERIN will just sit there. Even if there's a timeout declared in the statement, the whole program freezes. HSER will timeout (if a timeout is declared).
Bookmarks