AX033 i2c problem

Gazar94

New Member
I am using a picaxe 14m2 chip and a Serial LCD display (AXE033) with a clock upgrade

I have the chip in i2c mode and am trying to set the time and then display it on the LCD display

This is what I have so far

Code:
goto setup
goto main
main:
	gosub readtime
	gosub displaytime
	debug
	pause 100
	goto main


setup:
	pause 500 ‘ wait for display to initialise
	hi2csetup i2cmaster,$C6,i2cslow,i2cbyte
	symbol seconds = b0
	symbol mins = b1
	symbol hour = b2
	symbol day = b3
	symbol date = b4
	symbol month = b5
	symbol year = b6
	symbol control = b7
	
		; set DS1307 slave address
	
		i2cslave %11010000, i2cslow, i2cbyte

		; Initialise the clock - "Thu 2003-12-25 11:59:00" 

		let day     = $02	; 03 Note all BCD format
		let year    = $12	; 03 Note all BCD format
		let month   = $04	; 12 Note all BCD format
		let date    = $25	; 25 Note all BCD format
		let hour    = $12	; 11 Note all BCD format
		let mins    = $02	; 59 Note all BCD format
		let seconds = $00	; 00 Note all BCD format
 		let control = %00010000 ; Enable output at 1Hz

		writei2c 0,(seconds,mins,hour,day,date,month,year,control)
		
		goto main
		
readtime:
	; Read the clock time

	readi2c 0,(seconds,mins,hour,day,date,month,year)
	
	; Report time read


	pause 500
	debug
	goto displaytime


displaytime:
	hi2cout 0,(254,128,255) ‘ move to start of first line
	pause 10
	hi2cout 0,(seconds,mins,hour,day,date,month,year,control,255)
	goto readtime

[code][/COLOR]

The clock does not appear to count on the debugger and there is nothing displayed on the LCD. Is the code correct?

Thanks for your help
 

nick12ab

Senior Member
The code is not correct. You're not setting the slave address back to the AXE033 address after setting the DS1307 slave address.

Also you shouldn't mix i2cslave and hi2csetup - always use hi2csetup on newer parts as it will make the code easier to follow and easier to search for i2c-based commands.
 

westaust55

Moderator
With respect to the use of i2cslave/i2cwrite/i2cread versus hi2csetup/hi2cout/hi2cin, the first commands were primarily used with the earlier PICAXE chips pre the X1 parts.
The newer hi2csetup/hi2cout/hi2cin commands are based upon the hardware i2c/SPI comms module built into the underlying PIC chip which is available on X1/X2 and M2 parts.

However the older commands while deprecated are still accepted and the Programming Editor will perform the translation to the hardware commands in the background for you.
That said it is good to be consistent.

It may be time for Rev Ed to update the i2c tutorial (based on the AXE110) and the Programming Editor wizard for the AXE110 RTC setting as these are both presently still using the older commands.

Before each access to read from or write the DS1307 RTC you need:
hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte ; Slave adddress $D0

Before access for the AXE033 display you need
hi2csetup i2cmaster,%11000110,i2cslow,i2cbyte ; Slave adddress $C6
 

Gazar94

New Member
ok thanks for that my code now looks like this is this correct?

Code:
goto setup
goto main
main:
    gosub readtime
    gosub displaytime
    debug
    pause 100
    goto main


setup:
    pause 500 ‘ wait for display to initialise
    hi2csetup i2cmaster,$C6,i2cslow,i2cbyte
    symbol seconds = b0
    symbol mins = b1
    symbol hour = b2
    symbol day = b3
    symbol date = b4
    symbol month = b5
    symbol year = b6
    symbol control = b7
    
        ; set DS1307 slave address
    
        i2cslave %11010000, i2cslow, i2cbyte

        ; Initialise the clock - "Thu 2003-12-25 11:59:00" 

        let day     = $02    ; 03 Note all BCD format
        let year    = $12    ; 03 Note all BCD format
        let month   = $04    ; 12 Note all BCD format
        let date    = $25    ; 25 Note all BCD format
        let hour    = $12    ; 11 Note all BCD format
        let mins    = $02    ; 59 Note all BCD format
        let seconds = $00    ; 00 Note all BCD format
         let control = %00010000 ; Enable output at 1Hz
        hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte ; Slave adddress $D0
        writei2c 0,(seconds,mins,hour,day,date,month,year,control)
        
        goto main
        



readtime:

    ; Read the clock time
    hi2csetup i2cmaster,%11010000,i2cslow,i2cbyte ; Slave adddress $D0
    readi2c 0,(seconds,mins,hour,day,date,month,year)
    
    ; Report time read



    pause 500
    debug
    goto displaytime




displaytime:
    hi2csetup i2cmaster,%11000110,i2cslow,i2cbyte ; Slave adddress $C6
    hi2cout 0,(254,128,255) ‘ move to start of first line
    pause 10
    hi2csetup i2cmaster,%11000110,i2cslow,i2cbyte ; Slave adddress $C6
    hi2cout 0,(hour,mins,seconds,day,date,month,year,control,255)
    goto readtime
but my display is showing a range or symbols that seem to be counting do I need to 'decode' it in some way?
is it to do with ascii code or bcd format or something else?
 
Last edited by a moderator:

nick12ab

Senior Member
but my display is showing a range or symbols that seem to be counting do I need to 'decode' it in some way?
is it to do with ascii code or bcd format or something else?
This should work better:
Code:
bcdtoascii hour,b10,b11
bcdtoascii b12,b13
'Repeat bcdtoascii for each variable
hi2cout 254,(128,b10,b11,":",b12,b13,":",b14,b15," ",#day," ",b16,b17,"/",b18,b19,"/",b20,b21,control,255)
 

Technical

Technical Support
Staff member
Your final
Code:
 needs a backslash

You don't need both hi2csetup and i2cslave commands. 
Just use one hi2csetup each time you need to talk to the LCD, and then another for the rtc. Delete all i2cslave.
 
Top