just a quick one

johnlong

Senior Member
Hi All
when using hserin and out does the hi2c command interfer
with the hser command
ie hserout 0,(something or other)
hi2cin 0, (read values)
regards john
 

Goeytex

Senior Member
It does for me. If an HI2C command is issued while background serial data is being received the serial data can become corrupted.

If you are having a problem please detail the problem so that others can offer help.
 

westaust55

Moderator
Not guaranteed as while I have used both in the same program, not adjacent to each other.

From PICAXE manual 2 appendix 4 both commands are internal interrupt driven.
They are using separate hardware modules (i2c shares only with SPI).

The manual in appendix 4 states that the internal event tasks temporarily "pause" the main program processing to process the task as and when it occurs.

Thus my take is that there would be no conflict as, although they use hardware modules and can be set up for background operation, used in "direct" mode as I believe you intend, like with other commends they are processes sequentially and would not interfere with each other.

If using background receive to scratchpad then there may be different issues as the main program does not control the start and timing relative to other commands.

Are you asking prior to trying or are you experiencing problems ?
 

johnlong

Senior Member
Hi
Are you asking prior to trying or are you experiencing problems ? #post3

A bit of both have connected a RTC ds1307 breakout board up to the chip and display
What I am finding is that after I send it to the clock setting sub it seems to hang
debug is showing that it has come out of the routine but not updating hanging on the time/calander page.
If I comment out the hi2c commands everything is fine. Values update moves in and out of the relivent slots
back and forth ok
Slot 0 selections are via hsersetup %0 (manual input)
However Slots 1 &2 use hsersetup %001 as an interupt for slot 0 with the ds1307 as an event timer
for the diffrent sections of the slots
Code:
#picaxe 40x2
#no_data
table 0,("JAN",0,"FEB",0,"MAR",0,"APR",0,"MAY",0,"JUN",0,"JUL",0,"AUG",0,"SEP",0,"OCT",0,"NOV",0,"DEC",0,0)
table 50,("MON",0,"TUE",0,"WEN",0,"THU",0,"FRI",0,"SAT",0,"SUN",0,0)
symbol usbon=b1   ' Data storage on or off
symbol pointer=b2  'setpointer and equipment selection in keypad    
symbol marker =b3      'b5 interupt marker between program slots
symbol themode=b4  'program location pointer
'***********************

'*************************************
'TEMPRETURE
symbol vT = b9 	' the preset value for Temperature obtained from keypad
symbol vC=b10   'for setting night tempreture if diffrent tempreture required

symbol fr=b54
'*******************************
'Humidity
symbol vHl=b14      '  the preset value for RHidity minimum value via keypad
symbol vH = b15 	' the value maximum for RHidity via keypad
symbol RH=b16      ' RHidity value obtained from sensor

'*********************************************************************************************
'SETTING VARIABLES FOR DS1307 
symbol datebcd=b19
symbol monthbcd=b20
symbol yearbcd=b21  'Variables from keypad converted at SetRTC to BCD
symbol daybcd=b22    'Loaded into the DS1307
symbol hourbcd=b23
symbol minbcd=b24
symbol secbcd=b25
'******************************************************************
'PICAXE VARIABLES FOR CONVERTED VALUES FROM I2C CLOCK
symbol sec =b26
symbol hour=b27
symbol mins=b28  'Read back variables from the DS1307 using the DS1307 as the
symbol day=b29   'Timer for the Data Logging and Display
symbol month=b30  'hour = hourbcd / 16 * $FA + hourbcd Hippy's solution for BCD to Dec conversion
symbol year=b31
symbol date=b32
symbol TD5=b42 symbol TD4=b43 symbol TD3=b44 symbol TD2=b45 symbol TD1=b46 symbol TD0=b47
symbol ii=b48
symbol Auto=b49
symbol optH=b55
symbol fsin=105
symbol mdptr=200
symbol rtnptr=201
symbol mtvl=211
symbol dyvl=212
symbol QT=34
symbol control=$10
		
	hi2csetup i2cmaster, %11010000, i2cslow_8, i2cbyte 
  	hi2csetup i2cslave, %11010000
	hsersetup   B9600_8, %0	
	pause 1000	
	upload:		
	bptr=1
	poke fsin,bptr
	bptr=0
	peek mdptr, themode
	poke rtnptr,theMode
	main:	
	hsersetup   B9600_8, %0
	pause 500
	if theMode=0 then:hserout 0,("page 3",QT,$FF,$FF,$FF) 'time and date settings for first power up or loss
	elseif theMode=1 or themode=2 then:hserout 0, ("page 0",QT,$FF,$FF,$FF) 'operation settings for all variables
	elseif themode=6 then: goto error 'clock not set warning page
	endif 		
		peek dyvl,ii 'day selection pointer updated in slots 1&2
		if ii<50 then:ii=50:endif
		poke dyvl,ii
		peek mtvl,auto 'month selection pointer updated in slots 1&2
		if auto>47 then:auto=0:endif
		poke mtvl,auto 		
		hserflag=0
	pick:
	pointer=0:marker=0
		do 	 		
			hserin 0,2 'variable settings and operation selection			 
		if hserflag <>0 then : if hserptr < 2 then: pause 10 : endif :endif: get 0,pointer:get 1,marker			
			select case pointer
			case "Q" if marker="A" then:hserout 0, ("page 1",$FF,$FF,$FF):theMode=1:gosub QTF:gosub HP:goto pick
						else
				hserout 0, ("page 2",$FF,$FF,$FF):theMode=2:gosub QTF:gosub HP:goto pick
				endif 
				case "Z" if marker="X" then goto leave
			case "R" 	if marker="T" then:gosub set_clock:pause 10:goto main:endif 
				case "T"  if marker="M" then:@bptr=1:poke fsin,@bptr:hserout 0,("page 3",$FF,$FF,$FF):themode=0:gosub QTF:gosub HP:goto pick:endif 
				case "A" if marker="L" then:hserout 0,("page 4",$FF,$FF,$FF)themode=1:gosub QTF:gosub HP:goto pick:endif 
				case "H" if marker="P" then:goto pick endif 'removed gosub to fit forum size 
				case "!"  if marker="!" then: theMode=1:poke mdptr,theMode:poke rtnptr,themode:poke fsin,themode:goto leave:endif 
				case "&"  if marker="&" then: theMode=2:poke mdptr,theMode:poke rtnptr,themode:poke fsin,themode:goto leave:endif 
				endselect
			pointer=pointer-65 'converts ascii capitals to 0 1 2 ect for the ongosub
			
			if pointer<11 then
			on pointer gosub n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10
		endif 
			
		gosub QTF
		gosub HP
		pause 10
		debug
		loop	
			
		n0:'"A"
		
		if marker="+" then
			inc vT
		elseif marker="-" then
			dec VT
		elseif marker="^" then
			vT=vT+10
		endif 
		if vT <0 or vT >200 then:vT=0:endif
			hserout 0, ("svt.txt=",QT,#vT)
			
		return
		n1:'"B"
		if marker="+" then
                     	inc vC
			   elseif marker="-" then
				 dec vC
		elseif marker="^" then
			vC=vC+10
			endif
				if vC <0 or vC >200 then:vC=0:endif
				hserout 0, ("svc.txt=",QT,#vC)
				
				return
		n2:'"C"		
				if marker="+" then
                     	inc vHl
			elseif marker="-" then
				 dec vHl
			elseif Marker="^" then
				vhl=vhl+10
			endif
				if vHl <0 or vHl >100 then:vHl=0:endif
				hserout 0, ("svhl.txt=",QT,#vHl)
				
				return
		n3:'"D"
			if marker="+" then
				inc vH
			elseif marker="-" then
				dec vH
			elseif marker="^" then
				vH=vH+10
			endif
				if vH <0 or vH >100 then:vH =0:endif
       			hserout 0, ("svh.txt=",QT,#vH)
				
				return
		n4:'"E"					
		
		if marker="+" then
			inc day
			elseif marker="-" then
				dec day
				elseif marker="E" and day>=1 then 'entre value for clock
				daybcd = day / 10 * 6 + day
				elseif marker="E" and day<=0 then 'if enter pressed before any value 					
					day=1
					daybcd = day / 10 * 6 + day
		endif 
		if day<1 or day>=7 then: day=1:endif
			select case day
			case 1 ii=50
			case 2 ii=54
			case 3 ii=58
			case 4 ii=62
			case 5 ii=66
			case 6 ii=70
			case 7 ii=74
		endselect 
			bptr=ii
		hserout 0, ("day.txt=",QT) 
 			readtable bptr,ii
 			 inc bptr
 			 do until ii = 0
   			 hserout 0, (ii)
    			readtable bptr,ii
     			inc bptr			
	loop	
			poke dyvl,ii
			
			return
		
		n5:'"F"
				
			if marker="+" then
				inc date				 
			elseif marker="-" then
				dec date				
			elseif marker="F" then		
		endif
			'date = datebcd / 16 * $FA + datebcd
		    
		   datebcd=date/10*6+date
			hserout 0, ("date.txt=",QT,#date)
				
		if date<0 or date>=31 then:date=0:endif
			return
		n6: '"G"
			if marker="+" then
				inc month
				elseif marker="-" then
					dec month
					elseif marker="G" and month>=1 then
						monthbcd=month/10*6+month
					elseif marker="G" and month<=0 then
						month=1
						monthbcd=month/10*6+month
					endif 
				if month<1 or month >12 then:month=1:endif 
				select case month
				case 1 auto=0:case 2 auto=4:case 3 auto=8:case 4 auto=12
				case 5 auto=16:case 6 auto=20:case 7 auto=24:case 8 auto=28
			      case 9 auto=32:case 10 auto=36:case 11 auto=40:case 12 auto=44
				endselect
				bptr=auto
				hserout 0, ("mth.txt=",QT) 
 				readtable bptr,auto
 			 	inc bptr
 				do until auto = 0
   				 hserout 0, (auto)
    				readtable bptr,auto
     				inc bptr
				loop				
 				poke mtvl,auto
				
			return
		n7:'"H"
			if marker="+" then
				inc year
			elseif marker="-" then
				dec year
			endif
			if year=0 or year>200 then:year=1:endif
				year=10+year
			hserout 0, ("yr.txt=",QT,"20",#year)
       			year=year-10
				yearbcd = year / 10 * 6 + year
				
		return
		n8:'"I"
		if marker="+" then
				inc hour
			elseif marker="-" then
				dec hour
			endif
			if hour<0 or hour>23 then:hour=0:endif		
			hserout 0, ("hr.txt=",QT,#hour) 
			hourbcd = hour / 10 * 6 + hour
			
			return
		n9:'"J"
			if marker="+" then
				inc mins
			elseif marker="-" then
				dec mins				
			endif
				if mins<0 or mins>59 then:mins=0:endif		
				hserout 0, ("mins.txt=",QT,#mins) 
				minbcd = mins / 10 * 6 + mins
				
				RETURN
		N10:'"K"
			if marker="+" then
				inc fr				           
			elseif marker ="-" then
				 dec fr							
			endif
				if fr <0 or fr >200 then:fr=0:endif
			hserout 0, ("fr.txt=",QT,#fr)
			
		RETURN		
		
		set_clock:		
		themode=3
		debug		
		hsersetup off 'only added to see if commands clash 
		secbcd=$14							
	hi2cout 0, (secbcd,minbcd,hourbcd,daybcd,datebcd,monthbcd,yearbcd,control) ' DS1307 RTC,0,1,2,3,4,5,6,7
	pause 50
	
   	hi2cin 0, (TD0,TD1,TD3,TD4,TD5) 
		if TD0<>secbcd then:themode=6:endif 
	
		if TD1<>minbcd then:themode=6:endif 

		if TD2<>hourbcd then:themode=6:endif 

		if TD3<>daybcd then:themode=6:endif 

		if TD4<>datebcd then:themode=6:endif 

		if TD5<>monthbcd then:themode=6:endif 

	hsersetup   B9600_8, %0 'only added due to hanging
	
		if themode=6 then:hserout 0,("page 9",$FF,$FF,$FF):gosub QTF:gosub HP		
	else
		hserout 0,("page 0",$FF,$FF,$FF):gosub QTF:gosub HP 
		endif	

return
 error:
 	pointer=0:marker=0
 	hsersetup   B9600_8, %0
	hserout 0, ("page 9",$FF,$FF,$FF)
	do		
	get 0,pointer
	get 1,marker
loop until pointer="T" and marker="M"

goto pick

QTF:
		hserout 0,(QT,$ff,$ff,$ff) 'command for nextion
		return
HP:
		hserflag=0
		hserptr=0
		pointer=0
		marker=0
		return

leave:	
		hserflag=0
		peek rtnptr,theMode
		
		if theMode=1 then: Run 1:endif
		if theMode=2 then: Run 2:endif
		if theMode=0 then
			hserout 0,("page 8",$ff,$ff,$ff)
		endif
		
		end
		return
	
		
		
return
regards
john
 

AllyCat

Senior Member
Hi,

..it seems to hang ..... Slots 1 &2 use hsersetup %001 as an interupt for slot 0 with the ds1307 as an event timer for the diffrent sections of the slots
So are you sure that the interrupt routine (and any other code that might be needed) has been downloaded to every slot?

Cheers, Alan.
 

johnlong

Senior Member
Hi Allycat
The other Slots(1,2) are downloaded ok as is slot0 as they have dummy routines writen in them
too see if the display is is updating correctly with the relivent variable
The problem is in the writing of the data to the ds1307 sub routine
after the write it clears the decimel variables (day,date ect) to 0 the same with the BCD variables (daybcd,datebcd,ect)
after the write it does not respond to the touches on the screen
the interupt do --loop until hserflag<>0 seems fine as a press of the menu button responds as expected
and opens slot0 at the menu page ok
It seems the interferance is between the 2 commands hserout and either hi2cin/hi2cout
used . Do I need to introduce pauses to allow the commands to exicute correctly ?
As I thourght commands are exicuted sequensially all the relivent functions of the command would
be completed prior to the program flow moving on.
regards
jo
 

westaust55

Moderator
Do I need to introduce pauses to allow the commands to execute correctly ?
As I thought commands are executed sequentially all the relevant functions of the command would
be completed prior to the program flow moving on.
regards
jo
I do not know for sure, but in the absence of firm information give it a try. Certainly nothing to lose!

Based on what I see in your HSEROUT command transmission data/strings,
try a PAUSE for a duration of say 30 ms to 50 ms (serial data output will be taking around 20 ms at 8 MHz with an X2 part)
 

johnlong

Senior Member
Hi
finaly cracked it change the hi2cin/out to readi2c writei2c the old command
i2cslave %11010000, i2cslow, i2cbyte
removed the hser commands out of the clock write sub and
used the mode to achive the page change in main
It bobs in and out of the diffrent slots without a clitch (so far)
able to change 1 or all variables or non just a quick nip in and out
to see how far it is
So it would seem that there is some conflict between hser and hi2c
:)
regards
john
 

hippy

Technical Support
Staff member
finaly cracked it change the hi2cin/out to readi2c writei2c the old command
i2cslave %11010000, i2cslow, i2cbyte
The new commands generate exactly the same executable code as the old commands so that won't be the change which fixed things.

I do note that in post #4 you have set the PICAXE as an I2C Master, then as an I2C Slave, then use it as if an I2C Master. That is very likely to cause some problems.

Your "error:" routine would also seem to hang indefinitely in most cases.
 

johnlong

Senior Member
Hi Hippy
thanks for that totally misunderstood the addressing structure,
It looked to me that you set the master and then had to set the slave
removed the slave address reverted back to hi2cin/out every thing running fine
regards
john
 
Top