Code failure

russbow

Senior Member
I am attempting to run this code.

Code:
'Station Base developement
'
'Vers 1 @ 10/10/12


#picaxe20m2
'#No_Data

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
init:

symbol LCD=b.6
symbol ANT=b.1

symbol ASK=b.2 'Conn to RX port
symbol ANS=b.3 'Conn to TX port

symbol HrHi=b18
symbol HrLo=b19
symbol MinHi=b20
symbol MinLo=b21
symbol DayHi=b22
symbol DayLo=b23
symbol MthHi=b24
symbol MthLo=b25
symbol YrHi=b26
symbol YrLo=b27

setfreq m16

pause 2000


	serout LCD,N2400_16,(254,1,254,1)
	pause 200
	


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

	do

	gosub get_time
	
	pause 5000
	
	gosub get_base
	
	pause 5000
	
	
	
	Loop	

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

get_time:

	i2cslave%11010000, i2cslow, i2cbyte
		readi2c 1,(b1,b2,b3,b4,b5,b6)
	pause 1000

	bcdtoascii b2,HrHi,HrLo
	bcdtoascii b1,MinHi,MinLo	
	bcdtoascii b4,DayHi,DayLo
	bcdtoascii b5,MthHi,MthLo
	bcdtoascii b6,YrHi,YrLo
	
	serout LCD,N2400_16,(254,192,HrHi,HrLo,":",MinHi,MinLo)
	serout LCD,N2400_16,(254,199,dayHi,DayLo,"/",MthHi,MthLo,"/",YrHi,YrLo)
	pause 10000
	
return

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

get_base:

	'First get pressure
	
	setfreq m32
	pause 500
	
	serout ASK,t9600_32,("$sure p",$0D,$0A) 'Get pressure
	serin ANS,t9600_32,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b1,b2,b3,b4,b5,b6,b7
	
	setfreq m16
		serout LCD,N2400_16,(254,128,b0,b1,b2,b3,b4,b5,b6)
		sertxd ("Hg ",b0,b1,b2,b3,b4,b5,b6,cr,lf)

	pause 500
	
	'Now get temperature
	
	setfreq m32
	serout ASK,t9600_32,("$sure t-c",$0D,$0A) 'Get pressure
	serin ANS,t9600_32,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b0,b4,b5,b6,b7,b8,b9
	
	setfreq m16
		serout LCD,N2400_16,(254,135,b4,b5,b6,b7,b8,b9)
		sertxd (b4,b5,b6,b7,b8,b9,cr,lf)

	pause 500

return

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Each block works perfectly on it's own.

When run, the screen clears and the time is displayed correctly. Nothing further happens and sertxd does not respond.

If I rem out the gosub get_time, the program loops OK, and sertxd shows regular updates.

However, if I change the loop order thus ...

Code:
do

	
	pause 5000
	
	gosub get_base
	
	pause 5000
	
	gosub get_time
	
Loop
Data first, then time, ALL performs OK, time and data updated regularly.

I thought at first some variable conflict. Any ideas?
 

inglewoodpete

Senior Member
Possibly not the cure to your problem but I notice that you are running the native 20M2 at 16MHz for the i2c comms, 4 times its native speed. However, the i2c is configured for 4MHz slow.

Before you go any further, replace with the following i2c setup command:

Code:
i2cslave %11010000, i2cslow_16, i2cbyte_16
Secondly, should you position the input point on the LCD before issuing the following command?

Code:
serout ASK,t9600_32,("$sure p",$0D,$0A) 'Get pressure
 

russbow

Senior Member
Working fine now thanks to your inputs.

@IWP - Changing the I2C parameters as suggested just produced a syntax error. However that made me focus on the chip speed.
I re-jigged the code to run at 4mHZ, only calling m32 for the serial to the pressure / temperature module. Works fine now whichever sub routine I call first.

I have a suspicion that it was OK anyway and I assumed a fault due to a loooong delay between clock and data.

@Bill - No, neither. Improvements to an original project http://www.picaxeforum.co.uk/showthread.php?18630-Weather-measurements-with-Sure-Modules

more changes in the pipeline.
 

inglewoodpete

Senior Member
Changing the I2C parameters as suggested just produced a syntax error.
I was at work and made the suggestion off the top of my head during a coffee break.

A check of the manual would have given you the correct syntax:
Code:
i2cslave %11010000, i2cslow_16, i2cbyte
 
Top