Hi2cin

cfarr

Member
I am testing the following code on the newly downloaded programming editor v. 5.1.4. When I run the code the simulator displays a syntax error on the first line. Am I doing something wrong? This program is intended to read the time from a DS1307.


hi2csetup i2cslave,%11010000,i2cslow,i2cbyte

main:
hi2cin 0,(b0,b1,b2)
bcdtoascii b0, b12,b13 : serout 6,N2400,(254,128,b12,b13,":")
bcdtoascii b1, b12,b13 : serout 6,N2400,(b12,b13,":")
bcdtoascii b2, b12,b13 : serout 6,N2400,(b12,b13," ")
goto main
 

MORA99

Senior Member
Have you selected the extended editor syntax, and the correct chip in options ?

If you run the syntax check with the wrong chip selected it will give a error.


You can also use a #picaxe line in the start
like
#picaxe 28x1
#picaxe 14m
etc



Edited by - MORA99 on 15/07/2007 18:54:10
 

MORA99

Senior Member
I havent used hi2, but the datasheet says hi2setup with slave does not need the last 2 arguments.

These both passes syntax check
hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte
hi2csetup i2cslave,%11010000

Edited by - MORA99 on 15/07/2007 18:59:33
 

cfarr

Member
OK I have removed the last two arguments and that cleared the problem. However, the simulator than crashes on the hi2cin 0,(b0,b1,b2)line.
 

cfarr

Member
For the time being, thanks for your help. I'll get to the problem later on because I have to leave now.
 

Technical

Technical Support
Staff member
To use hi2cin from a slave chip (e.g. EEPROM or DS1307) you must set the PICAXE chip up as the 'master', not as another 'slave' device. This is because the PICAXE is controlling the bus.

You therefore need this type of syntax

hi2csetup i2cmaster,%1010000,i2cslow,i2cbyte

You only set the PICAXE as a slave when another device on the bus (e.g. another PICAXE) is acting as the master.

Edited by - Technical on 15/07/2007 21:38:24
 

cfarr

Member
Thanks technical for your prompt reply. The code has been changed but the simulator still crashes on the hi2cin 0,(b0,b1,b2)line.

hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte
main:
hi2cin 0,(b0,b1,b2)
bcdtoascii b0, b12,b13 : serout 6,N2400,(254,128,b12,b13,":")
bcdtoascii b1, b12,b13 : serout 6,N2400,(b12,b13,":")
bcdtoascii b2, b12,b13 : serout 6,N2400,(b12,b13," ")
goto main
 

cfarr

Member
Actually I cannot test the code on a 28x1 as I have still to purchase this part. But before migrating to these new version Picaxes, I decided to get acquainted with the new commands using the simulator. Has anyone successfully used the hi2cin command with these devices?
 

Technical

Technical Support
Staff member
There is a bug in the simulator for which we apologise, we will fix in next release. Real chip will work fine.

Under simulation there are options to 'simulate' EEPROM and RTC, so (when the simulator works) you can simulate these chips (ie the value will not be always $FF if these simulation options are enabled).
 

MORA99

Senior Member
I have tested this code today, and it works well on a 28x1 (not simulated).

<code><pre><font size=2 face='Courier'>
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7

; Example of how to use DS1307 Time Clock
; Note the data is sent/received in BCD format.
; Note that seconds, mins etc are variables that need
; defining e.g. symbol seconds = b0 etc.
' set DS1307 slave address
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
'write time and date e.g. to 11:59:00 on Thurs 25/12/03
start_clock:
let seconds = $00' 00 Note all BCD format
let mins = $27' 59 Note all BCD format
let hour = $23' 11 Note all BCD format
let day = $02' 03 Note all BCD format
let date = $16' 25 Note all BCD format
let month = $07' 12 Note all BCD format
let year = $07' 03 Note all BCD format
let control = %00010000 ' Enable output at 1Hz
hi2cout 0,(seconds,mins,hour,day,date,month,year,control)



SerTxd(&quot;Date set&quot;,CR,LF )



</font></pre></code>


<code><pre><font size=2 face='Courier'>
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7

hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte

main:
hi2cin 0,(seconds,mins,hour,day,date,month,year)

bcdtoascii date, b12,b13
SerTxd(b12,b13,&quot;/&quot;)

bcdtoascii month, b12,b13
SerTxd(b12,b13,&quot;-&quot;)

bcdtoascii year, b12,b13
SerTxd(&quot;20&quot;,b12,b13,&quot; &quot;,&quot; &quot;)

bcdtoascii hour, b12,b13
SerTxd(b12,b13,&quot;:&quot;)

bcdtoascii mins, b12,b13
SerTxd(b12,b13,&quot;:&quot;)

bcdtoascii seconds, b12,b13
SerTxd(b12,b13)

SerTxd(CR,LF )

pause 1000
goto main


</font></pre></code>
 
Top