Hitt Data Logger & SX/B
![John Kauffman](https://forums.parallax.com/uploads/userpics/555/nZBNEPT0B6FMD.jpg)
I just did a search of fora and could not find sample code for SX/B to run Hitt Data Logger.
Bean? Anyone else using the data logger wtih SX/B?
(Works brilliant on BS2 using code in manual available on Bean's website)
Overall goal is to store several thousand records of ADC data with time stamps from DS1302.
Thanks.
·
Bean? Anyone else using the data logger wtih SX/B?
(Works brilliant on BS2 using code in manual available on Bean's website)
Overall goal is to store several thousand records of ADC data with time stamps from DS1302.
Thanks.
·
Comments
I don't think I have any SX/B code. It would basically be a direct translation from the BS2 demos.
I will do convert some of the demos as soon as I get some free time.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Q1 - baud
In SX/B, what is the Baud setting for the SEROUT commands?
I'm not sure how to translate the logger's datasheet "8N1" into the SXB Baud "N,T,OT,ON"
I'm using SX28 with murata 400C resonator and OSCXT1
Data Logger jumper is ON (but I can change)
Q2 - SXB serout of three-character control codes
BS is SEROUT SPin, Baud, [noparse][[/noparse]"!CF"] ' Close File
in SX/B will I have to do three SEROUT commands. one for each character?
SEROUT RA.0, baud, "!"
SEROUT RA.0, baud, "C"
SEROUT RA.0,baud, "F"
It assembles, but when run never turns on the active light of the logger.
I suspect the SEROUT baud parameter is wrong.
'
Program Description
' Hitt Data Logger in SX/B
' Attempt #2 - not there yet
' lines start with 'BS2' are artifacts of conversion
' SERIN of results will probably not be used
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "" 'eight characters max
'
IO Pins
SPin PIN RA.0
'
Constants
Open CON $8000
'BS2'Baud CON T2400
NO_ERROR CON 0
'
Variables
counter VAR Word
value VAR Word
result VAR Byte ' not used
'================================================
PROGRAM Start
'================================================
'
Subroutines / Jump Table
'
Program Code
Start:
' Initialize SD Data Logger
LOW SPin ' Start with serial pin low
PAUSE 1000 ' Allow module to stabilize
SEROUT SPin, T2400, "!" ' Wake-up module from sleep mode
SEROUT SPin, T2400, "W" ' Wake-up module from sleep mode
SEROUT SPin, T2400, "U" ' Wake-up module from sleep mode
' Set pacing value
' SEROUT SPin, T2400, [noparse][[/noparse]"!PV", 30] ' Set pacing to 10*100uSec
SEROUT SPin, T2400, "!" ' Set pacing to 10*100uSec
SEROUT SPin, T2400, "P" ' Set pacing to 10*100uSec
SEROUT SPin, T2400, "V" ' Set pacing to 10*100uSec
SEROUT SPin, T2400, "," ' Set pacing to 10*100uSec
SEROUT SPin, T2400, 30 ' Set pacing to 10*100uSec
SERIN SPin, T2400, result ' Get result (should be pacing value)
' Close File
' SEROUT SPin, T2400, [noparse][[/noparse]"!CF"] ' Close File
SEROUT SPin, T2400, "!" ' Close File
SEROUT SPin, T2400, "C" ' Close File
SEROUT SPin, T2400, "F" ' Close File
SERIN SPin, T2400, result ' Get result of Close File
Main:
' Open file "DATA.CSV"
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!OF", "DATA.CSV"] ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "!" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "O" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "F" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "," ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "D" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "A" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "T" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "A" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "." ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "C" ' Open File DATA.CSV, created if doesn't exist
SEROUT SPin, T2400, "V" ' Open File DATA.CSV, created if doesn't exist
SERIN SPin, T2400, result ' Get result (should be zero)
IF result = NO_ERROR THEN
' Append column headings to file
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!AS", "Count,Value", CR, LF] ' Write column labels
'BS2'' SERIN SPin, T2400, [noparse][[/noparse]result] ' Get result (should be zero)
'BS2'' DEBUG "Append result = ", DEC result, CR
' Write 10 numbers to file
FOR counter = 1 TO 10
' Get a value
value = 17
' Write counter and value to file using Append String
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!AS", DEC counter, ",", DEC value, CR, LF]
SEROUT SPin, T2400, "!"
SEROUT SPin, T2400, "A"
SEROUT SPin, T2400, "S"
SEROUT SPin, T2400, ","
SEROUT SPin, T2400, value
SERIN SPin, T2400, result ' Get results (should be zero)
NEXT
' Close File
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!CF"] ' Close File
SEROUT SPin, T2400, "!"
SEROUT SPin, T2400, "C"
SEROUT SPin, T2400, "F"
SERIN SPin, T2400, result ' Get result of Close File
ELSE
' Close File
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!CF"] ' Close File
SEROUT SPin, T2400, "!"
SEROUT SPin, T2400, "C"
SEROUT SPin, T2400, "F"
SERIN SPin, T2400, result ' Get result of Close File
'BS2'' DEBUG "Close result = ", DEC result, CR
'BS2'' DEBUG DEC result, "ERROR OPENING FILE...", CR
ENDIF
' Put module into Sleep Mode
'BS2'' SEROUT SPin, T2400, [noparse][[/noparse]"!SL"]
SEROUT SPin, T2400, "!"
SEROUT SPin, T2400, "S"
SEROUT SPin, T2400, "L"
'BS2' GOTO Finished
GOTO Main
' =========================================================================
' Subroutines
' =========================================================================
'BS2' NoResponse:
'BS2'' DEBUG "NO RESPSONSE FROM DATA LOGGER."
'BS2' Finished:
'BS2' GOTO Finished
That would be terribly inefficient as SEROUT compiles into a fair bit of code. My suggestion is that you create a subroutine that is a shell for SEROUT. This is what I do:
Pretty easy; now you can send a character from any point in the program and not waste code space. To send a string, add a second routine.
With the TX_STR subroutine you can embed a string in your code like this:
... or pass the name of a label that holds a Z-String in a DATA statement; like this:
Note that you must add the trailing zero (SX/B does this for you with inline strings).
Post Edited (JonnyMac) : 3/20/2008 1:29:54 PM GMT
I have to do some homework on "Z strings."
Any advice on that baud rate?
· It should be N19200 if the jumper is on, or N2400 if the jumper is off.
· Also you cannot do serial communication using the internal 4MHz oscillator. It is not accurate enough. You need to use a resonator.
· P.S. I usually send a couple "junk" characters before any commands, just in case the SD Datalogger is waiting for a partial command. So I usually send something like "xxx!CF" to close a file.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
Post Edited (Bean (Hitt Consulting)) : 3/20/2008 2:20:27 PM GMT
How does this look as about the minimum to get a result?
Resonator is Murata "400C.625" that came with Tech Tool kit.
Logger jumper is off
Problems:
- Logger's active light does not come on ther then about 200 mSec when I power up the board
- Nothing appears on the SD when I look at it on my PC.
' Almost minimum to get result with Hitt Data Logger
'
' Device Settings
'
' external resonator Murata "400C.625"
DEVICE SX28, OSCXT1, TURBO, STACKX, OPTIONX
FREQ 20_000_000
'
IO Pins
Spin pin RA.0 ' Serial Pin
' note: data logger jumper OFF for 2400
' Variables
tmpW1 var word
tmpB1 var byte
counter var byte
'
Subroutines / Jump Table
TX_BYTE sub 1
TX_STR sub 2
'================================================
PROGRAM Start
'================================================
Start:
'
Program Code
Main:
LOW SPin ' Start with serial pin low
PAUSE 1000 ' Allow device to stabilize
TX_Str "xxx!WU" ' Wake Up
TX_Str "xxx!PV30" ' Set pacing
TX_Str "xxx!CF" ' Close file (in case open)
TX_Str "xxx!OFDATA01.CSV" ' Open file "DATA01.CSV"
TX_Str "xxx!ASHeadings" ' Append col headings
For counter = 1 to 100 'append some test values
Tx_str "xxx!AS"
Tx_byte counter
Tx_str "CRLF"
next
TX_Str "xxx!CF" ' Close File
TX_Str "xxx!SL" ' Put module into Sleep Mode
end
'
Subs
sub TX_BYTE
SEROUT Spin, N2400, __PARAM1
endsub
SUB TX_STR
tmpW1 = __WPARAM12
DO
READINC tmpW1, tmpB1
IF tmpB1 = 0 THEN EXIT
TX_BYTE tmpB1
LOOP
ENDSUB
The tech tool kit does not come with a 20MHz resonator.
It must be either a 4MHz or a 50MHz.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Bean,
Is there a particualar reason this adversely affects the SX? It's possible to do serial communications with the internal oscillator of pretty much any other major microcontroller family. While I understand that the SX needs to use a software UART implementation, I can't see any reason why the SX should have issues at even 19,200 baud, where it has over 200 cycles between bits.
I'd make an educated guess that this because the SX ships without it's internal oscillator trimming? (Sorry, can't check this theory with the datasheet at the moment)
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
I some extra hardware must be requried to trim the SX' oscillator. In fact, I can't see any way it couldn't.
If the use "IRC_CAL IRC_4MHZ" it the SX-key programmer will trim the device.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......
I've incorporated your suggestions (I think) but am still getting:
- no file written to the SD card
- no logger active light on
I've tried with Murata 400CM625 resonator and FREQ=4_000_000
I've also switched to Murata 50 resonator and freq of 50M.
Logger works fine in BS2.
This program is stripped down to try to focus on what is wrong to create a file.
My guesses on problems:
Pacing command & value not sent correctly?
Baud setting on SEROUT?
Much thanks.
'
' Device Settings
'
' external resonator Murata "50.00"
DEVICE SX28, OSCXT1, TURBO, STACKX, OPTIONX
FREQ 50_000_000
'
IO Pins
' data logger jumper OFF for 2400
Spin pin RA.0 ' Serial Pin
' Variables
tmpW1 var word
tmpB1 var byte
counter var byte
'
Subroutines / Jump Table
TX_BYTE sub 1 'has parameters so don't use "GoSub"
TX_STR sub 2 ' a string as follows
' TX_Str takes a string in quotes (minimum 2 char)
' TX_Str takes a string in DATA with a 0 terminator
'================================================
PROGRAM Start
'================================================
Start:
'
Program Code
Main:
LOW SPin ' Start with serial pin low
PAUSE 1000 ' Allow device to stabilize
TX_Str "xxx!WU" ' Wake Up
TX_Str "xxx!PV30" ' Set pacing
TX_Str "xxx!CF" ' Close file (in case open)
TX_Str "xxx!OFDATA01.CSV" ' Open file "DATA01.CSV"
TX_Str "xxx!ASHeadings" ' Append col headings
For counter = 1 to 100 'append some test values
Tx_str "xxx!AS"
Tx_byte counter
Tx_str "CRLF"
next
TX_Str "xxx!CF" ' Close File
TX_Str "xxx!SL" ' Put module into Sleep Mode
end
'
Subs
sub TX_BYTE
SEROUT Spin, N2400, __PARAM1
endsub
SUB TX_STR
tmpW1 = __WPARAM12
DO
READINC tmpW1, tmpB1
IF tmpB1 = 0 THEN EXIT
TX_BYTE tmpB1
LOOP
ENDSUB
OSCXT1 is not going to work with the 50MHz resonator. Try OSCHS1 or OSCHS2. I'd suggest using the 4MHz resonator anyway.
You are not reading back the data returned by the SD Datalogger. You either have to read it, or at least wait until it is sent before you send anything else. What is happening is that you are sending the next command at the same time the datalogger is sending data back. As a result the datalogger "misses" the command.
The pacing value must be sent as a value, not as ascii. Instead of TX_Str "!PV30" you need to use TX_Str "!PV" then TX_Byte 30.
You need to convert the counter value to ASCII when using the "!AS" command.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Symptom remains the same, logger blinks activate light when power up, then I can't get the active light on again.
Same result with OCHS1 or OCHS2. I'm using the "400" resonator from the TX Tech Tool Kit.
Where do I put SERIN? After each Tx_Str in the main code (as below and in BS2 sample) or once after the SEROUT in the sub Tx_Byte?
'
' Device Settings
'
' external resonator Murata "400Cxxx"
DEVICE SX28, OSCHS1, TURBO, STACKX, OPTIONX
FREQ 4_000_000
'
IO Pins
' data logger jumper OFF for 2400
Spin pin RA.0 ' Serial Pin
' Variables
tmpW1 var word
tmpB1 var byte
counter var byte
result var byte ' sent back from logger
'
Subroutines / Jump Table
TX_BYTE sub 1 'has parameters so don't use "GoSub"
TX_STR sub 2 ' a string as follows
' TX_Str takes a string in quotes (minimum 2 char)
' TX_Str takes a string in DATA with a 0 terminator
'================================================
PROGRAM Start
'================================================
Start:
'
Program Code
Main:
LOW SPin ' Start with serial pin low
PAUSE 1000 ' Allow device to stabilize
TX_Str "xxx!WU" ' Wake Up
PAUSE 100
' Set pacing
TX_Str "xxx!PV" ' Set pacing
TX_Byte 30 ' Pacing value
SERIN SPin, N2400,Result ' Get result
' Close file (in case open)
TX_Str "xxx!CF" ' Close file (in case open)
SERIN SPin, N2400,Result ' Get result
' Open file "DATA01.CSV"
TX_Str "xxx!OFDATA01.CSV" ' Open file "DATA01.CSV"
SERIN SPin, N2400,Result ' Get result
'append some test values
For counter = 1 to 10 'append some test values
Tx_str "xxx!AS"
SERIN SPin, N2400,Result ' Get result
Tx_byte "A" ' simple as possible for test
Tx_str "CRLF"
SERIN SPin, N2400,Result ' Get result
next
' Close File
TX_Str "xxx!CF" ' Close File
SERIN SPin, N2400,Result ' Get result
' Put module into Sleep Mode
TX_Str "xxx!SL" ' Put module into Sleep Mode
end
'
Subs
sub TX_BYTE
SEROUT Spin, N2400, __PARAM1
endsub
SUB TX_STR
tmpW1 = __WPARAM12
DO
READINC tmpW1, tmpB1
IF tmpB1 = 0 THEN EXIT
TX_BYTE tmpB1
LOOP
ENDSUB
· Here is a simple program that appends the string "This is a test" to a data file everytime you run it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com