Problem interfacing ADXL202 and Accustar Clinometer with 16F876A


Closed Thread
Results 1 to 12 of 12
  1. #1
    Beatrix's Avatar
    Beatrix Guest

    Default Problem interfacing ADXL202 and Accustar Clinometer with 16F876A

    Hi,

    I'm a student learning my way around PICBasic Pro (using a copy
    licensed to my school), and I'm having some problems accessing data
    via HyperTerminal. Specifically I'm trying to read data from two
    AXDL202 accelerometers and one MSI Sensors Accustar Serial Clinometer
    being sent to a PIC16F876A. The three sensors send information to one
    876A, which transmits the data serially via RF to another 876A, which
    I would like to read via Hyperterminal. Unfortunately though, when I
    connect to HyperTerminal, I'm not receiving any data, and I have
    tested my RF so I know that it is working properly. In addition, I'm
    using pins C6 and C7 to connect to the RS232 connectior without a MAX
    chip since I seem to recall reading somewhere that those pins can be
    used as an internal RS232 buffer to switch the voltage logic.

    My code is as follows (I didn't include the initials/variable sections for brevity sake):

    First 876A)

    accelmeasX1:
    pulse_a1x_T2 = 0 'find T2
    pulsin xout_a1, 1, pulse_a1x_t1
    pulsin xout_a1, 0, temp_x1
    pulse_a1x_t2 = pulse_a1x_t2 + temp_x1
    pulse_a1x_t2 = pulse_a1x_t2 + pulse_a1x_t1
    pulse_a1x_t2 = pulse_a1x_t2 / 10

    pulsin xout_a1, 1, pulse_a1x_t1 'read T1

    accel1x = (pulse_a1x_t1 / pulse_a1x_t2)
    accel1x = accel1x - half_duty
    accel1x = accel1x / duty_div
    pause 10
    goto accelmeasx1

    accelmeasY1:
    pulse_a1y_T2 = 0 'find T2
    pulsin yout_a1, 1, pulse_a1y_t1
    pulsin yout_a1, 0, temp_y1
    pulse_a1y_t2 = pulse_a1y_t2 + temp_y1
    pulse_a1y_t2 = pulse_a1y_t2 + pulse_a1y_t1
    pulse_a1y_t2 = pulse_a1y_t2 / 10

    pulsin yout_a1, 1, pulse_a1y_t1 'read T1

    accel1y = (pulse_a1y_t1 / pulse_a1y_t2)
    accel1y = accel1y - half_duty
    accel1y = accel1y / duty_div
    pause 15
    goto accelmeasy1

    accelmeasX2:
    pulse_a2x_T2 = 0 'find T2
    pulsin xout_a2, 1, pulse_a2x_t1
    pulsin xout_a2, 0, temp_x2
    pulse_a2x_t2 = pulse_a2x_t2 + temp_x2
    pulse_a2x_t2 = pulse_a2x_t2 + pulse_a2x_t1
    pulse_a2x_t2 = pulse_a2x_t2 / 10

    pulsin xout_a2, 1, pulse_a2x_t1 'read T1

    accel2x = (pulse_a2x_t1 / pulse_a2x_t2)
    accel2x = accel2x - half_duty
    accel2x = accel2x / duty_div
    pause 20
    goto accelmeasx2

    accelmeasY2:
    pulse_a2y_T2 = 0 'find T2
    pulsin yout_a2, 1, pulse_a2y_t1
    pulsin yout_a2, 0, temp_y2
    pulse_a2y_t2 = pulse_a2y_t2 + temp_y2
    pulse_a2y_t2 = pulse_a2y_t2 + pulse_a2y_t1
    pulse_a2y_t2 = pulse_a2y_t2 / 10

    pulsin yout_a2, 1, pulse_a2y_t1 'read T1

    accel2y = (pulse_a2y_t1 / pulse_a2y_t2)
    accel2y = accel2y - half_duty
    accel2y = accel2y / duty_div
    pause 25
    goto accelmeasy2


    'for tilt #1
    init_clin1:
    Low TiltReady1
    low TiltReq1
    If TiltReady1 = 1 then
    goto req_clin1
    else
    goto init_clin1
    endif
    pause 25

    req_clin1:
    'while cnt < 17

    high TiltReq1
    if TiltReady1 = 1 then
    goto clin1_prep
    else
    goto req_clin1
    endif

    clin1_prep:
    if TiltReady1 = 0 then
    goto clin1_work
    else
    goto clin1_prep
    endif

    clin1_work:
    If tiltReady1 = 0 then
    tiltreq1 = 0
    else
    if tiltready1 = 1 then
    goto clin1_data
    else
    goto clin1_work
    endif
    endif

    clin1_data:
    high Tiltready1
    goto clin1_send

    clin1_send:
    if tiltready1 = 1 then
    Tiltdata1 = clin_data1
    goto req_clin1
    endif
    ' cnt = cnt + 1
    'wend
    goto init_clin1

    'for tilt #2
    init_clin2:
    Low TiltReady2
    low TiltReq2
    If TiltReady2 = 1 then
    goto req_clin2
    else
    goto init_clin2
    endif
    pause 25

    req_clin2:
    'while cnt2 = 17

    high TiltReq2
    if TiltReady2 = 1 then
    goto clin2_prep
    else
    goto req_clin2
    endif

    clin2_prep:
    if TiltReady2 = 0 then
    goto clin2_work
    else
    goto clin2_prep
    endif

    clin2_work:
    If tiltReady2 = 0 then
    tiltreq2 = 0
    else
    if tiltready2 = 1 then
    goto clin2_data
    else
    goto clin2_work
    endif
    endif

    clin2_data:
    high Tiltready2
    goto clin2_send

    clin2_send:
    if tiltready2 = 1 then
    Tiltdata2 = clin_data2
    goto req_clin2
    endif
    ' cnt2 = cnt2 + 1
    ' wend
    goto init_clin2

    btnclk:
    'for buttons
    Clk_str1 = 0
    clk_str2 = 0

    if click1 = 1 then
    clk_str1 = 1
    else
    clk_str1 = 0
    endif

    if click2 = 1 then
    clk_str2 = 1
    else
    clk_str2 = 0
    endif
    goto btnclk

    Send_Data:
    'for sending to tx
    serout porta.0, n9600, ["ATJHSD"]
    serout porta.0, n9600, [accel1x]
    pause 5
    serout porta.0, n9600, ["BSDFGF"]
    serout porta.0, n9600, [accel1y]
    pause 5
    serout porta.0, n9600, ["CTERT"]
    serout porta.0, n9600, [accel2x]
    pause 5
    serout porta.0, n9600, ["DDFGHT"]
    serout porta.0, n9600, [accel2y]
    pause 5
    serout porta.0, n9600, ["EVBNRG"]
    serout porta.0, n9600, [clin_data1]
    pause 5
    serout porta.0, n9600, ["FPOEQUY"]
    serout porta.0, n9600, [clin_data2]
    pause 5
    serout porta.0, n9600, ["GGHBDG"]
    serout porta.0, n9600, [clk_str1]
    pause 5
    serout porta.0, n9600, ["HDFYEB"]
    serout porta.0, n9600, [clk_str2]
    pause 5
    goto send_data

    end


    Second 876A)

    incoming:
    serin portb.0, n9600, 1000, ser_error, ["ATJHSD"], Accel1x
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["BSDFGF"], Accel1y
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["CTERT"], Accel2x
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["DDFGHT"], Accel2y
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["EVBNRG"], Clin_data1
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["FPOEQUY"], Clin_data2
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["GGHBDG"], Clk_str1
    pause 5
    serin portb.0, n9600, 1000, ser_error, ["HDFYEB"], Clk_str2
    pause 5

    ser_error:
    pause 1000
    goto incoming

    calc_accel1: 'using pyth triangle
    Accel1x = Accel1x * accel1x
    accel1y = accel1y * accel1y
    accel_1 = accel1x + accel1y
    accel_1 = sqr(accel_1)

    calc_accel2: 'using pyth triangle
    accel2x = accel2x * accel2x
    accel2y = accel2y * accel2y
    accel_2 = accel2x + accel2y
    accel_2 = sqr(accel_2)

    calc_pos1: 'x=(1/2)at^2
    time = 5
    time = time * time
    half = 1 / 2
    pos1 = half * Accel_1
    pos1 = pos1 * time

    'if pos > ? then



    calc_pos2:
    time = 5
    time = time * time
    pos2 = half * Accel_2
    pos2 = pos2 * time


    send_data:
    serout portc.7, n9600, ["M"]
    serout portc.7, n9600, [Accel_1]
    pause 5
    serout portc.7, n9600, [Accel_2]
    pause 5
    serout portc.7, n9600, [Clin_data1]
    pause 5
    serout portc.7, n9600, [clin_data2]
    pause 5
    serout portc.7, n9600, [pos1]
    pause 5
    serout portc.7, n9600, [pos2]
    pause 5
    goto send_data

    end



    As I said, I'm still learning PBP, so I'm sure that my problem of not
    reading any data in HyperTerminal could very well be a gross error
    I'm making (I'm using Hellebuyck's PIC Microcontrollers book as a reference). I
    was hoping that someone here could point me in the right direction
    please? Sorry if this is a simple problem, but I just can't seem to
    figure it out.

    Thanks!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As you use MAX ic, you don't need to use N9600... use T9600 instead

    But that will not solve your problem with Hyperterminal. There's for sure a way to make that software work but i never spend the time to work with. I prefer to use MicroCode Studio to edit my code and use the Serial Communicator window. It's so easy to use.

    you download the free version of MicroCode Studio here

    more info
    here
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Beatrix's Avatar
    Beatrix Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, I'll try Microcode Studio later when I'm able to. Oh, and I'm NOT using the MAX IC, so I think I need to use N9600....right?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You're right. With a resistor in serie that will work.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Beatrix's Avatar
    Beatrix Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    You're right. With a resistor in serie that will work.
    Hmm..that might be part of my problem. Right now I have pin C6 connected to pin 3 of the RS232 connector and pin C7 connected to pin 2 directly (no resistor in series). What resistor would you recomend? That and would I need to use any of the other pins on the RS232 connector (request to send, etc) if just reading trhe data via HyperTerminal or Microsode Studio?

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Beatrix
    Hmm..that might be part of my problem. Right now I have
    pin C6 connected to pin 3 of the RS232 connector and
    pin C7 connected to pin 2 directly (no resistor in series). What resistor would you recomend?
    That and would I need to use any of the other pins on the RS232 connector (request to send, etc) if just reading trhe data via HyperTerminal or Microsode Studio?
    Beatrix,

    On the second PIC (I guess that's the one to transfer data to the PC) you are using PortB.0 with SERIN
    I assume that's the incomming Data from the first PIC.

    And you are using PortC.7 with SEROUT
    I assume that's the outgoing Data to the PC.
    A series resistor is not really required on the PC's RX-Pin.
    (But 1k wouldn't hinder either)

    Since the PIC does not receive any Data from the PC
    you don't need a connection between PortC.6 and Pin3 on the RS232.
    If you want to connect it you should have a series resistor (say 22k).

    All you actually need are two wires:
    PortC.7 to RS232 Pin 2
    and
    PIC GND (Vss) to RS232 Pin 5

    Is it probably the missing GND that is causing the Problem?

    Set the Handshake in Hyperterm to "NONE"

    Simple test of your PCs serial Port:
    With nothing connected to the RS232
    In Hyperterm set "Local Echo" to "OFF"
    when type on your keyboard there should nothing appear on your screen.

    Now connect Pin 2 and Pin 3 on the RS232
    every character typed should be echoed back on the screen.
    Last edited by NavMicroSystems; - 4th July 2005 at 15:18.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  7. #7
    Beatrix's Avatar
    Beatrix Guest


    Did you find this post helpful? Yes | No

    Default

    Regarding the connection to ground: currently I have both of the Vss pins connected to board ground. For this connection to RS232 ground, should I simply solder in a wire, thereby having Vss connected to board ground and RS232 ground, or should I disconnect it from board ground and only connect it to RS232 ground?

  8. #8
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Beatrix
    ...having Vss connected to board ground and RS232 ground...
    That's the way it should be.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  9. #9
    Beatrix's Avatar
    Beatrix Guest


    Did you find this post helpful? Yes | No

    Default



    I tried it again with the ground wire in place and no more receive wire using both Microcode Studio and HyperTerminal, and it still doesn't work. Is there anything I should be doing with the other pins on the RS232 connector? Any ideas?

  10. #10
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Beatrix,

    have you tried the simple test described here

    Have you set the Baudrate on the PC-side correctly
    and is "Handshake" set to none?

    Could you post a schematic and your code (cut down to the RS232 part)

    For a one-way communication (PIC --> PC) you definitely need only two wires:
    PIC-GND to PC-GND and PTC-TX to PC-RX

    Probably your PCs COM-Port doesn't work with TTL-Levels.
    If so you would need to add a MAX232-type of Level shifter.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  11. #11
    Beatrix's Avatar
    Beatrix Guest


    Did you find this post helpful? Yes | No

    Default

    For that test, would I need to use an RS232 keyboard? I didn't run it since I'm pretty sure the port works since I'm also using it to program my PICs. The baudrate and handshake is set on the PC as well.

    I'll probably have to try it with another computer to see if the one I'm using is not compatible and needs the MAX IC. That's going to be a problem since the board had been fabricated and adding the MAX would require me to do a bit of a workaround (which is why I'm trying to get it going without the MAX). Initially, I was planning on using a PS/2 connection to transmit the data to the computer, but I was unable to find enough information on it to the point that I could understand how it works, so I decided to switch to RS232.

  12. #12
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Beatrix
    For that test, would I need to use an RS232 keyboard?
    All you need is a simple piece of wire betwenn Rx and Tx on the PCs RS232

    Quote Originally Posted by Beatrix
    I didn't run it since I'm pretty sure the port works since I'm also using it to program my PICs. The baudrate and handshake is set on the PC as well.
    Well that case I would assume the PCs RS232 isfunctional, but not compatible with the PICs Levels.

    Anyway
    If you want to make sure your Product works with any PC-COM-Port you should add a Levelshifter.

    The PICs (0/+5V) Levels are ways off the specs of a standard COM-Port (+/- 12V)

    And bear in mind: the MAX232 does not only shift the levels, it also inverts the logic.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts