Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:57 19 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Odd serial data for micromite

     Page 2 of 3    
Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 01:09am 23 Jun 2017
Copy link to clipboard 
Print this post

you seem to be missing the SETPIN statement.


cheers,
rob :-)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 01:24am 23 Jun 2017
Copy link to clipboard 
Print this post

  Quote  I think that Peter's BitBanger Csub is for the 470 chips.


Can't see anything in the code which would make it MX470 specific and Jim's experience seems to support it working fine on MX170.

This is precisely the sort of application it was intended forEdited by matherp 2017-06-24
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 12:29pm 23 Jun 2017
Copy link to clipboard 
Print this post

  Quote  you seem to be missing the SETPIN statement.

Thanks for the reply Rob but I only posted a snippet of the code which did have the SETPIN statements in it.

  Quote  This is precisely the sort of application it was intended for

Peter, thanks it looks like using the Bitbanger Csub may be the next method to try. Do you think that I could use the COM2 TX PIN as DOUT to send out the timing and serial stream query then open the COM port ready to receive the reply?

Just to check my maths, 1200 bps data would mean each bit would be 0.833mS in length?

Graeme
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 06:50pm 23 Jun 2017
Copy link to clipboard 
Print this post

More into the quagmire
Decided to give the Bitbanger CSub a go so I loaded the code into the 170 saved the library and wrote a bit of code to test it. Pin 7 has a LED attached so I thought I would send some pulses to it but here is the result.

> run
[LIBRARY] CSubB bitbangerB
Error: Unknown command
> library list
CSubB bitbangerB
B B B B 00000000
B B B B 27BDFFC0B AFBF003CB AFBE0038B AFB70034B AFB60030B AFB5002CB AFB30024B AFB20020B
B B B B AFB1001CB AFB00018B AFB40028B 3C109D00B 8E030000B 00808821B 8E020080B 8C640000B
B B B B 00A09021B 00002821B 00C0B021B 0040F809B 8E140064B 00409821B 8E02009CB 3C0449F4B
B B B B 0040F809B 24842400B 00402821B 0280F809B 02602021B 0040B821B 8E240000B 8E020024B
B B B B 24050007B 0040F809B 241E0001B AFA20010B 8E020028B 0040F809B 8E240000B 8E520000B
B B B B 8E030040B 005EF004B 0060F809B 00122080B AFA20014B 12400013B 0040A821B 0000A021B
B B B B 00008821B 3C139D00B 0014A080B 02D41821B 8C640000B 8E620058B 8E70007CB 0040F809B
B B B B 02E02821B 26310001B 0200F809B 00402021B 02B4A021B 0232182BB AE820000B 1460FFF2B
B B B B 0220A021B 8FA30014B 3C040008B 8C620000B 2442FFFDB AC620000B 3C03BF88B AC641064B
B B B B 3C03BF88B 00001021B AC601068B 40824800B 8FA50014B 8FA30010B 2652FFFFB AC7E0000B
B B B B 8CA40000B 00442021B 40024800B 0044182BB 1460FFFDB 00000000B 1640FFF6B 24A50004B
PRESS ANY KEY ...


> ? mm.ver
5.0404


Can someone help with the reasons I get all these "B"'s saved with the CSub?
Edited by OA47 2017-06-25
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 07:45pm 23 Jun 2017
Copy link to clipboard 
Print this post

No problems here
  Quote  LIST
CSub bitbanger integer,integer,float 'pin number, number of bits, floating point array of bit lengths in usec
00000000
27BDFFC0 AFBF003C AFBE0038 AFB70034 AFB60030 AFB5002C AFB30024 AFB20020
AFB1001C AFB00018 AFB40028 3C109D00 8E030000 00808821 8E020080 8C640000
00A09021 00002821 00C0B021 0040F809 8E140064 00409821 8E02009C 3C0449F4
0040F809 24842400 00402821 0280F809 02602021 0040B821 8E240000 8E020024
24050007 0040F809 241E0001 AFA20010 8E020028 0040F809 8E240000 8E520000
8E030040 005EF004 0060F809 00122080 AFA20014 12400013 0040A821 0000A021
00008821 3C139D00 0014A080 02D41821 8C640000 8E620058 8E70007C 0040F809
02E02821 26310001 0200F809 00402021 02B4A021 0232182B AE820000 1460FFF2
0220A021 8FA30014 3C040008 8C620000 2442FFFD AC620000 3C03BF88 AC641064
3C03BF88 00001021 AC601068 40824800 8FA50014 8FA30010 2652FFFF AC7E0000
8CA40000 00442021 40024800 0044182B 1460FFFD 00000000 1640FFF6 24A50004
8FBF003C 3C020008 3C03BF88 AC621064 3C03BF88 8FBE0038 8FB70034 8FB60030
8FB5002C 8FB40028 8FB30024 8FB20020 8FB1001C 8FB00018 AC621068 03E00008
27BD0040
End CSub
> library save
> library list
CSub bitbanger integer,integer,float 'pin number, number of bits, floating point array of bit lengths in usec
End CSub
>


I tried it with V5.2 and 5.4.4

Is all OK when you do a LIST befroe saving into the library?
Jim
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 09:52pm 23 Jun 2017
Copy link to clipboard 
Print this post

Jim, all looked ok before I saved it to the library. I will clear the chip and try again.
Graeme
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 10:58pm 23 Jun 2017
Copy link to clipboard 
Print this post

It seems the corruption is happening when I paste from TERATERM. The code in the TERATERM Clipboard is OK but the B's appear when I paste using AUTOSAVE. I had originally saved the code from Peter's post to a text file for future reference and this post had diagrams imbedded so there must have been unprintable characters imported across. Cutting and pasting from Jims post fixed the problem and guess what the LED flashes.

Now to see if I can talk to this device...................

Graeme
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 12:51am 28 Jun 2017
Copy link to clipboard 
Print this post

Found more information on the device which mentions that the serial logic is reversed and needs to be logic 0 @ 3.5-5.5V and logic 1 @ -0.5-1.0v. To over come this I had a spare 2803 inverter which gives me the required logic levels and inversion. I have tried the following code with the Bitbanger outputting on PIN 14 and monitor the outgoing and incoming with COM1 RX. The query command needs to have the address as the first character (represented in earlier documentation by the letter a)so the query for info should be >12mS Break (3.5-5.5V) followed by a >8.5 mS Mark (-0.5-1.0V),then the address 0 (all units supplied at address 0 and can be individually changed)followed by the letter I then ended by the Exclamation Mark. I seem to be setting up the Query string OK as monitored by the COM1 port but I still cannot capture a REPLY.
If someone can see an error in my code or a bad assumption I would love to know.
RTC GETTIME
SetPin 2,AIN 'PV Voltage
SetPin 3,Ain 'SLA Voltage
SetPin 4,AIN 'EXT ANALOG IN 2 (SOL 2 Pressure)
SetPin 5,AIN 'EXT ANALOG IN 1 (SOL 1 Pressure)
SetPin 6,DOUT 'SOLENOID 1 SET [5V] (Prev DS18B20)
SetPin 7,DOUT 'INDICATOR LED (COM1 EN|DIGITAL|INT|ANALOG|3V)
SetPin 9,DOUT 'COM2 TX (Pin 3 Labelled OUT on connecter)
SetPin 10,DOUT 'COM2 RX (Pin 2 Labelled IN on connector)
SetPin 14,DOUT 'SOLENOID 2 RESET [5V]
SetPin 15,DIN 'MODEM CD AND TEST BUTTON (DB15[14])
SetPin 16,DOUT 'MODEM PTT (WAKE FROM SLEEP & DB15[13])
SetPin 17,DOUT 'RTC I2C CLK (DIGITAL|COUNT|5V)
SetPin 18,DOUT 'RTC I2C DATA (DIG|COUNT|5V) PREV CIN RADIO AF OUT
'SetPin 21,DOUT 'COM1 TX (DB15[2] J2-??)
'SetPin 22,DOUT 'COM1 RX (DB15[4] J2-??)
SetPin 23,AIN 'EXT ANALOG IN 3
SetPin 24,AIN 'EXT ANALOG IN 4
SetPin 25,DOUT 'SOLENOID 1 RESET
SetPin 26,DOUT 'SOLAR SHUTDOWN & LED D3 (PREV PWM OUT/RADIO AF IN)

Dim BRDTEMP
Dim REPLY$

RTC GETREG 2,BRDTEMP
Print Time$,Date$,"BOARD TEMP=";BRDTEMP;" DEG C"

Open "COM1:1200,INV" As #1 'OUTPUT VIA 2803 TO GET 5V & INV

Dim FLOAT TRQ(30)
For I =0 To 17
Read A
TRQ(I)=A
Next I

Pin(7)=1 'SET THE INDICATOR LED TO ON
Pin(14)=1 'START THE BIT TRAIN AT 0V

BITBANGER(14,18,TRQ())
Pin(7)=0 'SET THE INDICATOR LED TO OFF
Pause 100
REPLY$=Input$(10,#1)
Close #1

Print " 8 BIT QUERY STRING IS ";Left$(REPLY$,3)
Print " 8 BIT REPLY STRING IS ";Right$(REPLY$,(Len(REPLY$)-3))
Print
Print
Print "CHR#","8BIT ASC","7BIT ASC"
For J = 1 To Len(REPLY$)
Print J,Asc(Mid$(REPLY$,J,1)),,Asc(Mid$(REPLY$,J,1)) And 127
Next J

'ADDRESS QUERY ?!
'ACKNOWLEDGE ACTIVE 0!
'SEND IDENTIFICATION 0I!

Data 12500,8500 '12.5mS BREAK THEN 8.5mS MARK
Data 4165,1666,1666,833 '0 = -----__--_
Data 833,833,1666,833,1666,2499 'I = -_--_--___
Data 833,833,3332,833,1666,833 '! = -_----_--_


> RUN
20:16:38 28-06-2017 BOARD TEMP= 32 DEG C
8 BIT QUERY STRING IS 0É!
8 BIT REPLY STRING IS


CHR# 8BIT ASC 7BIT ASC
1 48 48
2 201 73
3 33 33
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 12:58pm 28 Jun 2017
Copy link to clipboard 
Print this post

Pin(14)=1 'START THE BIT TRAIN AT 0V


should be
Pin(14)=0 'START THE BIT TRAIN AT 0V


You really need a logic analyzer or storage cro!

Jim
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 01:07pm 28 Jun 2017
Copy link to clipboard 
Print this post

Thanks for the comment Jim, I am a long way from the shed at the moment so I have to try and deal with the minimum of test equipment. The most sophisticated equipment I have is a 30 year old digital multimeter with a low battery.

The reason that the PIN(14) is around the other way is because I am inverting the output through the 2803.

Graeme

EDIT; Just re-measured to be sure, pin(14)=1 is 0.64v and pin(14)=0 is 5.02VEdited by OA47 2017-06-29
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 04:32pm 29 Jun 2017
Copy link to clipboard 
Print this post

Do you have a link to any datasheets or info on the module you are trying to communicate with? Might help us try to work out what's going on.....

Cheers,
GTG!
...... Don't worry mate, it'll be GoodToGo!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 07:02pm 29 Jun 2017
Copy link to clipboard 
Print this post

Thank you @GTG for taking an interest in my plight, I have found many snippets of information some that seem to conflict with others but here are a couple:
PROBE COMMANDS
User Manual
Using arduino to talk to sensors
sdi-12 support group

@ Peter. Is there a way that I can use the Bitbanger CSub with a variable for the number of transitions so that I can dynamically build the pulse train with Basic?

Graeme Edited by OA47 2017-07-01
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 08:02pm 30 Jun 2017
Copy link to clipboard 
Print this post

I have scratched together some very clumsy and untidy code that will dynamically re-order the bit train from a LINE INPUT command string to a 1200,7,e INVERTED serial stream. The device echoes the commands accurately so I think I have the coding right but still refuses to reply with any data.


'******************************************************************************
'* Micromite MMBasic Version 5.4.4 on PICMX170F56B-50I/SP 28 PIN DIL Chip *
'* *
'* File: RCSV6SDITEST8 PROGRAM FOR SDI-12 SOIL MOISTURE PROBE 01/07/2017 *
'* *
'* ENVIROPRO SOIL MOISTURE SENSOR SDI-12 (1200,7,E,1,INV) *
'* *
'******************************************************************************
Option EXPLICIT
RTC GETTIME
SetPin 2,AIN 'PV Voltage
SetPin 3,Ain 'SLA Voltage
SetPin 4,AIN 'EXT ANALOG IN 2 (SOL 2 Pressure)
SetPin 5,AIN 'EXT ANALOG IN 1 (SOL 1 Pressure)
SetPin 6,DOUT 'SOLENOID 1 SET [5V] (Prev DS18B20)
SetPin 7,DOUT 'INDICATOR LED (COM1 EN|DIGITAL|INT|ANALOG|3V)
SetPin 9,DOUT 'COM2 TX (Pin 3 Labelled OUT on connecter)
SetPin 10,DOUT 'COM2 RX (Pin 2 Labelled IN on connector)
SetPin 14,DOUT 'SOLENOID 2 RESET [5V]
SetPin 15,DIN 'MODEM CD AND TEST BUTTON (DB15[14])
SetPin 16,DOUT 'MODEM PTT (WAKE FROM SLEEP & DB15[13])
SetPin 17,DOUT 'RTC I2C CLK (DIGITAL|COUNT|5V)
SetPin 18,DOUT 'RTC I2C DATA (DIG|COUNT|5V) PREV CIN RADIO AF OUT
'SetPin 21,DOUT 'COM1 TX (DB15[2] J2-??)
'SetPin 22,DOUT 'COM1 RX (DB15[4] J2-??)
SetPin 23,AIN 'EXT ANALOG IN 3
SetPin 24,AIN 'EXT ANALOG IN 4
SetPin 25,DOUT 'SOLENOID 1 RESET
SetPin 26,DOUT 'SOLAR SHUTDOWN & LED D3 (PREV PWM OUT/RADIO AF IN)

Dim BRDTEMP 'TEMPERATURE MEASUREMENT FROM RTC
Dim REPLY$ 'ECHOED QUERY AND STRING RETURNED BY DEVICE
Dim ASV(10) 'ASCII VALUE OF EACH CHARACTER TO SEND
Dim BINV$(10) 'MSB-LSB BINARY STRING OF EACH CHARACTER TO SEND
Dim INVB$(10) 'LSB-MSB BINARY STRING OF EACH CHARACTER TO SEND
Dim PAR$(10) 'INVERTED EVEN PARITY BIT(CALCED ON ZEROS NOT ONES)
Dim TENBIT$(10) 'TOTAL TEN BITS INCL PARITY, START AND STOP BITS
Dim PARTLENGTH(10) 'TOTAL PULSE TRANSMISSION TIME
Dim BL=833 'NUMBER OF uS FOR EACH BIT LENGTH AT 1200 BPS
Dim FLOAT BitBangTrain(49)'BITBANG ARRAY ALLOWING FOR 50 TRANSISTIONS
Dim F,G,H,I,J,K,L,M
Dim QUERY$ 'COMMAND READ AT LINE INPUT
Dim ZEROS 'ZERO COUNT IN BINARY STRING
Dim BITS$ 'EACH BINARY BIT READ OUT OF STRING
Dim BITLENGTH 'No OF TRANSITIONS IN BIT TRAIN
RTC GETREG 2,BRDTEMP
Print Time$,Date$,"BOARD TEMP=";BRDTEMP;" DEG C"


Print "ENTER COMMAND ";
Line Input QUERY$

For F=0 To 49:BitBangTrain(F)=0:Next F
BitBangTrain(0)=12500
BitBangTrain(1)=8500
H=1 'BitBang ARRAY POINTER
For I = 1 To Len(QUERY$)
ASV(I)=Asc(Mid$(QUERY$,I,1)) 'GET THE ASCII VALUE OF EACH LETTER
BINV$(I)=Bin$(ASV(I)) 'CONVERT THE ASCII VALUE TO BINARY
'PAD OUT BINARY TO 7 BITS
If Len(BINV$(I))=2 Then BINV$(I)="0"+BINV$(I)
If Len(BINV$(I))=3 Then BINV$(I)="0"+BINV$(I)
If Len(BINV$(I))=4 Then BINV$(I)="0"+BINV$(I)
If Len(BINV$(I))=5 Then BINV$(I)="0"+BINV$(I)
If Len(BINV$(I))=6 Then BINV$(I)="0"+BINV$(I)'HAVE 7 BIT BINARY FOR EACH CHAR

ZEROS=0
For J= 7 To 1 Step -1
BITS$=Mid$(BINV$(I),J,1)
INVB$(I)=INVB$(I)+BITS$ 'CONVERT BINARY STRING TO LSB-MSB
If BITS$="0" Then ZEROS=ZEROS+1 'COUNT THE ZEROS IN THE 7 BITS
Next J 'SET PARITY BIT TO 1 IF EVEN

If ZEROS Mod 2=0 Then PAR$(I)="1" Else PAR$(I)="0"
TENBIT$(I)="0"+INVB$(I)+PAR$(I)+"1" 'FINAL TEN BITS=TENBIT$(I)
BITLENGTH=1 'THE FIRST TRANSITION BL IN LENGTH

For K=1 To 10 '2ND AND FOLLOWING TRANSITIONS
'CHECK FOR CONSECUTIVE HIGHS OR LOWS
If Mid$(TENBIT$(I),K,1)=Mid$(TENBIT$(I),K+1,1) Then
BITLENGTH=BITLENGTH+1 'ADD TO TRANSITION FOR EACH CONSEC
Else
PARTLENGTH(I)=BITLENGTH*BL 'TOTAL TRANSITION TIME
H=H+1 'INCREMENT BitBang ARRAY POINTER
BitBangTrain(H)=PARTLENGTH(I) 'ADD TRANSITION TO BITBANG ARRAY
BITLENGTH=1 'RESTORE TRANSITION TO ONE BIT
EndIf
PARTLENGTH(I)=0
Next K

Next I

Pin(7)=1 'SET THE INDICATOR LED TO ON
Pin(14)=1 'START THE BIT TRAIN AT 0V
'OUTPUT VIA 2803 TO GET 5V & INV
Open "COM1:1200,INV" As #1 'MONITOR OUTGOING AND READ INCOMING
BITBANGER(14,50,BitBangTrain())


Pin(7)=0 'SET THE INDICATOR LED TO OFF
Pause 250
REPLY$=Input$(20,#1)

Print " 8 BIT SERIAL MONITOR ";REPLY$

Print "CHR#","8BIT ASC",,"7BIT ASC"
For J = 1 To Len(REPLY$)
Print J,Asc(Mid$(REPLY$,J,1)),Chr$(Asc(Mid$(REPLY$,J,1))),
Print ,Asc(Mid$(REPLY$,J,1)) And 127 ,Chr$(Asc(Mid$(REPLY$,J,1)) And 127)
Next J
Print "_____________________________________________________"
Close #1


Here is the RUN screen...

RUN
15:57:29 01-07-2017 BOARD TEMP= 21 DEG C
ENTER COMMAND 0C5!
8 BIT SERIAL MONITOR 0Ã5!
CHR# 8BIT ASC 7BIT ASC
1 48 0 48 0
2 195 Ã 67 C
3 53 5 53 5
4 33 ! 33 !
_____________________________________________________
>

This command is supposed to return the temperature of the probe..........

I am running out of ammunition at this stage so any help or comments would be greatly appreciated.
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 08:06pm 30 Jun 2017
Copy link to clipboard 
Print this post

Does it need a CR or CR/LF ?

VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 08:09pm 30 Jun 2017
Copy link to clipboard 
Print this post

Gday Jim, I did read on one piece of info that the commands did need a CR/LF and I did try it to no avail but most of the other reference material state that the exclamation mark is the character that denotes the end of the command.
Thanks
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 04:40am 01 Jul 2017
Copy link to clipboard 
Print this post

Reading the SDI12 spec, the sensors can take up to 100mS to wake up after a break is detected. So you may have to do a few retries.
Have a look at sections 7.0-7.2 of the SDI Spec.

I haven't got any SDI12 sensors so I can't test your code.

Cheers,
GTG!

...... Don't worry mate, it'll be GoodToGo!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 03:56pm 01 Jul 2017
Copy link to clipboard 
Print this post

Thanks for the reply GTG, I have monitored the 12V current draw of the probe which sits at 500uA on idle and up to 18mA once queried, so I believe that the probe is waking from sleep ok.
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 04:39pm 01 Jul 2017
Copy link to clipboard 
Print this post

I would start with the ?! command.
Until you know for sure what the address is, the rest is hit and miss.

The SDI-12 spec sheets make it look so simple!
I haven't read anything obvious yet.

Jim

Edit:
What are you doing to the TX line while you are listening for a response?
I think it would have to be high impedance to stop swamping the response from the probe.

Can the inverter you are using go tri-state?

Jim
Edited by TassyJim 2017-07-03
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 05:29pm 01 Jul 2017
Copy link to clipboard 
Print this post

Jim, thanks for your input, I don't think there is any way I could make the ULN2803 line driver chip go tri-state. Currently I have the output pulled to 5v via a 1K resistor. I could possibly increase that value and try to maintain the correct logic voltages.
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 05:43pm 01 Jul 2017
Copy link to clipboard 
Print this post

From the SPI specs
  Quote  C After a data recorder transmits the last character of a command, it must relinquish
control of the data line within 7.5 milliseconds following the end of the stop bit.
(Tolerance: +0.40 milliseconds.)


also:
  Quote  When an SDI-12 device has its transmitter on, its direct current (DC) source resistance
must be greater than 1000 ohms and less than 2000 ohms. When any SDI-12 device's
transmitter is off, including during a low-power standby mode, the DC resistance to
ground must be within 160K to 360K ohms.


From that, I understand that the internal impedance of your sensor when transmitting is 1-2K

The 1K at the 'mite end will certainly get in the way.
You need some way of making it high Z when not transmitting. You do need some sort of level translator because the bus needs the 5V to work.

Got any 4016 IC's in the drawer?

VK7JH
MMedit   MMBasic Help
 
     Page 2 of 3    
Print this page
© JAQ Software 2024