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

Strange problem with i2c slave on 16F690 [Solved]

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

Strange problem with i2c slave on 16F690 [Solved]
PostPosted: Mon Sep 30, 2013 1:20 pm     Reply with quote

Hi,

PCM: 3.249
MPLAB IDE: 8.60
Device: 16F690

I am trying to setup the 16F690 as an i2c slave. I used the EX_SLAVE.c code example for this. This works very well.

But when I add set_tris_a, set_tris_b, set_tris_c functions, the i2c communication stops and the 16F690 does not respond.

The same problem occurs when using enable_interrupt(INT_RDA).

The working code is given below.
Code:
#include <16F690.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOMCLR,NOFCMEN
#use delay(clock=4000000)

#use rs232(baud=9600,xmit=pin_b7, rcv=pin_b5,parity=n,errors)
#use i2c(SLAVE,slow,SDA=pin_b4,SCL=pin_b6,address=0xA7)

BYTE address,buffer[0x10];

#INT_RDA
void usart()
{


}

#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]);
   }
}

#zero_ram
void initialise()
{
   setup_oscillator(OSC_INTRC|OSC_4MHZ);
   setup_comparator(NC_NC_NC_NC);

//   set_tris_a(0b11111111);
//   set_tris_b(0b00101111);
//   set_tris_c(0b00110111);

//   enable_interrupts(INT_RDA);
      enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
}

void main()
{
   initialise();
   
   do{
   }while(TRUE);

}


the problem starts when the set_tris_a, set_tris_b, set_tris_c and enable_interrupts(INT_RDA) lines are un-commented.

I am powering the 16F690 with a 3.3V supply, the pullups are 3.9K. However I don't think the problem is with the supply as the example code works very well.

Please help...

thanks
a
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 30, 2013 1:33 pm     Reply with quote

Quote:
#INT_RDA
void usart()
{


}

The source of the interrupt is the fact that there is a character sitting in
the UART's receive buffer. If you don't read the character (which removes
it from the buffer), it will sit there in the buffer and you will get an
interrupt over and over again. The program will appear to lock up.
To prevent this, read the character with getc() inside the #int_rda routine.


Quote:
#use i2c(SLAVE,slow,SDA=pin_b4,SCL=pin_b6,address=0xA7)

#use i2c does not want an odd slave address. Change it to an even address.
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Mon Sep 30, 2013 1:34 pm     Reply with quote

As far as I know the SDA and SCL pins should be inputs.

Regards
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

re
PostPosted: Mon Sep 30, 2013 1:43 pm     Reply with quote

thanks for the reply, i shall try this out.

but why does the i2c communication lock up when only the set tris functions are used (no rda interrupt).

thanks
a
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 30, 2013 1:54 pm     Reply with quote

Get rid of the floating inputs. In the thread below, it is shown that floating
inputs on spare pins cause the SPI to partially fail. It could also affect i2c:
http://www.ccsinfo.com/forum/viewtopic.php?t=45371&start=15
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

re
PostPosted: Tue Oct 01, 2013 1:02 pm     Reply with quote

thanks for the reply, i made all the unused ports as input and pulled them high, its working well now,

thanks
a
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