Serout WORD variable ???
How can I program my SX28 to output a WORD variable serially?· I believe·I have the SERIN side working, since, when from a terminal program, I send a "channel" to sample, I have successfully made the SX display the channel I've sent, since the channel value is 0-11, "byte territory" all works or at least appears to work correctly.· as you can see... I'm still working on my TLC2543 project, and would like to output serially the WORD variable "result", to a BS2p.· I've tried and mostly hacked all examples that I've found on the web but to no avail....· Is there a way to SEROUT what you see in the WATCH directive???· Below is a copy of code I've tried in the TX_BYTE subroutine....
I even tried to output words within "quotation marks" as was shown in the RFID SX/B example, and the literals within quotes displayed correctly, yet when I replaced the literal within quotes with my variable... 'result'... without quotes... the display from the terminal program didn't give me what I saw in the debug window of SX/B...
I plan on·"replacing" the terminal with the BS2p,·but since I can't get·this to work with the terminal I'm stuck·and really need some help...Rob
' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- sclk VAR RC.7 ' clock out from SX/28 to AD2543 sdo VAR RC.6 ' data out from SX/28 to AD2543 sdi sdi VAR RC.5 ' data in from AD2543 sdo to SX/28 ADcs VAR RC.4 ' AD2543 chip select, active low Sin VAR RA.1 ' pull-up via 4.7k Sout VAR RA.0 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Baud CON "T9600" ' open for single wire ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- serbyte VAR Byte ' serial IO byte ADch VAR Word ' selects AD external channel 0-10 result VAR Word temp1 VAR Byte temp2 VAR Byte temp3 VAR Byte tmpW1 VAR Word ' ------------------------------------------------------------------------- ' Watch Directives ' ------------------------------------------------------------------------- WATCH result,13,UDEC ' display 12-bit result variable, value in millivolts ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- TX_BYTE SUB 1,2 ' transmit byte to BS2p serial interface RX_BYTE SUB ' receive byte from BS2p serial interface ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: HIGH ADcs ' make CS output LOW sclk ' make clock 0-1-0 LOW ADcs ' select TLC2543 ADch=$b ' make dummy conversion to intialize converter GOSUB ADread Get_Channel_Voltage: ' get data from specified ADC channel serbyte=RX_BYTE ADch=serbyte GOSUB ADread ' get millivolt data from channel specified BREAK() ' update result variable in watch window TX_BYTE result GOTO Get_Channel_Voltage END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ADread: LOW ADcs ADch=ADch<<8 SHIFTOUT sdo,sclk,MSBFIRST,ADch\12 ' mode, left justify ADch SHIFTIN sdi,sclk,MSBPRE,result_MSB\4 ' get result, 12 bits SHIFTIN sdi,sclk,MSBPRE,result_LSB HIGH ADcs ' deselect chip tmpW1=result**14464 ' convert count to millivolts result=result+tmpW1 RETURN RX_BYTE: SERIN Sin,Baud,temp1 ' receive a byte RETURN temp1 ' return to caller TX_BYTE: temp1=__PARAM1 ' save byte IF __PARAMCNT=1 THEN ' if no count temp2=1 ' set to 1 ELSE temp2=__PARAM2 ' get count IF temp2=0 THEN ' do not allow 0 temp2=1 ENDIF ENDIF DO WHILE temp2>0 ' loop through count SEROUT Sout,Baud,temp1 ' send the byte DEC temp2 ' decrement count LOOP RETURN
I even tried to output words within "quotation marks" as was shown in the RFID SX/B example, and the literals within quotes displayed correctly, yet when I replaced the literal within quotes with my variable... 'result'... without quotes... the display from the terminal program didn't give me what I saw in the debug window of SX/B...
TX_BYTE: Use: LCD_OUT [noparse][[/noparse] aByte | string | label ] ' -- "aByte" is single-byte constant or variable ' -- "string" is an embedded literal string ' -- "label" is DATA statement label for stored z-String temp1 = __PARAM1 ' byte or string offset IF __PARAMCNT = 2 THEN ' string specified? temp2 = __PARAM2 ' yes, save base DO READ temp2 + temp1, temp3 ' read a character IF temp3 = 0 THEN EXIT ' if 0, string complete SEROUT Sout, Baud, temp3 ' send the byte INC temp1 ' point to next character temp2 = temp2 + Z ' update base on overflow LOOP ELSE SEROUT Sout, Baud, temp1 ' send the byte ENDIF RETURN
I plan on·"replacing" the terminal with the BS2p,·but since I can't get·this to work with the terminal I'm stuck·and really need some help...Rob
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
As Chris pointed out, you will need to call TX_Byte twice since a byte is expected for serial transmission and you want to transmit the double-byte value that is held in a word variable.
Something like the following should work:
The "__MSB" and "__LSB" suffixes are automatic aliases SX/B creates for word variables so that the individual bytes that comprise the variable can be addressed separately. Pretty cool, eh?
As Chris also noted, you may need to switch the order of the statements if your BS2 is expecting the Least Significant Byte to be sent first.
Also, depending upon the capabilities of the terminal program you are using, you may not be able to visually recognize the correct values. Your terminal program will likely attempt to display each byte as a character or interpret it as a control code of some kind.
- Sparks