byatin
Joined: 26 Oct 2006 Posts: 10 Location: delhi -india
|
problem with running i2c |
Posted: Thu Nov 09, 2006 10:57 pm |
|
|
hi, i am having a problem with running an ds1307 driver through i2c interface.
the time i am reading from the ds1307 is displaying on the lcd, but there is some garbage values coming on the lcd.
the hardware i have crosschecked is correct
the pins that are reserved for the i2c are B0 and B1 but I am using some other pins ,can this be the problem.
below is the code , i am using.
#use i2c(Master,Slow,sda=PIN_E2,scl=PIN_E1)
in main :---
i2c_bus_byte_write(0xD0,0x00,0x00);
i2c_bus_byte_write(0xD0,0x00,0x01);
i2c_bus_byte_write(0xD0,0x01,0x02);
i2c_bus_byte_write(0xD0,0x01,0x03);
i2c_bus_byte_write(0xD0,0x01,0x04);
i2c_bus_byte_write(0xD0,0x01,0x05);
i2c_bus_byte_write(0xD0,0x01,0x06);
i2c_bus_byte_write(0xD0,0x97,0x07);
while(1)
{
sec = i2c_bus_byte_read(0xd0,0x00); // REG 1
min = i2c_bus_byte_read(0xd0,0x01); // REG 1
hrs = i2c_bus_byte_read(0xd0,0x02); // REG 5
sec1 = (sec & 0x0f);
sec2 = (sec & 0xf0);
min1 = (min & 0x0f);
min2 = (min & 0xf0);
hrs1 = (hrs & 0x0f);
hrs2 = (hrs & 0xf0);
set_address(0x80);
datawrt(sec1);
datawrt(sec2);
datawrt(min1);
datawrt(min2);
datawrt(hrs1);
datawrt(hrs2);
}
function definations :---
void i2c_bus_byte_write(unsigned char device,unsigned char dat,unsigned char address)
{
i2c_start();
i2c_write(0xD0);
i2c_write(address);
i2c_write(dat);
i2c_stop();
}
unsigned char i2c_bus_byte_read(unsigned char device,unsigned char address)
{
unsigned char i;
i2c_start();
i2c_write(device & 0xfe);
i2c_write(address);
i2c_start();
i2c_write(device | 0x01);
i=i2c_read();
i2c_stop();
return(i);
} |
|