Hi,
This is not a general I2C communication flow chart.
It as a dedicated DS1307 I2C communication.
Thus please refer to the DS1307 datasheet. There are three figures (4, 5 and 6). Please say which one you want to implement. Then compare them step by step with your flow chart.
Thanks for encourage me to make flow chart. There are the different opinion in every link I will look each problem step by stepHi,There are mistakes. But you did a good job. Drawing the flow chart is the best way to really understand the interface.
.
I saw datasheet and I am making flow chart for figure 9Your flowchart is wrong. It generates new start with register address, however start has to be send exclusively before the slave address.
I suggest to refer to the original Philips/NXP I2C specification. **broken link removed**
I have modified flow chart according to figure 6Hi,
How I´d check it step by step:
Klaus
Hi,
How I´d check it step by step:
Klaus
Hi,
Reading an 8 bit wide "data" byte is similar to
outputting an 8 bit "word address" or sending the 8bit "slave address + R/W".
it is a loop running 8 times per byte: like this.
Klaus
#include<stdio.h>
int main(void)
{
int array[8]= {5, 4, 6, 8, 9, 7, 8, 8};
int *pointer = &array[0];
int i;
for( i = 0; i < 8; i++ )
printf("\n Array[%d] is %d ",i,*(pointer+i));
for( i = 0; i < 8; i++)
printf("\n %d at %u ",*(pointer+i),(pointer+i));
return 0;
}
I´can read a bit, but can't write at all....I am not very good at Embedded c programming.
Hi,
you forgot about ACK after each byte.
I now marked it red in my post#9
Please read the recommended documents.
Klaus
I understand I am making flow chart to understand basic first. Once I complete flow chart then I will try to convert it into programHi,
I´can read a bit, but can't write at all....
Klaus
Correct, except for: You are reading 9 bytes instead of 8. And you miss to generate the NACK after last byte.
Then I would try next step. I have to write code for each box in flow chartLooks good now
SDA PIN1
SCL PIN2
define High 1
define Low 0
void Generate_I2C_Start (); //Declare the function
void Generate_I2C_Stop (); //Declare the function
void main (void) //start from here
{
while (1) //infinite Loop
{
Generate_I2C_Start (); //generate i2c start conditions
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 // assumed state before start SDA = Z; SCL = Z; // Generate start SDA = 0; delay; SCL = 0; delay;
Hi FvM,Which processor are you working with?
Driving SCL or SDA to high level is done by tri-stating the port pin. Except for peripherals with open drain pin like 8051 this needs programming the direction register.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 #define SDA P2_1 /* Set P2.1 = SDA */ #define SCL P2_2 /* Set P2.2 = SCL */ define High 1 define Low 0 void I2C_Initialize (void) //Declare the function void I2C_Delay (N) //Declare the function void Generate_I2C_Start (); //Declare the function void Generate_I2C_Stop (); //Declare the function void main (void) //start from here { while (1) //infinite Loop { I2C_Initialize (); // idle sate is: SCL = 1 and SDA = 1 Generate_I2C_Start (); //generate i2c start conditions } } // This function give N nuber of delay void I2C_Delay(int N) { unsigned int i; for( i= 0; i < N; i++); } // Initialize idle sate is: SCL = 1 and SDA = 1 void I2C_Initialize (void) { SCL = 1 // set SCL pin to High SDA = 1 // Set SDA pin to High } //generate i2c start conditions void Generate_I2C_Start (void) { SDA = Low; // Clear SDA Pin I2C_Delay(2); //Required delay SCL = Low; // Clear SCL Pin I2C_Delay(2); //Required delay }
To prevent you from the most often made I2C implementation mistake:
Mind: I2C never sets an output HIGH. A HIGH is generated by an external pullup resistor and the I/O set to HIGH_IMPEDANCE.
Valid output states: DRIVE_LOW or HIGH_IMPEDANCE.
* Before performing an "I2C_START" be sure that the bus is in idle sate. If it is not in idle state: perform an "I2C_STOP" before the "I2C_START"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?