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 support@ccsinfo.com

Problems with 16F886 as I2C slave.

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







Problems with 16F886 as I2C slave.
PostPosted: Tue Mar 10, 2009 2:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 3:03 pm     Reply with quote

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







PostPosted: Wed Mar 11, 2009 3:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 5:23 pm     Reply with quote

Use a compatible PIC that doesn't have erratas on the i2c slave mode.
You could use the 16F876A.

Or,

You can use this page to find a PIC:
http://www.microchip.com/maps/microcontroller.aspx
Set the number of package pins to 28 in both the "From" and "Thru"
columns. Then set the Prefix to "PIC16F". Then look at the list of PICs
in the Search Results box at the top.

Then check the errata sheets for the PICs.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2046
See if they have any problems in i2c slave mode.
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