Home     Company     Products     Services     Community     Download     Store
    [Home arrow Community arrow Forum ]
Community
Community
Login Form





Lost Password?
No account yet? Register
Evidence Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Yet Another Question on i2c bus... (1 viewing) (1) Guests
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Yet Another Question on i2c bus...
#201
Alberto_82 (User)
Junior Boarder
Posts: 25
graphgraph
User Offline Click here to see the profile of this user
Gender: Male alberto_savioli@libero.it Location: Mantova Birthdate: 1982-12-09
Yet Another Question on i2c bus... 3 Months ago Karma: 1  
Hi,
I'm still working on my i2c Honeywell sensor.. I can't send the ACK to the sensor after receiving the first byte of data, the dsPic sends always a NACK and the transmission stops.
Here is my code:

...

// Read the MSB data byte

while(I2C2CONbits.RCEN);
I2C2STATbits.I2COV = 0;
Data_Msb = I2C1RCV;
I2C2CONbits.ACKDT = 0; //set ACKDT bit to send ACK
i2c_SWBIT(I2C1CONbits.ACKEN); //send ACKEN = 1 and wait
i2c_SWBIT(I2C2CONbits.RCEN); //set RCEN = 1 and wait
I2C2STATbits.I2COV = 0;
Data_Lsb = I2C2RCV;

...

Data_Msb and Data_Lsb are the two bytes sent me by the sensor.
i2c_SWBIT is a macro to set high a bit and wait.

Is the code right?? Can you help me??

Tnx,
/Alberto
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/07 10:23 By Alberto_82.
  The administrator has disabled public write access.
#204
chris (Moderator)
Moderator
Posts: 14
graphgraph
User Offline Click here to see the profile of this user
Re:Yet Another Question on i2c bus... 2 Months, 3 Weeks ago Karma: 0  
The code seems to be ok, but there's a problem I think in the following statement:
I2C2CONbits.ACKDT = 0; //set ACKDT bit to send ACK
because the value should be 1 instead of 0.
This is due, I think, to the behaviour of the master during the reading phase as described in the detailed Microchip reference manual for the I2C (Section 19, page 7).


I attach the code I used for the I2C bus communication; it is for I2C port 1, so you need to adapt to port 2.
File Attachment:
File Name: i2c.zip
File Size: 2057


I hope this will help you. If you have any problem post a more detailed version of the code you are using for the I2C communication.

Regard,
Christian.
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/11 11:30 By chris.
  The administrator has disabled public write access.
#210
Alberto_82 (User)
Junior Boarder
Posts: 25
graphgraph
User Offline Click here to see the profile of this user
Gender: Male alberto_savioli@libero.it Location: Mantova Birthdate: 1982-12-09
Re:Yet Another Question on i2c bus... 2 Months, 3 Weeks ago Karma: 1  
Many thanks, now I try to look at your code.. I hope it will solve my problems.

/Alberto
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#216
Alberto_82 (User)
Junior Boarder
Posts: 25
graphgraph
User Offline Click here to see the profile of this user
Gender: Male alberto_savioli@libero.it Location: Mantova Birthdate: 1982-12-09
Re:Yet Another Question on i2c bus... 2 Months, 3 Weeks ago Karma: 1  
Yeah!!!! It works!!!!

I tried your code, but nothing worked... So I've decided to rewrite all the i2c protocol using the PORTG 2 and 3 pins (the same of the original i2c1 bus) and move up and down the pins by hand. The result?? All worked fine!!! Here is my code...
File Attachment:
File Name: i2c-195a1abbfe67fdb6f739ee60a797a060.zip
File" target="_new">http://www.evidence.eu.com/images/fbfiles/files/i2c-195a1abbfe67fdb6f739ee60a797a060.zip">i2c-195a1abbfe67fdb6f739ee60a797a060.zip
File Size: 895


http://www.sparkfun.com/datasheets/Components/HMC6352.pdf

Thanks for your help!

/Alberto
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/13 15:23 By Alberto_82.
  The administrator has disabled public write access.
#217
chris (Moderator)
Moderator
Posts: 14
graphgraph
User Offline Click here to see the profile of this user
Re:Yet Another Question on i2c bus... 2 Months, 3 Weeks ago Karma: 0  
Uhm...
I cannot download your code, it seems that it has not been properly uploaded on the server.
Anyhow, if you say that it's now working that's fine , but I suggest to investigate which could be the error.
I think it would be better to use the I2C interface instead of doing it by hand (that increase the CPU load without any reason).

Try to post the code once more, if you can, and I shall have a look at it.

Bye.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#218
Alberto_82 (User)
Junior Boarder
Posts: 25
graphgraph
User Offline Click here to see the profile of this user
Gender: Male alberto_savioli@libero.it Location: Mantova Birthdate: 1982-12-09
Re:Yet Another Question on i2c bus... 2 Months, 3 Weeks ago Karma: 1  
Sorry, here is the code...

File Attachment:
File Name: i2c-295cfdc840b9db35967b59c30de7e6f2.zip
File Size: 895


Now it works!
The problem I had was that the master always generate a NACK after reading the first byte, causing the stopping of the communication.

Regards,
/Alberto
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/13 15:50 By Alberto_82.
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop
Evidence S.r.l. - PIVA: 01638690501
Via Carducci 64/A - Ghezzano - Pisa - Italy
Privacy Policy