Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

SEROUT and SERIN

2007-06-03 by briangregory82

First I want to thank everyone for their help with the software SPI, I
managed to interface with the HM55B compass successfully. For that
solution, I ended up just writing shiftin/shiftout routines. If anyone
wants to see my code it is here:
http://docwiki.gumstix.org/Robostix_and_HM55B_Compass

I now am trying to interface with the following I/R distance sensor:
http://www.hvwtech.com/products_view.asp?ProductID=91

It has a synchronous protocol that I've already bit-banged in similar
fashion to the compass. This works ok, but I'd like to try and get the
asynchronous protocol working. Essentially the sensor will
continuously send out a sync pattern byte (10101010) and then the
reading byte. The example is written in pbasic and essentially
performs a SERIN at 4800 bps with a wait on the sync pattern.

My question is this: Is there example code out there for a C
implementation of SERIN and SEROUT? I see these "bit-bang" functions
all over the place in pbasic examples and would like a C equivalent.

SERIN: As a guess I would think I could start polling the pin for the
first low-high transition and then spin (according to my processor's
clock) for the appropriate time for the specified baud (4800). In this
fashion I could start looking for the sync pattern, restarting my
search if the pattern is incomplete. I would probably need to find the
pattern twice (with a byte between) before I could be certain I've
found it. Then I can just read the next eight bits. 

SEROUT: This would be the easy part, since I can just push out my bits
based upon the baud timing. If there needs to be a sync pattern, then
I just send it first.

In each case, I would need to account for MSB or LSB.

Any thoughts from the group? Thanks in advance...

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.