|
|
View previous topic :: View next topic |
Author |
Message |
AGS Guest
|
Problems with 16F886 as I2C slave. |
Posted: Tue Mar 10, 2009 2:59 pm |
|
|
Hello all,
I’m trying to use an 16F886 as I2C slave. Really it is the Pic embedded into the board supplied with the PCKit Serial Analizer from Microchip.
As slave code, I’m using the code example provide for CCS in the file ‘EX_SLAVE.C’. I’m introducing the following changes for PIC16F886. Also I’m using a PCM v.4.023.
Code: |
#include <16F886.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0)
BYTE address, buffer[0x10];
#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state < 0x80) //Master is sending data
{
incoming = i2c_read();
if(state == 1) //First received byte is address
address = incoming;
if(state == 2) //Second received byte is data
buffer[address] = incoming;
}
if(state == 0x80) //Master is requesting data
{
i2c_write(buffer[address]);
}
}
void main ()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while (TRUE) {}
}
|
As I2C master, I’m using the PCKit Serial Analizer Sw and Hw configured as Master at 100Mhz with pullups enable and 3000 ms for timeout script.
The script used is quit simple:
I2CSTART
I2CWRTBYT
A0
I2CWRTBYT
01
I2CSTOP
This script works like:
Code: |
i2c_start();
i2c_write(0xA0);
i2c_write(0x01);
i2c_stop();
|
And the result in the transaction window is the follwing:
Code: |
Welcome to PICkit Serial version 2.1.1.0
Found PICkitS.dll - Ver: 2.2.0.0
Found PICkit Serial Analyzer - FW Ver: 0x0201
USB control block updated with preference data.
Advanced View Set.
PICkit Serial Analyzer correctly updated.
21:17:06
[S_][W_][A0][W_][01][P_]
Warning - did not receive a 'Script Complete' tag within 3000ms. Script may have failed.
Try increasing the Script Timeout value on the Configuration page if this continues.
[S_]
|
Please, somebody can halp me with this elementary practice?
thanks in advanced. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 10, 2009 3:03 pm |
|
|
That PIC is buggy in i2c slave mode. You're also using an early version
of the compiler which probably adds to the problem.
Read the post at the end of this thread re fixing the slave mode problems:
http://www.ccsinfo.com/forum/viewtopic.php?t=38091 |
|
|
AGS Guest
|
|
Posted: Wed Mar 11, 2009 3:32 pm |
|
|
Thanks. I'll follow this thread. But let me know a few things before.
What it is a better PIC micro option for a simple I2C slave solution?. This PIC 16F886 is included normally in the standard offer of Microchip for buses practices.
I get my CCS compiler when I bought the PCKit 2. So, Does it is possible to get an update from CCS.?
If the I2C master in the development is the same that the slave, 16F886 in this case, also still doing critical the response time, etc.?
thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|