Author Topic: ds1307 in assembly  (Read 3818 times)

0 Members and 1 Guest are viewing this topic.

Offline Toruk.maktoTopic starter

  • Newbie
  • Posts: 4
ds1307 in assembly
« on: February 12, 2014, 11:39:11 am »
i want drive a ds1307 with ATmega32 in assembly

(ATmega32 works in 8 MHZ internal oscillator mode)

i use this simple program for drive ds1307 and its not working ...

leds randomly turn on and off

the purpose of this program is first send primary Values to ds1307

(second/minute/hour/day/month/year)

and then reading second and send it to porta.(to show on leds)

would you please correct this program or write another simple

program like this one

(i am beginner in assembly and i searched internet and found nothing )

attention: this mode i used in my program called hardware i2c mode which is used pc0 and pc1 as scl and sda and use registers like twbr/ /twsr/twcr/twdr

the program:
http://www.mediafire.com/view/q2jvdprp4u3micz/ds1307+.asm

schematic:
http://img4u.ir/upload/427ds1307+.JPG
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2034
  • Country: au
Re: ds1307 in assembly
« Reply #1 on: February 12, 2014, 12:09:21 pm »
does the 1307 have Vcc and ground?

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ds1307 in assembly
« Reply #2 on: February 12, 2014, 12:10:10 pm »
Quote
(i am beginner

My advice to you: learn to program in C, if you are a beginner. Assembly is useful if you are dedicated to doing simple things or you are very experienced and have lots of time / money.
================================
https://dannyelectronics.wordpress.com/
 

Offline Toruk.maktoTopic starter

  • Newbie
  • Posts: 4
Re: ds1307 in assembly
« Reply #3 on: February 12, 2014, 03:13:32 pm »
does the 1307 have Vcc and ground?

of course had  |O
 

Offline Lajon

  • Contributor
  • Posts: 31
  • Country: se
Re: ds1307 in assembly
« Reply #4 on: February 12, 2014, 04:54:13 pm »
Comparing your
;-------------------reading second from ds1307 and send to porta

          call  delay
main:     call  i2c_init
          call  i2c_start
          ldi   r16,208
          call  i2c_send
          call  i2c_start
          ldi   r16,209
          call  i2c_send
          ldi   r16,0x00
          call  i2c_send
          in    r18,twdr
          out   porta,r18
          call  i2c_stop
          call  delay_1sec
          rjmp main

with Arduino lib I googled it appears that you are not doing the reading correctly. The 0 (which is for selecting register 0 in the DS1307) should be part of the write sequence.

  WIRE.beginTransmission(DS1307_ADDRESS);
  WIRE.write(0);   
  WIRE.endTransmission();

  WIRE.requestFrom(DS1307_ADDRESS, 7);
  uint8_t ss = bcd2bin(WIRE.read() & 0x7F);

/Lars
 

Offline Toruk.maktoTopic starter

  • Newbie
  • Posts: 4
Re: ds1307 in assembly
« Reply #5 on: February 13, 2014, 01:39:55 pm »
Comparing your
;-------------------reading second from ds1307 and send to porta

          call  delay
main:     call  i2c_init
          call  i2c_start
          ldi   r16,208
          call  i2c_send
          call  i2c_start
          ldi   r16,209
          call  i2c_send
          ldi   r16,0x00
          call  i2c_send
          in    r18,twdr
          out   porta,r18
          call  i2c_stop
          call  delay_1sec
          rjmp main

with Arduino lib I googled it appears that you are not doing the reading correctly. The 0 (which is for selecting register 0 in the DS1307) should be part of the write sequence.

  WIRE.beginTransmission(DS1307_ADDRESS);
  WIRE.write(0);   
  WIRE.endTransmission();

  WIRE.requestFrom(DS1307_ADDRESS, 7);
  uint8_t ss = bcd2bin(WIRE.read() & 0x7F);

/Lars

iwrite the code like this:

 call  delay
main:    call  i2c_init
          call  i2c_start
          ldi   r16,208
          call  i2c_send
          ldi   r16,0x00
          call  i2c_send
          call  i2c_start
          ldi   r16,209
          call  i2c_send
          in    r18,twdr
          out   porta,r18
          call  i2c_stop
          call  delay_1sec
          rjmp main

and then 0xD1 (or 209) appears on port A and its not changed never.  :-//
 

Offline Toruk.maktoTopic starter

  • Newbie
  • Posts: 4
Re: ds1307 in assembly
« Reply #6 on: February 14, 2014, 09:43:24 am »
i find the problem code must be write like this:

          call  delay
main:     call  i2c_init
          call  i2c_start
          ldi   r16,208
          call  i2c_send
          ldi   r16,0
          call  i2c_send

          call  i2c_start
          ldi   r16,209
          call  i2c_send
          ldi   r16,0x00
          call  i2c_send

          in    r18,twdr
          out   porta,r18
          call  i2c_stop
          call  delay_1sec
          rjmp main
 :-+

 

Offline uwezi

  • Supporter
  • ****
  • Posts: 272
  • Country: se
    • GreenPhotons
Re: ds1307 in assembly
« Reply #7 on: February 18, 2014, 10:43:48 pm »
I spend hours and hours on a batch of DS1307 which I had bought on eBay from China for a student lab.

Some worked for a short time, then became hot - almost letting the gray smoke come out which drives then. Other did never work at all. :-BROKE

Running the same, exact same code on legitimate DS1307 from a commercial reseller in Sweden worked flawlessly!  :-DMM


It really took me a while to realize that I must have gotten counterfeit chips.  :palm:

I was pulling all strings on possible circuit and software errors, tried my own I2C code and two or three external libraries. Replaced the crystals a dozen times, checked the battery connection, changed the battery, replaced the battery with a diode-circuit to fake the battery voltage... |O
 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf