|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 03, 2012 12:48 pm |
|
|
Quote: | There must be someone who needed to get more than 1 byte via I2C.
|
One of the reasons you are not getting replies is because you are making
really, really dumb errors in your code. This makes people avoid giving
help. They think you don't care enough to proof-read your code. So they
think, "he (Chaud) doesn't care, so why should I care ?", and they don't
give help.
Here is an example from your program:
Quote: |
i2c_write(11010001); // Device address/Read
|
Here, you are giving it an i2c address of 11 million and something.
That's not an i2c address. No way. A number written just like that
is in Decimal format. It's 11 million and something. If you want
binary format (1's and 0's), then you have to put a "0b" in front of
the number. That's very basic knowledge in programming. When
you make that mistake, it makes people groan and turn away.
I'm not trying to beat up on you too much, but I am trying to let you
know that you need to proof-read your code. You need to question
your own code, and think like this: "Is that right ? Do I really use 11
million for the i2c address ?". "That can't be right". "I must find the
correct way to do it".
In addition to that, there are at least two more mistakes in the following
code. If you read previous threads on i2c problems on this forum you
would see the answer. For one thing, no one ever uses i2c_poll() in
a simple PIC Master to Slave device program. You won't see it in any
examples. So why use it ? Again, you need to question everything
you do.
Code: |
i2c_write(11010001); // Device address/Read
for(count = 0; count < 2;count++){
while(!i2c_poll());
buffer[count] = i2c_read(1);
|
The other problem has to do with using a NACK on the last i2c_read().
That answer must have been posted at least 100's of times on this forum.
Sometimes people get tired of posting it one more time. You need to
read the forum archives for i2c problems. Use the search page. |
|
|
Chaud
Joined: 11 Jan 2012 Posts: 39
|
|
Posted: Sun Feb 05, 2012 2:50 pm |
|
|
Hello PCM Programmer, I agree with you, sorry I'm a very distracted guy, and I completely forget the "0b" , and the problem was that .. sorry my bad, thanks for help friend.
temtronic thanks for your help too
Problem solved |
|
|
|
|
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
|