Shop OBEX P1 Docs P2 Docs Learn Events
reading in from serial port — Parallax Forums

reading in from serial port

lackofcolourlackofcolour Posts: 5
edited 2005-01-25 17:53 in General Discussion
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

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2005-01-24 23:48
    Perhaps a snip of your code would be helpful. Don't forget the STOP and START bits that make part of the RS232 signal, so that 10 bits actually make a byte. Look for the START bit as an edge detection, and then
    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
  • BeanBean Posts: 8,129
    edited 2005-01-25 00:04
    If you want you can use SX/B to do it, or just to see what code it generates. That's what it's for.
    Bean.
  • lackofcolourlackofcolour Posts: 5
    edited 2005-01-25 00:22
    Thanks for the help, I'll check out the SX/B.
    Beau Schwabe said...
    Perhaps a snip of your code would be helpful. Don't forget the STOP and START bits that make part of the RS232 signal, so that 10 bits actually make a byte. Look for the START bit as an edge detection, and then
    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.

    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.
  • James NewtonJames Newton Posts: 329
    edited 2005-01-25 00:53
    http://www.sxlist.com/techref/piclist/codegen/delay.htm

    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!



  • lackofcolourlackofcolour Posts: 5
    edited 2005-01-25 12:53
    Cool, thanks for the help. smile.gif
  • BeanBean Posts: 8,129
    edited 2005-01-25 13:50
    What frequency are you running the SX at ?
    Bean.
  • PJMontyPJMonty Posts: 983
    edited 2005-01-25 17:53
    Lackofcolour,

    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
Sign In or Register to comment.