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...
#219
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  
Ok, as I said before, if the code works (and it seems that should do) that is fine, but just for testing I dare say.
I mean that this is good to be sure that the peripheral you want to communicate with is working properly, but just this!

I strongly discourage you to use that code for general purpose, because it will be not flexible at all.
I have been able to use the I2C interface, and I think that you will be able to.

I suggest to go back to the version with the I2C interface and to debug it. Post the previous code, the full version is better, and I shall look for the problem.

Regards.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#220
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  
Hi,
I've used your code adapted for my sensor. First of all I have to send to sensor 0x42 adress the 0x41 command to make start the reading; then sending the sensor 0x43 adress will give me back two bytes of data: MSB and LSB. Between the two bytes the sensor expects an ack from the master, that is the master must set the sda line low at the 9th clock after received the last bit of the MSB data Byte. Well, I don't know why, I always get a NACK, causing the end of the transmission.
Here is the revised code, that doesn't work at all: the scope doesn't see anything nor on the SDA line neither on the SCL line.
File Attachment:
File Name: i2c-a67682b98eed6b61a99d9f12e4791511.zip
File Size: 1379


PS: Sorry for my code, it's messy...

Bye,
/Alberto

EDIT: and sorry for my english!!!
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/10/13 17:49 By Alberto_82.
  The administrator has disabled public write access.
#221
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  
As far as I understood from the last code that you posted you are explicitly using the NACK after the first transmission. What you want, and what you should need, is the following transmission:
select_device -> ack_from_device -> read_msb -> ACK -> read_lsb -> NACK.
But looking at the code you send NACK after the msb byte, telling the device to close the transmission.

Code: :

/* Read the MSB data byte */ I2C1CONbits.RCEN = 1; while (I2C1CONbits.RCEN); I2C1STATbits.I2COV = 0; data = I2C1RCV & 0x00FF; _I2C1_CHECK_IDLE(); /* send NACK condition back to the I2C slave indicating master * received the data byte */ I2C1CONbits.ACKDT = 1; I2C1CONbits.ACKEN = 1; while (I2C1CONbits.ACKEN);     /* wait until NACK sequence is over */ _I2C1_CHECK_IDLE();



This is due to the following line
I2C1CONbits.ACKDT = 1;

Try to put 0 (meaning ACK) instead of 1 after reading the msb byte (but keep the last NACK after the lsb byte).

The problem with the scope is more serious (remember you are now using the i2c port 1 ).
Did you call the i2c_init() function before doing everything?
You should at least see the clock line and some transition on the SDA.
Check also the I2C1BRG = 362; assignment in the init function, since this specify the i2c bus frequency and should match the peripheral specifiication (please refer to the microchip refman for i2c).

I hope this can help somewhat.
I don't mind your code, and above all your English (I'm sorry for the mine )

Bye!
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#222
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  
Yes, you are right, in the code post before I used ACKDT bit set to 1. But either giving it zero value the result is unfortunatly always the same. In fact, as I told you before, this version of the code does not work at all. The scope was setted up fine, one input on SDA and another on the SCL, and the i2c port I used was the number 1. I'm using an old scope and I cannot capture the screen, but tomorrow I'll try to take a picture of the wave... Anyhow, for now I'll use my code, I don't have too much time to finish my thesis!

Thank you a lot,
/Alberto
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#223
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  
Ok, don't worry for the driver. Use your own version and ...

in bocca al lupo per la tua tesi!

 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#224
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  
Crepi il lupo!!!

Ciao,
/Alberto
 
Report to moderator   Logged Logged  
  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