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

Need help to make I2C Master working

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



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

Need help to make I2C Master working
PostPosted: Tue Jun 21, 2011 10:32 am     Reply with quote

Hi,

I have some difficult to make I2C master working on PIC16f687. In attached code, PIC sends a slave address and asking slave to return one byte.
If slave is not connected, PIC will repeat same action and toggle PIN_B7 every 100 ms.

If slave is connected and sends back one byte, PIC will be stopped. (PIN_B7 will be a flat line on oscilloscope all the time until next power cycle). Anyway, PIC is OK to send data to slave as I2C master.

By the way, with same PIC, 16f687 and CCS 4.120d, I2C slave is working on read and write both. And two 3.3K pull-up resisters are used on SCL and SDA.


Please help.
Thanks.
Howard

Code:

#include <16F687.h>

#fuses NOWDT, BROWNOUT, NOPUT, MCLR,NOCPD,INTRC,IESO,FCMEN
#use delay(clock=4M)
//#use i2c(SLAVE, SDA=PIN_B4, SCL=PIN_B6, address=0x80,FORCE_HW)
#use i2c(MASTER, SDA=PIN_B4, SCL=PIN_B6, address=0x2f,fast=100000)  //,SMBUS)  //,FORCE_HW)

void main (void)
{
   output_high(PIN_C4); // to turn pwr on for testing board
   output_low(PIN_C1);  // to turn pwr on for testing board
   output_high(PIN_C3); // to turn pwr on for testing board

   while (TRUE)
   {
      //hello for ack
      i2c_start();
      i2c_write(0x20);
      i2c_stop();

      //read
      i2c_start();
      i2c_write(0x21);
      i2c_read(1);
      i2c_stop();     // Stop condition
     
       
      delay_ms(100);
      output_toggle(PIN_B7);
   }
}
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 11:05 am     Reply with quote

out of curiosity, try changing your i2c_read(1) call to i2c_read(0)

For some reason I thought you had to NACK the last byte you read as the master.
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 11:35 am     Reply with quote

jeremiah wrote:
out of curiosity, try changing your i2c_read(1) call to i2c_read(0)

For some reason I thought you had to NACK the last byte you read as the master.


Did the test. No difference.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 12:52 pm     Reply with quote

This post has some working i2c Master and Slave code. Look at how its
done in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=39242&start=6
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 2:38 pm     Reply with quote

PCM programmer wrote:
This post has some working i2c Master and Slave code. Look at how its
done in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=39242&start=6


Thanks for help. Since PIC is used as I2C master and TI DSP is used as a slave in my case, the implementation of I2C slave is different with CCS but master code of PIC is close enough.

My question is that, what could be a reason causing PIC to hangup while I2C slave sending a data and why?

Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 2:54 pm     Reply with quote

Did you write the TI DSP i2c slave code ? How do you know it works OK ?

Is there a specification document for the TI DSP i2c slave ? I don't mean
the general TI data sheet. I mean a document describing in detail the
operation of the specific TI DSP slave implementation that you have.
In other words, what's the i2c command protocol for the slave ? Where is
the i2c bit diagram describing the exact data to be sent and received,
with start bits, ACK, NACK, stop bits, etc.

I need to see that documentation to know what the correct PIC master
code should be.
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 5:45 pm     Reply with quote

PCM programmer wrote:
Did you write the TI DSP i2c slave code ? How do you know it works OK ?

Is there a specification document for the TI DSP i2c slave ? I don't mean
the general TI data sheet. I mean a document describing in detail the
operation of the specific TI DSP slave implementation that you have.
In other words, what's the i2c command protocol for the slave ? Where is
the i2c bit diagram describing the exact data to be sent and received,
with start bits, ACK, NACK, stop bits, etc.

I need to see that documentation to know what the correct PIC master
code should be.


We are using CSL Lib and DSP 320C5504. And AARDVARK I2C Protocol analyzer is used. DSP did I2C correctly based the protocol analyzer.

I2C doc:
http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sprufo1a&fileType=pdf
CSL Lib:
http://processors.wiki.ti.com/index.php/Chip_support_library
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 6:14 pm     Reply with quote

You didn't answer my questions so I can't give any help. One of your
links is dead, and the other goes to many, many links. There is no
protocol information on the i2c slave as I requested. Someone else
will have to help.
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