Dual UART problems continue
John Whitfield
Posts: 42
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
Thanks,
-John Whitfield
Comments
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
Does anybody have any ideas on why the program is not reading the data, could it be a timing issue?
-John Whitfield
Thanks,
-John Whitfield
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
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
Thanks,
-John Whitfield
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
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
·
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
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
·
Thanks,
-John Whitfield
Thanks Again,
-John Whitfield
You can post the final code and schematics here or in the Projects forum.
regards peter
-John Whitfield