Yes Mark,
I read all samples, made all forum search of xmega , i2c and made corrections. Full day looking for it.
Also made correction to i2c code by adding extra i2cstop. (which I had never done for 8051)
'My code ...............
$regfile = "xm256d3def.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 64
$framesize = 64
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 ' use 32 MHz
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = Enabled
Enable Interrupts
$lib "xmega.lib"
$external _xmegafix_clear
$external _xmegafix_rol_r1014
Dim Twi_start As Byte
Open "twic" For Binary As #4
Config Twic = 100000
I2cinit #4
'address of ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
Dim _day As Byte , _month As Byte , _year As Byte
Dim _sec As Byte , _min As Byte , _hour As Byte
Gosub Getdatetime
Locate 1 , 1
Lcd "Time = " ; _hour ; ":" ; _min ; ":" ; _sec
end
'---------------
Dim Weekday As Byte
Getdatetime:
I2cstart #4 ' Generate start code
I2cwbyte Ds1307w , #4 ' &HD0 ' send address
I2cwbyte 0 , #4 ' start address in 1307
I2cstop #4
I2crepstart #4 ' Generate start code
I2cwbyte Ds1307r , #4 ' &HD1 ' send address
I2crbyte _sec , Ack , #4
I2crbyte _min , Ack , #4 ' MINUTES
I2crbyte _hour , Ack , #4 ' Hours
I2crbyte Weekday , Ack , #4 ' Day of Week
I2crbyte _day , Ack , #4 ' Day of Month
I2crbyte _month , Ack , #4 ' Month of Year
I2crbyte _year , Nack , #4 ' Year
I2cstop #4
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
'-------------------------------------------------------------------------------------------
Please help. If I am not able to work a simple i2c clock, how will write bigger code in AVR BASCOM ?
Regards,
Devidas
↧