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

problem i2c slave 16F88 (NACK!) (EX_SLAVE.C)

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



Joined: 08 Apr 2010
Posts: 2

View user's profile Send private message

problem i2c slave 16F88 (NACK!) (EX_SLAVE.C)
PostPosted: Thu Apr 08, 2010 4:08 am     Reply with quote

Hi i'm trying to comunicate 2 pics via i2c.

MASTER:
- The master is 18F452 and implements software i2c (also is using the microchip TCP/IP stack)
- The master comunicates OK with other devices (SRF08 ultrasonic sensor)
- The clock frequency is 100Khz (bus speed)
- Pull-up resistors 10k

SLAVE:
- I'm using the ex_slave.c example in CCS (version 4.023)
- Pic 16F88 running at 20MHz
- Using HW i2c
- The LED blinks ok, so the pic is not locked.

PROBLEM DESCRIPTION:
- When the master tries to write, the slave ack correctly the address byte (i'm sure about this). The last 2 bytes (data bytes) the slave gives a NACK.
- I think that SSP interrupt never reaches.

The slave code:
Code:

#include <16F88.h>           
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use i2c(SLAVE,FORCE_HW, SDA=PIN_B1,SCL=PIN_B4,address=0xA0)

#define LED_GROC_ON()    output_high(PIN_B0)
#define LED_GROC_OFF()    output_low(PIN_B0)

BYTE address, buffer[0x10];
BYTE interrup;

#INT_SSP
void ssp_ISR (void)
{
   BYTE incoming, state;
   interrup = 1;
   
   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()
{
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_timer_1(T1_DISABLED);

   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   set_tris_b(0b11111110);
   LED_GROC_OFF();
   interrup = 0;
   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);

   delay_ms(10);

   while(1){
   delay_ms(1000);
   LED_GROC_OFF();
   delay_ms(1000);
   LED_GROC_ON();   
   }
}

Any suggestions to solve the problem? Could the 16F88 or the compiler have any bug? I'm almost sure that the problem remains on the slave.

Thanks for your help!!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 5:20 am     Reply with quote

Quote:
CCS (version 4.023)
Whenever I read about a version 4 compiler before v4.070 I stop reading.
Upgrade your compiler to a more recent version, or downgrade to the stable v3.249 that was available at the time of your download.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 10:53 am     Reply with quote

Your version may have problems because it is an early version.
But assuming that it might work, here's what you can do:

First, try to get a simple i2c slave program working.
When you get that working, then try to make your own program work.

Use the CCS example file code, Ex_Slave.c, for the Slave PIC.
It's in this directory:
Quote:

c:\Program Files\picc\Examples\Ex_Slave.c


Use the code in this post for the Master PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=32368&start=3

Make sure that you have the 4.7K pull-up resistors on both SDA and SCL.
TM_F88



Joined: 08 Apr 2010
Posts: 2

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 12:24 pm     Reply with quote

Hi guys!! I've upgraded the compiler version to 4.093 and now it works perfect!!!


Thanks, thanks and more thanks!! I've wasted many time on this! =D
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