CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with running i2c

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
byatin



Joined: 26 Oct 2006
Posts: 10
Location: delhi -india

View user's profile Send private message Send e-mail

problem with running i2c
PostPosted: Thu Nov 09, 2006 10:57 pm     Reply with quote

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);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 10, 2006 1:07 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=20308&start=2&highlight=nak
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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


Powered by phpBB © 2001, 2005 phpBB Group