View previous topic :: View next topic |
Author |
Message |
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Sat May 20, 2017 8:21 pm Post subject: DS1307 |
|
|
HI ALL!!
I have connected SDA (DS1307) with atmega8A SDA (portc.4) and SCL (DS1307) with atmega8A SCL (portc.5) with both connected and check connections well and battery at 3 volts and with $ lib file "ds1307clock.lib "And I am using bascom compiler 2.0.7.5.
Why do I get LCD?
= 1 / = 1 / = 1
= 1: = 1 /: = 1
|
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sat May 20, 2017 9:12 pm Post subject: |
|
|
Hard to say without any code.
Try first the bascom i2cscan.bas sample from your Bascom sample directory to see if your i2c hardware is working.
If that's working try get "Helllo Evert" on your display. If that is also working combine both samples.
If it's still not working show some code _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Sun May 21, 2017 2:37 am Post subject: |
|
|
Evert wrote: | Hard to say without any code.
Try first the bascom i2cscan.bas sample from your Bascom sample directory to see if your i2c hardware is working.
If that's working try get "Helllo Evert" on your display. If that is also working combine both samples.
If it's still not working show some code |
There is no example bascom directory because it is demo.
I already solved missing GND and VCC connect it DS1307 already works and works well.
When you cut back to the beginning is normal? Do you miss connecting eprom?
Code: | $regfile = "m16adef.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
$lib "ds1307clock.lib"
$lib "i2c_twi.lbx"
Config Sda = Portc.1
Config Scl = Portc.0
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdpin = Pin , E = Portb.1 , Rs = Portb.0
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3
Config Lcdpin = Pin , Db6 = Portb.4 , Db7 = Portb.5
Cursor Off Noblink
Config Clock = User ' 1307 klok
Config Date = Dmy , Separator = -
Dim _date As Byte
Dim Ds1307w As Byte
Dim Ds1307r As Byte
Dim Weekday As Byte
Ds1307w = &B11010000
Ds1307r = &B11010001
'setup date
_day = 20
_month = 5
_year = 17
Gosub Setdate
'Setup time
_sec = 00
_min = 12
_hour = 16
Gosub Settime
Do
Locate 1 , 1
Lcd "Hora:"
Locate 1 , 9
Lcd Time$
Locate 2 , 1
Lcd "Fecha:"
Locate 2 , 9
Lcd Date$
Loop
End
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
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:
_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 |
How do I do it when the time is not cleared? |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Sun May 21, 2017 4:33 pm Post subject: |
|
|
When I turn off my TK500 and then turn on my TK500, it goes back to the beginning, why?
DS1307 already includes eproom?
The batteries are fine by now.
Do I have to configure these?
Code: | Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
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:
_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
|
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue May 23, 2017 5:12 am Post subject: Re: I2c scan |
|
|
bzijlstra wrote: | https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10729&highlight=i2cscan
Here you can find the i2c scanner. Perhaps you have to change things like regfile, crystal, config sda en slk. Perhaps you can run this to check if you see your ds1307 is seen on the i2c bus before.
Could you please check it. And let us know?
Have fun
Ben Zijlstra |
Hi Ben!!
Now compile the i2c scanner. But I get all zero in variable B?
Code: | $Regfile="m16adef.dat"
$Crystal=4000000
$hwstack=40
$swstack=16
$framesize=32
$sim
$baud = 19200 ' baud rate
Dim B As Byte
Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name
'we use the TWI pins of the Mega88
$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI
Print "Scan start"
For B = 0 To 254 Step 2 'for all odd addresses
I2cstart 'send start
I2cwbyte B 'send address
If Err = 0 Then 'we got an ack
Print "Slave at : " ; B ; " hex : " ; Hex(b) ; " bin : " ; Bin(b)
End If
I2cstop 'free bus
Next
Print "End Scan"
End |
Are you correct the code?
Code: | Print "Slave at : " ; B ; " hex : " ; Hex(b) ; " bin : " ; Bin(b) |
It came out like this.
[img][/img] |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue May 23, 2017 8:32 am Post subject: Pull ups? |
|
|
Google for the connection of the DS1307. There should be a pull up on sda and sclk.
Could you confirm that?
Ben Zijlstra |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue May 23, 2017 11:47 am Post subject: |
|
|
Before I had them connected VCC and GND with atmega8 and I replaced with atmega16.
I have them well connected as you are the scheme.
[img][/img]
I'm researching these with bascom and forum help.
Code: | I2cwbyte 0 ' start address in 1307 |
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue May 23, 2017 1:19 pm Post subject: Out of ideas... |
|
|
I can't see anything wrong in the hardware around the ds1307. But as long as the i2c scanner doesn't see the ds1307 it can not work with it. So you got to get that working first.
I see a lot of discussion from you in this forum about the ds1307 in the year 2014. Is this some of your unfinished projects?
Perhaps somebody else got an idea.
Ben Zijlstra |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Tue May 23, 2017 9:06 pm Post subject: Re: Out of ideas... |
|
|
bzijlstra wrote: | I can't see anything wrong in the hardware around the ds1307. But as long as the i2c scanner doesn't see the ds1307 it can not work with it. So you got to get that working first.
I see a lot of discussion from you in this forum about the ds1307 in the year 2014. Is this some of your unfinished projects?
Perhaps somebody else got an idea.
Ben Zijlstra |
It is an exercise nothing more but I have many to learn and for DS1307 I will do a programmable timer project. |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Wed May 24, 2017 5:29 pm Post subject: Happy? |
|
|
You make it very difficult for me. An i2c scanner scans the i2c bus and should display all i2c devices on the bus it finds. Your ds1307 occupies two addresses on hex(D0) and hex(D1. So you should see only that single device.
You are talking about 'Research', I suggest you read some more on the working of i2c. The help of Bascom is very clear on this. In 2014 you were struggeling with the same problem.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
|