Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

DS1307
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Sat May 20, 2017 8:21 pm    Post subject: DS1307 Reply with quote

HI ALL!! Very Happy Very Happy

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

Rolling Eyes Rolling Eyes Crying or Very sad
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2113

netherlands.gif
PostPosted: Sat May 20, 2017 9:12 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Sun May 21, 2017 2:37 am    Post subject: Reply with quote

Evert Smile 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? Laughing Laughing
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Sun May 21, 2017 4:33 pm    Post subject: Reply with quote

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

 


Laughing Laughing Laughing
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon May 22, 2017 1:43 pm    Post subject: I2c scan Reply with quote

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
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 692

poland.gif
PostPosted: Mon May 22, 2017 2:18 pm    Post subject: Reply with quote

It back everytime to the same date and time because of this code:
Code:
'setup date
_day = 20
_month = 5
_year = 17
Gosub Setdate

'Setup time
_sec = 00
_min = 12
_hour = 16
Gosub Settime


Set time once and then remove or remark this code. Then compile and program microcontroller again.
So microcontroller without this part of code will not set date and time back.


Solution for comfortable setting date and time is made some Menu but this can be dificult to You if you ask about this simple "issue" Very Happy

Try at first to read (with understanding) some example codes from Bascom sample folder. Try also forum searchengine.
Some book or even Google know the answears for these basic questions Very Happy
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Tue May 23, 2017 5:12 am    Post subject: Re: I2c scan Reply with quote

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
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Tue May 23, 2017 5:17 am    Post subject: Reply with quote

EDC wrote:
It back everytime to the same date and time because of this code:
Code:
'setup date
_day = 20
_month = 5
_year = 17
Gosub Setdate

'Setup time
_sec = 00
_min = 12
_hour = 16
Gosub Settime


Set time once and then remove or remark this code. Then compile and program microcontroller again.
So microcontroller without this part of code will not set date and time back.


Solution for comfortable setting date and time is made some Menu but this can be dificult to You if you ask about this simple "issue" Very Happy

Try at first to read (with understanding) some example codes from Bascom sample folder. Try also forum searchengine.
Some book or even Google know the answears for these basic questions Very Happy


I'm reading help on Bascom i2c and I confirm EDC !! Shocked
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue May 23, 2017 8:32 am    Post subject: Pull ups? Reply with quote

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
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Tue May 23, 2017 11:47 am    Post subject: Reply with quote

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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue May 23, 2017 1:19 pm    Post subject: Out of ideas... Reply with quote

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
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Tue May 23, 2017 9:06 pm    Post subject: Re: Out of ideas... Reply with quote

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. Wink
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Wed May 24, 2017 5:08 am    Post subject: Reply with quote

EDC wrote:
It back everytime to the same date and time because of this code:
Code:
'setup date
_day = 20
_month = 5
_year = 17
Gosub Setdate

'Setup time
_sec = 00
_min = 12
_hour = 16
Gosub Settime


Set time once and then remove or remark this code. Then compile and program microcontroller again.
So microcontroller without this part of code will not set date and time back.


Solution for comfortable setting date and time is made some Menu but this can be dificult to You if you ask about this simple "issue" Very Happy

Try at first to read (with understanding) some example codes from Bascom sample folder. Try also forum searchengine.
Some book or even Google know the answears for these basic questions Very Happy


With the code when compiling the program will update the time but when I turn off my STK500 restarts again with the same time 16:12:00 ok !!

Code:
'setup date
_day = 20
_month = 5
_year = 17
Gosub Setdate

'Setup time
_sec = 00
_min = 12
_hour = 16
Gosub Settime


Now without this code as my friend says EDC when compile will update the time but every time it is restarted, the time is not erased .... ok !!

Code:
'setup date
'_day = 20
'_month = 5
'_year = 17
'Gosub Setdate

'Setup time
'_sec = 00
'_min = 12
'_hour = 16
'Gosub Settime


Until then we are going well !! I am still reading with the help bascom i2c protocol is very difficult for me. Shocked Shocked
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 223
Location: D.F.

mexico.gif
PostPosted: Wed May 24, 2017 3:14 pm    Post subject: Re: I2c scan Reply with quote

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


I have read and seen the code but I am very happy !!
Disable these:


Code:
'$lib "i2c_twi.lbx"                                          ' we do not use software emulated I2C but the TWI



I already detected slave of the scanner. Very Happy Very Happy Very Happy
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Wed May 24, 2017 5:29 pm    Post subject: Happy? Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum