Shop OBEX P1 Docs P2 Docs Learn Events
Dual UART problems continue — Parallax Forums

Dual UART problems continue

John WhitfieldJohn Whitfield Posts: 42
edited 2005-06-08 01:55 in General Discussion
I rewrote some of the code thinking that the comparison code was going wrong somewhere in the SendDigit function, but the output is very similar. In the code Multi4.src·the SX·is constantly putting out codes to the speakjet for point and negative over and over again. In the modified code Multi5.src the SX is constantly sending out the codes for digits 2-9, point, and negative over and over again. In both cases the Multimeter being on or off, connected or not makes no difference. If anybody can figure out why this is it would really help me a lot.

Thanks,
-John Whitfield

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-04 03:36
    John,

    I changed your code a little.

    My changes have ;PV--comment in front of them.

    Try it and let us know the result.

    regards peter
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-04 04:13
    Cool, now it only outputs the welcome and nothing else which is great. Thank You.

    Does anybody have any ideas on why the program is not reading the data, could it be a timing issue?

    -John Whitfield
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-04 05:16
    In the following section of code, is the output set up for eight data bits and one stop bit? Or is that handle by the earlier code segment of transmit1? If so how can I alter it to make it seven data bits and two stop, as is needed?
    ; This routines sends a string to the DMM - it expects the index into the
    ; string table in w.
    ;
    ; Note: Sets bank to Serial
    ;
    _SendString1
        mov     Temp, w             ; Save index into string table
        bank    Serial
    :WaitTxDone1 
        test    TxCount1            ; Test if transmitter is busy
        sz
        jmp   :WaitTxDone1
        mov     w, #Strings >> 8    ; Copy the upper 4 bits of the
        mov     m, w                ; string table into the lower 4
                                    ; bits of m
        mov     w, Temp             ; Restore the index
        iread                       ; Read one byte indirectly
        test    w                   ; Test for end of string
        snz
        jmp     :out1
        mov     TxHigh1, w          ; Put character into transmit register high
        setb    TxHigh1.7           ; Force bit 7 to high for the 1st stop bit (the
                                    ; 2nd one is automatically sent by the transmitter)
        clr     TxLow1              ; Clear transmit register low for start bit
        mov     w, #10 
        mov     TxCount1, w         ; 1 start, 8 data, 1 stop (this also starts the
                                    ; transmitter)
        inc     Temp                ; Point to next charater in the string table
        jmp     :WaitTxDone1         ; Loop back
    :out1 mov w,#$1F   ; reset the mode register
     mov m,w
    ;PV--use a retp to return to the caller's page, a simple ret may not do
     retp
    

    Thanks,
    -John Whitfield
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-04 05:58
    John,

    The M3850 only samples about 3 times a second (successive DAC), which means you should

    limit datarequests to max. 2 per second, i.e insert a 0.5 sec delay in your mainloop.

    eg.

    MainLoop
    ;PV--wait 0.5sec before another reading

    ··· call·· @delay_0s5

    ··· clr···· !wdt
    ··· call··· @GetString1········· ; Read a data-set from the DMM (sets bank to DMM)

    Also be sure the DMM pins DTR and RTS get the right steady signal (-10V and +10V) but I

    believe you already solved that.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-04 06:15
    John,

    When I tested my M3850 with a terminal program, I had it set to 8N1, which works

    because bit7 is always clear (so 7N2 equals 8N1)

    _SendString1
    ··· mov···· Temp, w············ ; Save index into string table
    ··· bank··· Serial
    :WaitTxDone1
    ··· test··· TxCount1··········· ; Test if transmitter is busy
    ··· sz
    ··· jmp·· :WaitTxDone1
    ··· mov···· w, #Strings >> 8··· ; Copy the upper 4 bits of the
    ··· mov···· m, w··············· ; string table into the lower 4
    ······························· ; bits of m
    ··· mov···· w, Temp············ ; Restore the index
    ··· iread······················ ; Read one byte indirectly
    ··· test··· w·················· ; Test for end of string
    ··· snz
    ··· jmp···· [noparse]:o[/noparse]ut1
    ··· mov···· TxHigh1, w········· ; Put character into transmit register high
    ;PV--now that we can use 8N1 no need to force bit7 high

    ;··· setb··· TxHigh1.7·········· ; Force bit 7 to high for the 1st stop bit (the
    ······························· ; 2nd one is automatically sent by the transmitter)
    ··· clr···· TxLow1············· ; Clear transmit register low for start bit
    ··· mov···· w, #10
    ··· mov···· TxCount1, w········ ; 1 start, 8 data, 1 stop (this also starts the
    ······························· ; transmitter)
    ··· inc···· Temp··············· ; Point to next charater in the string table
    ··· jmp···· :WaitTxDone1········ ; Loop back

    [noparse]:o[/noparse]ut1·mov·w,#$1F···; reset the mode register
    ·mov·m,w
    ;PV--use a retp to return to the caller's page, a simple ret may not do
    ·retp
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-04 19:06
    I inserted the delay and changed the code based upon the above segment, but it still doesn't read in data. I know that the DTR and RTS are right since when I use them at the voltage to go into a terminal program at regular RS232 it works. I really am not sure as to why the code doesn't work, since it seems like it should. Here is the present code, as always, any ideas are welcome.

    Thanks,
    -John Whitfield
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-04 20:00
    John,

    Can you connect the·SX pins that would connect to the DMM, to a pc com port?

    Then check with a terminal program if you receive 'D'. Reset the SX after terminal

    has started up.

    If you don't receive the 'D', the transmit routine is not correct, and the DMM

    does not recognize the 'D'.

    regards peter
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-04 21:12
    I didn't receive it.

    -John
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-04 23:00
    John,
    The end of the delay must be retp!

    _delay_0s5
    Delay:···;delay function
    ···;24999987 cycles
    ·mov·w, #$70
    ·mov·d1, w
    ·mov·w, #$2A
    ·mov·d2, w
    ·mov·w, #$27
    ·mov·d3, w
    Delay_0:
    ·decsz·d1
    ·jmp·$+2
    ·decsz·d2
    ·jmp·$+2
    ·decsz·d3
    ·jmp·Delay_0
    ···;7 cycles
    ·jmp·$+1
    ·jmp·$+1
    ·nop
    ···;6 cycles (including call)
    ·;PV--asimple ret will not do
    ·retp

    You call the delay from another page so a simple ret will not return to the mainloop!
    Hence, the 'D' may not have been transmitted. I believe the transmit1 routine is ok.

    regards peter

    ·
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-05 19:48
    Yeah now I am getting D's sent out to the terminal program, but the program still doesn't pass data across to the speakjet from the output of the multimeter. I don't know if its not getting it in or what. One other small thing is that it sends out a lower case t before it sends out the upper case D's, meaning the terminal output is like this...

    tDDDDDDDDDDDDDDDDDDDDDDDD...

    But it is still not getting input, comparing it, and sending out corresponding codes to the speakjet if anyone can figure this out, then the whole thing should work.

    Thanks,
    -John Whitfield
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-05 20:42
    John,

    I wouldn't be concerned about the first 't', because the DMM ignores it anyway.

    The fact that you get multiple 'D' means you wait and receive the right number

    of bytes from the DMM.

    Try this:

    connect the DMM to the SX as it must be,

    connect the SX output for the speakjet to the PC com port running the terminal program (9600 baud)

    Output the received bytes from the DMM to the speakjet output. then you see the DMM response.

    Main
    ··· jmp···· @_Main·
    GetByte1
    ··· jmp···· @_GetByte1·
    GetString1
    ··· jmp···· @_GetString1
    SendString1
    ··· jmp···· @_SendString1
    SendString2
    ··· jmp···· @_SendString2··
    SendDigit
    ··· jmp···· @_SendDigit
    delay_0s5
    ··· JMP···· @_delay_0s5
    ;PV--add entry to transmit single byte to speakjet

    SendByte2

    ··· JMP··· @_SendByte2

    MainLoop
    ··· call·· @delay_0s5
    ··· clr···· !wdt
    ··· call··· @GetString1········· ; Read a data-set from the DMM (sets bank to DMM)
    ;PV--test DMM input only
    ··· jmp·· Mainloop

    _SendString2
    ··· bank··· Serial
    ··· mov···· Temp, w············ ; Save index into string table
    :WaitTxDone2
    ;
    ; G.D. I'm not sure if this is enough to find out if the SpeakJet is busy
    ;
    ;··· movb· c, RxPin2············ ; get current rx bit
    ;··· test· RxCount2············· ; currently receiving byte?
    ;··· sz
    ;··· jmp·· :WaitTxDone2
    ;
    ; G.D. It is absolutely necessary to wait until the transmitter no longer
    ;····· busy. Otherwise false data will be transmitted.
    ;··· Therefore, I have inserted the instructions here that you have removed
    ;
    ·test·TxCount2
    ·sz
    ·jmp·:WaitTxDone2
    ;
    ··· mov···· w, #Strings>>8··· ; Copy the upper 4 bits of the
    ··· mov···· m, w··············· ; string table into the lower 4
    ······························· ; bits of m
    ··· mov···· w, Temp············ ; Restore the index
    ··· iread······················ ; Read one byte indirectly
    ··· test··· w
    ··· snz
    ··· jmp···· [noparse]:o[/noparse]ut2
    ··· call···· @SendByte2· ;transmit the byte
    ··· inc···· Temp··············· ; Point to next charater in the string table
    ··· jmp···· :WaitTxDone2········ ; Loop back
    [noparse]:o[/noparse]ut2
    ·mov·w,#$1F···; reset the mode register
    ·mov·m,w
    ·retp

    _SendByte2
    ··· bank··· Serial·· ;byte to transmit in w
    :WaitTxDone21
    ··· test·TxCount2· ;does not affect w
    ··· sz
    ··· jmp·:WaitTxDone21
    ··· mov···· TxHigh2, w········· ; Put character into transmit register high
    ··· clr···· TxLow2············· ; Clear transmit register low for start bit
    ··· mov···· w, #10
    ··· mov···· TxCount2, w········ ; 1 start, 8 data, 1 stop (this also starts the
    ······························· ; transmitter)
    ··· retp

    _GetByte1
    ··· bank··· Serial
    ··· sb····· RXAvail1··········· ; Check if the DMM has sent a byte
    ··· jmp···· _GetByte1
    ··· clrb··· RXAvail1··········· ; Clear the flag for the next byte
    ··· mov···· w, RxByte1
    ··· and···· w, #%01111111······ ; Clear the 2nd stop bit
    ····mov··· Temp,w
    ;PV--temporarily redirect DMM input
    ··· call··· @SendByte2·· ;output DMM input to speakjet output
    ··· mov··· w,Temp· ;restore w
    ··· retp

    If you make the little changes above, you should see the DMM response to 'D'.
    As this response consists of 14 letters, digits and spaces, they should be visible
    in the terminal program. If you get garbage in the terminal, then the DMM receive
    is incorrect because you know the speakjet transmit is working.

    regards peter



    ·
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-07 03:38
    Hey everybody thanks a lot for your help. Your last message made me realize through an exhaustive brute force method that the speakjet operates at TTL voltages and that I needed to run the multimeter through the max233 the other way. With a little tweeking of the delay it should work properly, since it sounds like it doesn't delay long enough. So, the last code I posted with the alterations made above should allow anyone to make a talking multimeter using the SX, a MAX233, a speakjet chip, and a METEX multimeter.

    Thanks,
    -John Whitfield
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-07 05:02
    I wanted to be sure there was no confusion and that stuff contained in the message right above the last one does not need to be changed in the code. Just to avoid confusion I will upload the working file, and if any one says they are interested I will upload the final code after I work out the last few bugs.

    Thanks Again,

    -John Whitfield
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-06-07 05:47
    Please do, John.

    You can post the final code and schematics here or in the Projects forum.

    regards peter
  • John WhitfieldJohn Whitfield Posts: 42
    edited 2005-06-08 01:55
    Here is a slightly improved version of the code.

    -John Whitfield
Sign In or Register to comment.