reading in from serial port
hi there, i'm looking to read into the sx28 using a serial port at 9600 baud and store the data as a byte in my program. i'm having problems with the timing - i was trying to read in a bit and then delay for approx. 104us, but it isn't working. is there a better way of doing this? any help would be greatly appreciated. thanks.
Comments
offset your delay for 1/2 of your bit time, in your case this would be 52uS. This way your timing will be placed in the center of each of the remaining bits and you will be less likely to "picket fence" your signal.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe - Mask Designer III
National Semiconductor Corporation
(Communication Interface Division)
500 Pinnacle Court, Suite 525
Mail Stop GA1
Norcross,GA 30071
Bean.
I don't have all of the code on this computer, but the program basically loops until the start bit edge is detected and then calls a function which reads in each bit. I'll try putting a 52uS delay before this process starts. I took the delay from the sample code on this site. It looks like this:
delay
; This function delays for ((W-1)*20us), plus/minus a few ns
mov dlycnt1,W
delay1
decsz dlycnt1
jmp loop1
retp
loop1
mov w,#166
mov dlycnt2,W
loop;
nop
nop
nop
decsz dlycnt2
jmp loop
jmp delay1
Would it make sense to replace the '166' with a '6' for an approx delay of 104uS? It seems a little bit too easy, so I'm skeptical.
Again, thanks for all your help.
or specifically:
http://www.piclist.com/cgi-bin/delay.exe?Delay=.000104&Type=seconds&Regs=d1+d2+d3+d4&clock=50&name=Delay&CPU=SX
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
Bean.
You asked if there is a better way of reading serial data. Yes, don't re-invent the wheel. Just use some pre-existing UART code. Heres'a link:
www.sxlist.com/techref/scenix/lib/io/osi2/serial/rs232_sx.htm
This page is full of UARTs. Furthermore, even if you want to roll your own, take a look at what others have done to get some idea of the good practices for writing your own UART.
Thanks, PeterM