View previous topic :: View next topic |
Author |
Message |
kongfu1
Joined: 26 Apr 2010 Posts: 56
|
Need help to make I2C Master working |
Posted: Tue Jun 21, 2011 10:32 am |
|
|
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
|
|
Posted: Tue Jun 21, 2011 11:05 am |
|
|
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
|
|
Posted: Tue Jun 21, 2011 11:35 am |
|
|
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
|
|
|
kongfu1
Joined: 26 Apr 2010 Posts: 56
|
|
Posted: Tue Jun 21, 2011 2:38 pm |
|
|
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
|
|
Posted: Tue Jun 21, 2011 2:54 pm |
|
|
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
|
|
Posted: Tue Jun 21, 2011 5:45 pm |
|
|
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
|
|
Posted: Tue Jun 21, 2011 6:14 pm |
|
|
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. |
|
|
|