Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Software I2C Clock Rate

Status
Not open for further replies.

Suraj143

Active Member
Guys I'm using nigels I2C routine & it works fine.But I want to know what its clock rate? Is it 400Khz? 100KHz?
Osc = 4Mhz

Code:
I2C_Out:                        ; send w register on I2C bus
            movwf     OutputByte
            movlw     0x08
            movwf     _N
Out_Bit:
            bcf     STATUS,    C        ; clear carry
            rlf     OutputByte, F    ; left shift, most sig bit is now in carry
            btfss     STATUS, C        ; if one, send a one
            goto     Out_Zero
            goto     Out_One

Out_Zero:
            call     LOW_SDA            ; SDA at zero
            call     Clock_Pulse   
            call     HIGH_SDA
            goto     Out_Cont

Out_One:
            call     HIGH_SDA        ; SDA at logic one
            call     Clock_Pulse
Out_Cont:
            decfsz     _N,    F            ; decrement index
            goto     Out_Bit
            return   


;=============
HIGH_SDA:                            ; high impedance by making SDA an input
            bsf     STATUS, RP0        ; bank 1
            bsf     I2C_TRIS, SDA    ; make SDA pin an input
            bcf     STATUS, RP0        ; back to bank 0
            return

LOW_SDA:
            bcf     I2C_PORT, SDA   
            bsf     STATUS, RP0        ; bank 1
            bcf     I2C_TRIS, SDA    ; make SDA pin an output
            bcf     STATUS, RP0        ; back to bank 0
            return

Clock_Pulse:                        ; SCL momentarily to logic one
            call     HIGH_SCL
            call     LOW_SCL
            return
 
The clock pulse takes approx 20 cycles at 1MHz and so the rate is approx 50kHz.

Mike.
 
Thank you very much I understood.

The reason I asked I'm reading time from DS1307. Every 1 second I'm reading Seconds,Minutes,Hours.The time lags after 1 week on....The crystals & hardware all ok. But the drift is there.Just guessing repeatedly reading the DS1307 cause problems?
 
Repeated reading won't cause a problem. However, whenever you write to the registers the fraction of seconds gets reset.

Mike.
 
The crystals & hardware all ok. But the drift is there.Just guessing repeatedly reading the DS1307 cause problems?
Crystal placement is paramount to get accuracy on these devices.. The datasheet shows how to screen the crystal..
 
Guys I'm using nigels I2C routine & it works fine.But I want to know what its clock rate? Is it 400Khz? 100KHz?
Osc = 4Mhz

I've no idea - it's no specific frequency, as it doesn't matter.

The time problem is down to the DS1307, nothing to do with I2C - it may just need the trimmer capacitor adjusting correctly?.

I would suggest using the far superior DS3231 instead, and get one of the cheap ready made modules rather than building it yourself..
 
Guys I have a question.

I'm reading DS1307 with software I2C.I2C clock rate is 50KHz.I'm reading 3 bytes from DS1307 (Seconds,Minutes,Hours).

Want to know how many time will it take to read 3 bytes?

Thanks.
 
You can read approx 5,000 bytes per second or 1 byte every 0.2mS. To read 3 bytes takes about 1mS after taking into account writing device address etc.

Mike.
 
You can read approx 5,000 bytes per second or 1 byte every 0.2mS. To read 3 bytes takes about 1mS after taking into account writing device address etc.

Mike.

Thank you very much.I asked because I'm multiplexing my display on ISR every 2.5mS rate.From here I counting 1Sec & set a flag to read RTC. So every time in the main routine I check this flag & if it sets read the 3 bytes from DS1307. I'm not disabling the GIE while reading this I2C routines.My clock increases 10 seconds every day :(
 
Have you tried leaving the chip alone for a day? Add a push button and only read and display the time when the button is pressed. Press the button and check it 24 hours later. If the time is correct then the problem is software, if not correct then it's hardware. Positioning and screening of the crystal is very important.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top