This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using DS1307 RTC facing return acknowledge problem

i am using RTC DS1307 i started coding it as per the datasheet.but when i started my Write subroutine in which i have to get the ACK from RTC for successful writting of the address, it is not sending me the ack signal.

the related code is

#include <c8051f340.h>
#include <intrins.h>
#include <stdio.h>

void I2C_Start();
void I2C_Stop();
void I2C_Write(char byte);

sbit SDA = P0^6;
sbit SCL = P0^7;

void I2C_Start()
{
        SCL = 1;

        SDA = 1;
        _nop_();
        SDA = 0;
        _nop_();
}

void I2C_Stop()
{
        SCL = 1;

        SDA = 1;
        _nop_();
        SDA = 0;
        _nop_();
}


void I2C_Write(char byte)
{
        char x = 8;
        char i2cOut;
        bit ACK;

        i2cOut = byte ;
        SCL = 0;

        for (x = 1; x <= 8; x++)
        {
                SDA = i2cOut^7;
                SCL = 1;
                i2cOut = _crol_(i2cOut,1);
                SCL = 0;
        }

        ACK = SDA;

        SCL = 1;

        if(ACK = 0)
        {
        SCL = 0;
        }
        else
        {
        printf("NO ACK From RTC\n");
        }

}

main code where they are called

#include <c8051f340.h>
#include "UART0.H"
#include <intrins.h>
#include <stdio.h>
#include "I2C.h"



/***************************************************************** * *Main code *****************************************************************/ void main() { unsigned char sec, min, hr, dy, dt, mn, yr;
PCA0MD &= ~0x40; // Disable Watchdog OSCICN |= 0x03; // SYSCLK derived from Internal H-F Oscillator divided by 1. PORT_Init(); UART0_Init();
IE = 0x10; // Enable UART0 interrupt EA = 1; // Enable Interrupts
UART0_Clr();
printf("WELCOME TO RTC ROUTINE\n");
I2C_Start(); /* The following Enables the Oscillator */ I2C_Write(0xD0); /* address the part to write */ I2C_Write(0x00); /* position the address pointer to 0 */ I2C_Write(0x00);/* write 0 to the seconds register, clear the CH bit */ I2C_Stop();
printf("Enter the year (0-99): "); scanf("%bx", &yr);
printf("Enter the month (1-12): "); scanf("%bx", &mn);
printf("Enter the date (1-31): "); scanf("%bx", &dt);
printf("Enter the day (1-7): "); scanf("%bx", &dy);
printf("Enter the hour (1-23): "); scanf("%bx", &hr); hr = hr & 0x3f; /* force clock to 24 hour mode */
printf("Enter the minute (0-59): "); scanf("%bx", &min);
printf("Enter the second (0-59): "); scanf("%bx", &sec);
while(1){ //disp_clk_regs(0x99); } }

PLease help with this,

the hardware connection are ok, i have checked it.

i not figuring out where is the error.

0