I2C communication question

JohnInTX

Joined Jun 26, 2012
4,787
First, please just trace the flow as I asked in #99 after the EDIT. We can not proceed until you do that.
 
Last edited:

Thread Starter

Gajyamadake

Joined Oct 9, 2019
310
First, please just trace the flow as I asked in #99 after the EDIT. We can not proceed until you do that.
I have fixed a all mistakes in flow chart. I have spent a so much time on flow chart so I hope this flow chart would be correct

C:
#define SlaveAddress   0xD1
 
int main()   
{   
  unsigned char P;
  unsigned ByteCount = 9;
  unsigned char RegisterAddress [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8} ; // 9 bytes register address stored into array
 
  P = I2C_Readbyte (SlaveAddress, unsigned int ByteCount, RegisterAddress);
 
  return 0;   
}
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
*sigh*
I have fixed a all mistakes in flow chart.
No, you haven't. You have introduced a new flow chart with new mistakes.
  • It is named incorrectly - the routine is actually recursive now because it is named I2C_ReadByte and you call I2C_ReadByte in step 7. Big problem caused by sloppy work.
  • It always reads one less byte than specified by ByteCount because of step 1
  • In step 7, I2C_ReadByte() was originally supposed to return OK or FAIL. That is not used, yet. Ignore the return value. I have said this many times before.
  • On the last byte it ACKs then NAKs. That will break the I2C protocol
  • You decrement the array pointer in step 9. That will cause writes to unknown memory. Another big problem.
  • How does it know success/fail?
I have spent a so much time on flow chart
That's because you continually refuse to do what I ask you to do so that we can resolve problems one by one instead of introducing new ones at random. In #99, I asked you to trace the last flow chart and post the numbers representing the flow. TWICE. I wanted to know if your problems were in step-by-step reasoning or in knowledge of I2C. I still don't know. I think you have problems in both but I can't help you because you won't follow directions. I am out of ideas to figure it out so I need to stop here.

Here is a flow chart for ReadI2C that meets the original specification. It reads any number of bytes (1 to n) from any slave and stores them in an array at the passed address. It returns ACK if it reads 1-n bytes successfully. It returns NAK if it is unsuccessful or called with 0 ByteCount. It doesn't do any other error checking.

Good luck!
 

Attachments

Last edited:

Thread Starter

Gajyamadake

Joined Oct 9, 2019
310
That's because you continually refuse to do what I ask you to do so that we can resolve problems one by one instead of introducing new ones at random. In #99, I asked you to trace the last flow chart and post the numbers representing the flow. TWICE. I wanted to know if your problems were in step-by-step reasoning or in knowledge of I2C. I still don't know. I think you have problems in both but I can't help you because you won't follow directions. I am out of ideas to figure it out so I need to stop here.
Your flow chart is better than my flow chart I was confident this time because I had written a simple program and tested the code to read memory location of array.

C:
#include<stdio.h> 
int read (unsigned int N, unsigned int *p);
int read (unsigned int N, unsigned int *p)
{
    int i;
       for (int i = N-1; i >= 0; i--) { 
       printf("\n read address %p \n ", (p + N-1)); 
       printf("value store at this address is = %d \n", *( p + N-1));
       --p;     
    } 
}    
int main() 
{ 
    int s;  int N = 5 ;  // length of array     
    int Data[] = {1, 2, 3, 4, 5};            
     s= read (N, Data);
    return 0; 
}
read address 0061FF24
value store at this address is = 5

read address 0061FF20
value store at this address is = 4

read address 0061FF1C
value store at this address is = 3

read address 0061FF18
value store at this address is = 2

read address 0061FF14
value store at this address is = 1

I did not want to post my slopy code but I am trying to show that, I tried my best But It is my lack of knowledge i could not get success till the end
 
Top