X2 thoughts ?

therowes

Member
Trying to get my head around the new facilities on the X2 chips, if any PIN can be I/O then is it possible to do this ?

dirsc = %00000000 ' all inputs
readtemp12 c.1,w1 ' save in b0 and b1

i.e having upto 32 temperature recorders ( on 40X2 ) !

The PE doesn't throw a syntax error, and I've not got a chip to try it on (yet) !

Bit confused because it doesn't object to this either !

dirsc = %00000000 ' all inputs
readtemp12 99,w1 ' save in b0 and b1

but does to this ( which I would expect )!

dirsc = %00000000 ' all inputs
readtemp12 c.9,w1 ' save in b0 and b1

With:- ( the port pin number is out of range strange error message ? )

readtemp12 c.9,w1 ' save in b0 and b1
^
Error: This command requires the pin number (X.Y) not the variable (pinX.Y)!

Another point I noticed is that an extra byte is used for ports a,b,d for those who need to optimize code .

Also it passes :-
readtemp12 7,w1

Which I guess ( maybe ) is using port D ( the X1 input ports) ?

PE version 5.2.4 and tried on laptop aswell .

Any thoughts ?

Cheers Martin
 

Technical

Technical Support
Staff member
Because all chips only use 'numbers' during their processing, screen notations such as B.1 are just, to the chip, different numbers - its only written in that port.pin format on screen just to make it clearer to the human programmer. The compiler tries to catch as many incorrect options as possible, but only valid port.pin notation should really be used.

As to your original question, yes you can use readtemp12 on almost every pin (not the download serial in/out pins though) and the correct programming format is like this

readtemp12 c.1,w1 ' save in b0 and b1



Or with the DS18B20 on X1/X2 you can connect them all to one pin and use the owin/owout commands to read each sensor in turn (bit more programming involved though!)
 

BeanieBots

Moderator
It's amazingly flexible I/O wise.
The only one to look out for is when using analogue inputs.
You can't for example use A.3 if you have not already specified 0-2 as being analogue inputs. This varies a little with the different versions (5v/3v 20/28X2) so be sure to read the manual carefully.
 

therowes

Member
Taking technical's advice I've successfully interrogated a couple of DS1820 devices and obtained their unique addresses using “readowsn”

Next I tried to read the values of 1 device still connect on input pin 7, using example from manual and also as an answer to another query (ignoring device id).

It didn’t work and after experimenting with either the example or reply. I found a problem even with the simplified code below.

Output 6 is set high ,then set to low so should only be high at start. It does however pulse with a 3 sec ON period suggesting a reset has occurred , the debug statement after the “owout” is never executed ?

REM out the owout command and it works as expected ?

setfreq m4
high 6
pause 3000
low 6
owout 7,%1001,($CC,$44)
debug b0
lp1:
goto lp1

Just by chance I’ve an LED connected to “output” 0 and it pulses as a mirror image of “Output 6” ?

I’ve tried 2 different chips, both 40X1 firmware A2, both have been used for other projects in the same development board, including the “readowsn”.
PSU is 5V from USB port and has never caused a problem even when using a Vdrive2 module, LCD, RTC etc. Wire lengths are less than 2 inches.
PE version 5.2.4
Any Ideas ?

Thanks Martin
 

therowes

Member
Thanks Technical - that has stopped the reset problem, for those who may wish to try it the following test code reads 2 DS18B20 results on the same input pin.

The rem'd code was used to identify the serial number of EACH device one at a time.

You must use the family code and CRC digits to make up the full identifier of each chip !

'ie. b6 to b13 from READOWSN

Next to try is 8 devices on about 30mtrs of cat5 ( solar hotwater system in the loft )!



setfreq m4

#rem
main1:
let b6 = 0 ' reset family code to 0
' loop here reading numbers until the
' family code (b6) is no longer 0
loop1:
readowsn 7 ' read serial number on input2
if b6 = 0 then loop1
' Do a simple safety check here.
' b12 serial no value will not likely be FF
' if this value is FF, it means that the device
' was removed before a full read was completed
' or a short circuit occurred
if b12 = $FF then main1
'Everything is ok so continue
debug b1 ' ok so display
pause 1000 ' short delay
goto main1

#endrem


; Read raw temperature value from DS18B20
; (this achieves a similar function to the readtemp12 command)

main:
owout 7,%1001,($55,$28,$BF,$09,$2E,$01,$00,$00,$00,$44)
' $55 + device id +$44
' send ‘reset’
pause 750 ' wait 750ms with strong pullup
owout 7,%0001,($55,$28,$BF,$09,$2E,$01,$00,$00,$00,$BE)
' $55 + device id +$BE
' send ‘reset’
' then ‘read temp’ command
owin 7,%0000,(b0,b1) ‘ read in result
sertxd (#w0," ") ‘ transmit value

' SECOND DEVICE

owout 7,%1001,($55,$28,$2A,$C3,$47,$01,$00,$00,$C6,$44)
' send ‘reset’
' then ‘convert’ then apply ‘pullup’
pause 750 ' wait 750ms with strong pullup
owout 7,%0001,($55,$28,$2A,$C3,$47,$01,$00,$00,$C6,$BE)
' send ‘reset’
' then ‘read temp’ command
owin 7,%0000,(b0,b1) ‘ read in result
sertxd (#w0," ") ‘ transmit value

goto main

Again thanks to Technical for your quick responses and solutions

Martin
 
Top