SX10502/SX10502RH: Programming
The SX10502 and SX10502RH have up to 4 temperature/humidity measuring functions depending on the model and whether or not there is an optional TN9301 peripheral board attached. Each of these functions is returned as a floating-point number. If it is a temperature function, the returned value will be in degrees Celsius. If it is humidity the returned value will be a percentage.
The remote target temperature and the ambient temperature from the TN9301 is updated at a rate of 1.4Hz. The on board temperature and humidity is updated at a rate of 2Hz.
Because the SX10502 has 2 model variations and can be used with or without an optional TN9301 sensor, the programmer is required to enable/disable selected functions of the SX10502.
By setting the Xwire Transmit Data length to 0 Bytes the Control Byte is disabled and ALL measurement functions will be enabled by default.
By setting the Xwire Transmit Data length to 1 Byte the Control Byte is enabled.
If the Control Byte is set to a number between 0-15 certain functions will be enabled.
If the TN9301 or on board sensor is removed from the SX10502 or damaged an error value of NaN is returned from the SX10502 for the affected function.
The following table depicts what functions will be enabled depending on the contents of the Control Byte, and the number of bytes needed for the Receive Data length. The relative location of the data returned from the functions inside the Xwire Receive Data block is also shown.
| Xwire Receive Data block relative byte addresses | |||||
|---|---|---|---|---|---|
| Control Byte | 0 1 2 3 | 4 5 6 7 | 8 9 10 11 | 12 13 14 15 | Receive Data length |
| 0 | TN9301 Object Temperature | TN9301 Ambient Temperature | On board Temperature | On board Humidity | 16 |
| 1 | TN9301 Object Temperature | 4 | |||
| 2 | TN9301 Ambient Temperature | 4 | |||
| 3 | TN9301 Object Temperature | TN9301 Ambient Temperature | 8 | ||
| 4 | On board Temperature | 4 | |||
| 5 | TN9301 Object Temperature | On board Temperature | 8 | ||
| 6 | TN9301 Ambient Temperature | On board Temperature | 8 | ||
| 7 | TN9301 Object Temperature | TN9301 Ambient Temperature | On board Temperature | 12 | |
| 8 | On board Humidity | 4 | |||
| 9 | TN9301 Object Temperature | On board Humidity | 8 | ||
| 10 | TN9301 Ambient Temperature | On board Humidity | 8 | ||
| 11 | TN9301 Object Temperature | TN9301 Ambient Temperature | On board Humidity | 12 | |
| 12 | On board Temperature | On board Humidity | 8 | ||
| 13 | TN9301 Object Temperature | On board Temperature | On board Humidity | 12 | |
| 14 | TN9301 Ambient Temperature | On board Temperature | On board Humidity | 12 | |
| 15 | TN9301 Object Temperature | TN9301 Ambient Temperature | On board Temperature | On board Humidity | 16 |
*Note that this data block does not need to start at memory location 0 and can be moved anywhere in memory as long as it stays together, is in the order above and is defined in the NVEM Xwire table in the program code.
Example Program 1
* Example program demonstrating how to interface with a SX10502 *
* For use with MMI202 and SX10502 *
* 2x16 LCD *
** Setup **
* The SX10502 is interfaced to the MMI202 over X-Wire protocol by setting the communications jumper to
* the X position.
* No board ID jumpers are installed as the X-Wire slave address for the SX10502 is address 0.
* If it is a MMI202 the X-Wire cable is connected from the Spice connector to the X1 connector on the SX10502.
* If it is a MMI202a the X-Wire cable is connected from the CN12 connector to the X1 connector on the SX10502.
** Program operation **
* X-Wire is set up to return data to the MMI from both temperature functions on the TN9301.
* Temperature from the TN9301 peripheral board are continually updated on the display.
* If at any time there are Xwire communications errors the front panel LED on output 15 will light.
* Equates *
* XWire Receive data block *
* Data block of 16 bytes *
RxRAMstart: equ 100 ;the starting memory location of the Xwire receive data block
RxRAMlength: equ 8 ;the size of the returned data in bytes depending on what functions are enabled
fTN9Temp: mequ 100,4 ;Location where the TN9301 object temperature is returned.
fTN9Amb: mequ 104,4 ;Location where the TN9301 ambient temperature is returned.
* XWire Transmit data block *
* Data block of 1 byte *
TxRAMlength: equ 1 ;setting the Transmit Ram length to 1 enables the control byte. 0 disables it.
bControlByte: mequ 10 ;location of the control byte to enable/disable SX10502 functions
SlaveAddress equ 0 ;the XWire slave address.
* Output Equates *
oXW_XWireError: oequ 15 ;LED turns on when there is an Xwire communication error.
*******************
** Program start **
*******************
Start
XwireMaster XWireTab ;start xwire going
setmem bControlByte,3 ;set the control byte to 3 to enable both TN9301 temperature functions.
launchtask LCD_Task ;start the Display task running
launchtask Xwire_Task ;start the XWire error checking task running
runtasksforever
******************
** Display Task **
******************
LCD_Task:
oblcd_CLS
oblcd_Type 2 ;set LCD to 2x16 type
LCD0:
pause 50 ;Update the display every 500mS
oblcd_setcur 0,0
; "0123456789012345"
oblcd_text "TN9 Temp: "
frecallw fTN9Temp
oblcd_fdispw 4,1 ;display the TN9301 object temperature with 1 decimal place
oblcd_spclchar 223 ;display a degree sign
oblcd_text "C"
; "0123456789012345"
oblcd_setcur 1,0
oblcd_text "TN9 Amb: "
frecallw fTN9Amb
oblcd_fdispw 4,1 ;display the TN9301 ambient temperature with 1 decimal place
oblcd_spclchar 223 ;display a degree sign
oblcd_text "C"
goto LCD0
****************************
** Xwire Error Check Task **
****************************
Xwire_Task:
XW0:
yieldtask
xwiregeterrcount ;get the xwire error count
goiff XW1
on oXW_XWireError ;turn on error LED if there are XWire errors
pause 1
goto XW0
XW1: off oXW_XWireError
goto XW0
** X-Wire Master table **
NVEM0
XWireTab:
NV0Byte SlaveAddress,bControlByte,TxRAMlength,RxRAMstart,RxRAMlength
NV0Byte 255 ;End of table sentinel. ;memory 10 (bControlByte) is transmit data block, 100 (RxRAMstart) is receive data block.
;TxRAMlength of 1 byte enables bControlByte
;RxRAMlength of 8 bytes for 2 floating point returned numbers.
Example Program 2
* Example program demonstrating how to interface with a SX10502RH *
* For use with MMI202 and SX10502RH *
* 2x16 LCD *
** Setup **
* The SX10502RH is interfaced to the MMI202 over X-Wire protocol by setting the communications jumper to
* the X position.
* No board ID jumpers are installed as the X-Wire slave address for the SX10502RH is address 0.
* If it is a MMI202 the X-Wire cable is connected from the Spice connector to the X1 connector on the SX10502RH.
* If it is a MMI202a the X-Wire cable is connected from the CN12 connector to the X1 connector on the SX10502RH.
** Program operation **
* X-Wire is set up to return data to the MMI from both temperature functions on the TN9301 and
* the on board temperature and humidity.
* Temperature and humidity from the on board sensor are continually updated on the display.
* Pressing front panel button IN8 advances to the next screen.
* Temperature from the TN9301 peripheral board are continually updated on the display.
* If at any time there are Xwire communications errors the front panel LED on output 15 will light.
* Equates *
* XWire receive data block *
* Data block of 16 bytes *
RxRAMstart: equ 100 ;the starting memory location of the Xwire receive data block
RxRAMlength: equ 16 ;the size of the returned data in bytes depending on what functions are enabled
fTN9Temp: mequ 100,4 ;Location where the TN9301 object temperature is returned.
fTN9Amb: mequ 104,4 ;Location where the TN9301 ambient temperature is returned.
fOBTemp: mequ 108,4 ;Location where the on board temperature from the SX10502RH is returned.
fOBHumid: mequ 112,4 ;Location where the on board humidity from the SX10502RH is returned.
* XWire Transmit data block *
* Data block of 1 byte *
TxRAMlength: equ 1 ;setting the Transmit Ram length to 1 enables the control byte. 0 disables it.
bControlByte: mequ 10 ;location of the control byte to enable/disable SX10502RH functions
SlaveAddress equ 0 ;the XWire slave address.
* Output Equates *
oXW_XWireError: oequ 15 ;LED turns on when there is an Xwire communication error.
*******************
** Program start **
*******************
Start
XwireMaster XWireTab ;start xwire going
setmem bControlByte,15 ;set he control byte to 15 to enable all SX10502RH measurement functions
launchtask LCD_Task ;start the Display task running
launchtask Xwire_Task ;start the XWire error checking task running
runtasksforever
******************
** Display Task **
******************
* Input equates *
iLCD_Cycle: iequ 8 ;this input is used to cycle the data on the LCD
LCD_Task:
oblcd_CLS
oblcd_Type 2 ;set LCD to 2x16 type
LCD0:
pause 50
goifink iLCD_Cycle,LCD1 ;if toggle button is pressed change LCD display
oblcd_setcur 0,0
; "0123456789012345"
oblcd_text "OB Temp: "
frecallw fOBTemp
oblcd_fdispw 4,1 ;display the on board temperature with 1 decimal place
oblcd_spclchar 223 ;display a degree sign
oblcd_text "C"
; "0123456789012345"
oblcd_setcur 1,0
oblcd_text "OB Humid: "
frecallw fOBHumid
oblcd_fdispw 4,1 ;display the on board humidity with 1 decimal place
oblcd_text " %"
goto LCD0
LCD1:
pause 50
goifink iLCD_Cycle,LCD0 ;if toggle button is pressed change LCD display
oblcd_setcur 0,0
; "0123456789012345"
oblcd_text "TN9 Temp: "
frecallw fTN9Temp
oblcd_fdispw 4,1 ;display the TN9301 object temperature with 1 decimal place
oblcd_spclchar 223 ;display a degree sign
oblcd_text "C"
; "0123456789012345"
oblcd_setcur 1,0
oblcd_text "TN9 Amb: "
frecallw fTN9Amb
oblcd_fdispw 4,1 ;display the TN9301 ambient temperature with 1 decimal place
oblcd_spclchar 223 ;display a degree sign
oblcd_text "C"
goto LCD1
****************************
** Xwire Error Check Task **
****************************
Xwire_Task:
XW0:
yieldtask
xwiregeterrcount ;get the xwire error count
goiff XW1
on oXW_XWireError ;turn on error LED if there are XWire errors
pause 1
goto XW0
XW1: off oXW_XWireError
goto XW0
** X-Wire Master table **
NVEM0
XWireTab:
NV0Byte SlaveAddress,bControlByte,TxRAMlength,RxRAMstart,RxRAMlength
NV0Byte 255 ;End of table sentinel. ;memory 10 (bControlByte) is transmit data block, 100 (RxRAMstart) is receive data block.
;TxRAMlength of 1 byte enables bControlByte
;RxRAMlength of 16 bytes for 4 floating point returned numbers.