Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20717

BASCOM-AVR : DS1307 RTC : NEWTOPIC

$
0
0
I have used this chip before in other versions of the compiler and it seemed to work. There are 4.7k pullups on the SDA and SCL lines. Vcc=5.0v. Today I go to use it and the following code doesn't work. [code:1:fcffd2969e] '------------------------------------------------------------------------------- ' DS1307.BAS ' shows how to use the ds1307 clock on the STK500 w/ATmega128 on SRTK501 ' TOSC switch on STK501 to XTAL position. ' it also shows the CONFIG CLOCK=USER option '------------------------------------------------------------------------------- $regfile = "m128def.dat" $hwstack = 80 $swstack = 80 $framesize = 160 $crystal = 14745600 ' External Xtal, full swing mode $baud = 115200 ' force Local_SetBaudRate routine to set proper baud rate ' '-----[Serial Port(s)]-------------------------------------------------------- Config Com1 = 115200, Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Open "com1:" For Binary As #1 Waitms 5 $lib "i2c_twi.lbx" ' using hardware I2C/TWI Config Sda = Portd.1 ' define pin names, scl and sda pins Config Scl = Portd.0 ' using hardware I2C, scl=D.0, sda=D.1 i2cinit Config Twic = 100000 'CONFIG TWI will ENABLE the TWI master interface 'configure the date format Config Date = mdy , Separator = - ' ANSI-Format config clock = user 'address of ds1307 Const Ds1307w = &HD0 ' Addresses of Ds1307 clock Const Ds1307r = &HD1 Enable Interrupts ' this will dim the bytes automatic 'dim other needed variables Dim Weekday As Byte Print #1, "DS1307" Waitms 100 ' assigning the time will call the SetTime routine Print #1, "Time" Time$ = "23:58:59" ' to watch the day changing value Print #1, "Date" Date$ = "11-13-02" ' 13 november 2002 Do Print #1, "Date / Time : " ; Date$ ; " / " ; Time$ Waitms 500 Loop End 'called from ds1307clock.lib Getdatetime: print #1, "In Getdatetime" I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 0 ' start address in 1307 I2cstart ' Generate start code I2cwbyte Ds1307r ' send address I2crbyte _sec , Ack I2crbyte _min , Ack ' MINUTES I2crbyte _hour , Ack ' Hours I2crbyte Weekday , Ack ' Day of Week I2crbyte _day , Ack ' Day of Month I2crbyte _month , Ack ' Month of Year I2crbyte _year , Nack ' Year I2cstop _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour) _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year) Return Setdate: print #1, "In Setdate" _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year) I2cstart ' Generate start code I2cwbyte Ds1307w ' send address I2cwbyte 4 ' starting address in 1307 I2cwbyte _day ' Send Data to SECONDS I2cwbyte _month ' MINUTES I2cwbyte _year ' Hours I2cstop Return Settime: print #1, "In Settime" _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour) print #1, "I2Cstart" I2cstart ' Generate start code print #1, "I2Cwrite1" I2cwbyte Ds1307w ' send address print #1, "I2Cwrite2" I2cwbyte 0 ' starting address in 1307 I2cwbyte _sec ' Send Data to SECONDS I2cwbyte _min ' MINUTES I2cwbyte _hour ' Hours I2cstop Return[/code:1:fcffd2969e] I then ran this scanner code and there is no slave detected. I have read posts and datasheets all day. I am obviously missing something. [code:1:fcffd2969e] $regfile = "m128def.dat" $hwstack = 80 $swstack = 80 $framesize = 160 '$crystal = 7372800 ' External Xtal, full swing mode $crystal = 14745600 ' External Xtal, full swing mode '$crystal = 18432000 ' External Xtal, full swing mode $baud = 115200 ' force Local_SetBaudRate routine to set proper baud rate $lib "i2c_twi.lbx" ' using hardware I2C/TWI Config Sda = Portd.1 ' define pin names, scl and sda pins Config Scl = Portd.0 ' using hardware I2C, scl=D.0, sda=D.1 i2cinit Config Twic = 100000 Dim B As Byte Print "Start Scan" For B = 1 To 255 Print b; " "; I2cstart 'Print "I2Cwrite" I2cwbyte B If Err = 0 Then Print "Slave at : " ; B End If I2cstop Next Print "End Scan" do:loop[/code:1:fcffd2969e] TIA, Mark [b:fcffd2969e][color=red:fcffd2969e](BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.7.6 )[/b:fcffd2969e][/color:fcffd2969e]

Viewing all articles
Browse latest Browse all 20717

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>