CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SDA left low after i2c_stop()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
e_vandyke
Guest







SDA left low after i2c_stop()
PostPosted: Fri Dec 14, 2007 11:15 am     Reply with quote

I'm currently trying to read some I2C devices using an 18F8722 PIC, using the current version of the CCS compiler.

I am able to perform a standard combo write/read cycle once, but after completing the cycle, the I2C hangs at the i2c_write() call in the next combo write/read cycle (executing the exact same code).

My i2c configuration spec is:
#use i2c(MASTER,SLOW,SCL=SCL1,SDA=SDA1,FORCE_HW,RESTART_WDT) // MSSP #1

and my write/read cycle is coded as:
printf("i2c_start...");
i2c_start();
printf("write addr...");
i2c_write(addrH); // Select sensor
i2c_write(addrL); // Select sensor
printf("write reg...");
i2c_write(regSel); // Select read register
i2c_write(dataAddr); // Select data address
i2c_start(); // Restart
i2c_write(addrH|1); // Select sensor [1st byte only, RD]
z = i2c_read(); // Read msB
z = (z << 8) | i2c_read(); // Read lsB
y = i2c_read(); // Read msB
y = (y << 8) | i2c_read(); // Read lsB
x = i2c_read(); // Read msB
x = (x << 8) | i2c_read(); // Read lsB
i2c_stop();

Any ideas?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 14, 2007 11:25 am     Reply with quote

You need to do a "NAK" on the last i2c read. This is done by using 0x00
as the parameter for i2c_read(). Example:
Quote:

x = (x << 8) | i2c_read(0); // Read lsB
i2c_stop();


If that doesn't fix the problem, then post the manufacturer and part
number of the Sensor device.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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