Shop OBEX P1 Docs P2 Docs Learn Events
First Serial Communication Program! :D — Parallax Forums

First Serial Communication Program! :D

tholbertontholberton Posts: 41
edited 2012-06-08 16:23 in Propeller 1
I just finished writing this program in asm for talking to a computer with standard serial board settings - 9600,1n8.
I was pretty excited when I finally saw "1"'s come pouring out of the serial port haha
org 0
serial_interface
mov dira,tx
mov n_data_bits,#8 
waitpeq inp,inp      'wait until send button is pressed


mov outa,tx          'send start bit
mov time_t,cnt
add time_t,delay_t
waitcnt time_t,delay_t


:main_loop           'send data
ror data_t,#1 wc
muxc outa,tx
waitcnt time_t,delay_t
djnz n_data_bits,#:main_loop wz


or outa,tx           'send stop bit
waitcnt time_t,delay_t
xor outa,tx
waitcnt time_t,delay_t


mov n_data_bits,#8   'restart counter and start again
jmp #:main_loop
 
data_t      long $0000_0031
inp         long $0001_0000
tx          long $4000_0000
rx          long $8000_0000
delay_t     long 8333
n_data_bits res 1
time_t      res 1
fit

Any suggestions or comments are welcome

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2012-06-08 12:43
    A couple things that I see ... Your only sending a start bit once. Perhaps the XOR in your stop bit is correcting this. Another thing is that your data variable 'data_t' isn't being restored except after every 4th byte you are sending.

    This may help for a reference:
    http://en.wikipedia.org/wiki/File:Rs232_oscilloscope_trace.svg

    Try something like this...
    DAT
                  org 0
    serial_interface
                  mov       outa,   tx              'preset tx pin HIGH
                  mov       dira,   tx              'make tx pin an OUTPUT
    
                  waitpeq   inp,    inp             'wait until send button is pressed
    
                  mov       time_t, delay_t
                  add       time_t, cnt
    :byte_start
                  mov       temp1,  data_t
                  or        temp1,  #%100000000     'Set Stop Bit
                  shl       temp1,  #1              'Set Start Bit
                  mov       n_data_bits,#10         '8 data bits plus 1 Start and 1 Stop bit 
    :main_loop                                      'send data
                  ror       temp1,  #1 wc
                  muxc      outa,   tx
                  waitcnt   time_t, delay_t
                  djnz      n_data_bits,#:main_loop
                  waitcnt   time_t, delay_t         'idle delay = 1 bit
    
                  jmp       #:byte_start            'restart ; send byte again
     
    data_t        long      $0000_0031
    inp           long      $0001_0000
    tx            long      $4000_0000
    rx            long      $8000_0000
    delay_t       long      8333
    n_data_bits   res       1
    time_t        res       1
    temp1         res       1
    fit
    
  • tholbertontholberton Posts: 41
    edited 2012-06-08 16:12
    Oh, I didn't know the start bit is suppose to be repeated... Or that the stop bit is a logic 0. Thanks!
    I'm aware of the 3 empty bytes. I'm planning on revising this for receiving data from a device.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-06-08 16:23
    I notice you use "xor" to set bit low.

    I think when the desired result is a low bit and not just a change of a bit's state, it makes more sense to use "andn" since it doesn't require the bit start high to end up low.
Sign In or Register to comment.