I have DS1307 for real time/calender (RTC) , and need to communicate with this IC thought atmega8 controller .
I read the section of TWI interface in atmega8 datasheet and understand all the instructions to use I2C protocol .
I found a library for GCC-avr :
http://homepage.hispeed.ch/peter...
It has all the function I need and implement the I2C interface operations .
I tried to edit the twimaster.c ... I just wrote additional functions for debugging use and I wrote the main function :
/* until this point twimaster.c except the init_fail() and write_fail() functions which just do some light effects depend on statues . */ void main(){ DDRD |= 0xFF; DDRC |=0x0F; DDRB |=0x7F; unsigned int addr ; addr=0+I2C_WRITE; while(i2c_start(addr)) init_fail() ;// if i2c_start(addr)=1 that means starting is failed . int m=0x40;// the value of Minuit I want to write to DS1307 while(i2c_write(m)) write_fail() ;// if i2c_write(m)=1 that means writing is failed . while(1) { while(i2c_rep_start(addr+I2C_READ)) init_fail(); unsigned char data = i2c_readNak(); if(data==0x40) {// show me somthing on sevent segment PORTC=(1<<PINC3)|(1<<PINC2); PORTB=(1<<PINB5)|(1<<PINB4)|(1<<PINB3)|(1<<PINB2)|(1<<PINB0); PORTD=(1<<PIND6)|(1<<PIND3)|(1<<PIND7); } else{ //failed ? show me another thing on seven segment PORTC=0xDF;} }}
I attached the schematic .
If I have any problem in the schematic you can edit online :
http://upverter.com/yahya%20tawi...
For pull-up resistors I tried to use both 5k2 and 10K .
Any help :) ?
p.s : maybe my code is messy because I still starter in programming micro-controller using raw C , I'm arduino user :)