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

i/o i2c expander interrupt problem

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







i/o i2c expander interrupt problem
PostPosted: Wed Aug 06, 2003 3:11 pm     Reply with quote

I try to read inputs from a pcf8674 by mean i2c bus, i have the next problem:

i have connected Interrupt pin from PCF8574 to PIC
INT0 interrup pin, but this is low while push button is pressed

int read_input(){
int data;
start_i2c();
data = read_i2c(0);
stop_i2c();
return (data);
}

#INT0
void Int_PCF8574 (){
dato=read_input();
output_high (pin_B0);
}

Can you help me please??
Thanks in advance
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516731
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: i/o i2c expander interrupt problem
PostPosted: Wed Aug 06, 2003 6:00 pm     Reply with quote

<font face="Courier New" size=-1>:=I try to read inputs from a pcf8674 by mean i2c bus, i have the next problem:
:=
:=i have connected Interrupt pin from PCF8574 to PIC
:=INT0 interrup pin, but this is low while push button is pressed

That's correct, it will go low on input change provided there is a pullup resistor and stay low until input returns to original state or port is read. It's better to connect unused inputs to either Vss or Vdd. So the PIC external interrupt needs to be setup for a falling edge.

This example is for a 16F876, which has RB0 as the external interrupt, so the test led is on RB1 instead. Change to suit the pic you are using.

Connect input to P0 on PCF8574, and all other port pins to Vss or Vdd.
Connect /INT pin of PCF8574 to external interrupt pin of PIC.
A pullup resistor is required, eg. 4k7 ohm.

Edited to tidy up.

Code:


#include <16F876.h>
#use delay(clock=16000000)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use i2c(MASTER,SDA=PIN_C4,SCL=PIN_C3,FORCE_HW)

#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,BROWNOUT

// PCF8574 addresses with A2,A1,A0 all tied to common
#define PCF8574_WRITE_ADDRESS 0x40
#define PCF8574_READ_ADDRESS 0x41

#define TEST_LED PIN_B1

int8 data;                 // Byte received from PCF8574
int1 PCF8574_int_flag = 0;

#INT_EXT
void ext_int_isr(void)
{
   PCF8574_int_flag = 1;
}

void main(void)
{
   ext_int_edge(H_TO_L);
   clear_interrupt(INT_EXT);      // Added. Clear flag.
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   
   // Configure PCF8574 pins as inputs. Defaults to inputs on power-up,
   // but do anyway.
   
   i2c_start();
   i2c_write(PCF8574_WRITE_ADDRESS);
   i2c_write(0xff);     // Set all pins as inputs
   i2c_stop();
   
   // Get and display current switch state
   // The read also resets the interrupt logic of the PCF8574
   
   i2c_start();
   i2c_write(PCF8574_READ_ADDRESS);
   data = i2c_read(0);  // First byte is also last so NACK
   i2c_stop();
   
   // Display state of switch on PCF8574 pin P0
   
   if(bit_test(data,0))
      output_bit(TEST_LED,1);
     
   else output_bit(TEST_LED,0);
   
   
   while(1)
   {
      // If switch state has changed read PCF8574 port
     
      if (PCF8574_int_flag)
      {
         PCF8574_int_flag = 0;   // Clear for next time
         
         i2c_start();
         i2c_write(PCF8574_READ_ADDRESS);
         data = i2c_read(0);     // First byte is also last so NACK
         i2c_stop();
         
         // Display state of switch on PCF8574 pin P0
         
         if(bit_test(data,0))
            output_bit(TEST_LED,1);
           
         else output_bit(TEST_LED,0);
      }
   }
}




___________________________
This message was ported from CCS's old forum
Original Post ID: 144516738


Last edited by Kenny on Fri May 16, 2008 9:24 pm; edited 2 times in total
alberto campo
Guest







Re: i/o i2c expander interrupt problem
PostPosted: Thu Aug 07, 2003 4:06 am     Reply with quote

The main problem for me is that while i press the push button Interrupt pin is low and not return to high until button is depressed . It is a problem because the others buttons cannot generate another interrupts.

I try to set high interrupt pin when finish ISR but it's not working.

Datasheet PCF8574 pag12 show when reading data by mean i2c_read() interrupt return to high. But in my project remains low until button is depressed.

Thanks for your help.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516760
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: i/o i2c expander interrupt problem
PostPosted: Thu Aug 07, 2003 5:51 am     Reply with quote

:=The main problem for me is that while i press the push button Interrupt pin is low and not return to high until button is depressed . It is a problem because the others buttons cannot generate another interrupts.
:=
:=I try to set high interrupt pin when finish ISR but it's not working.
:=
:=Datasheet PCF8574 pag12 show when reading data by mean i2c_read() interrupt return to high. But in my project remains low until button is depressed.
:=
:=Thanks for your help.


Guess it implies that the PCF8574 is not being read.
Things to check:
1. Is there activity on the i2c bus?
2. Are pullup resistors the correct value? 2k2 is good.
3. There is an 'A' version of the PCF8574, the PCF8574A.
It has a different address. Are address pins A0,A1, and A2 configured to match the address being sent?
4. i2c_read() should be i2c_read(0) to give the NACK. Not strictly necessary though because the PCF8574 is one of the few i2c devices tolerant of this error.

HTH
Kenny
Posting again because 1st attempt apparently unsuccessful
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516762
alberto campo
Guest







Re: i/o i2c expander interrupt problem
PostPosted: Thu Aug 07, 2003 7:30 am     Reply with quote

:=:=The main problem for me is that while i press the push button Interrupt pin is low and not return to high until button is depressed . It is a problem because the others buttons cannot generate another interrupts.
:=:=
:=:=I try to set high interrupt pin when finish ISR but it's not working.
:=:=
:=:=Datasheet PCF8574 pag12 show when reading data by mean i2c_read() interrupt return to high. But in my project remains low until button is depressed.
:=:=
:=:=Thanks for your help.
:=
:=
:=Guess it implies that the PCF8574 is not being read.
:=Things to check:
:=1. Is there activity on the i2c bus?
yes, sometimes i can read data correct from 8574
:=2. Are pullup resistors the correct value? 2k2 is good.
yes , i have set 4k7 pull up resistor
:=3. There is an 'A' version of the PCF8574, the PCF8574A.
:=It has a different address. Are address pins A0,A1, and A2 configured to match the address being sent?
version without "a" i have a0, a1,a2 connected to gnd and i use 0x40 for writing and 0x41 for reading
:=4. i2c_read() should be i2c_read(0) to give the NACK. Not strictly necessary though because the PCF8574 is one of the few i2c devices tolerant of this error.
:=

Again, Sometimes INT pin not return to high after depressing push button this disable another new interrupt ¿?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516776
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: i/o i2c expander interrupt problem
PostPosted: Fri Aug 08, 2003 12:26 am     Reply with quote

:=:=:=The main problem for me is that while i press the push button Interrupt pin is low and not return to high until button is depressed . It is a problem because the others buttons cannot generate another interrupts.
:=:=:=
:=:=:=I try to set high interrupt pin when finish ISR but it's not working.
:=:=:=
:=:=:=Datasheet PCF8574 pag12 show when reading data by mean i2c_read() interrupt return to high. But in my project remains low until button is depressed.
:=:=:=
:=:=:=Thanks for your help.
:=:=
:=:=
:=:=Guess it implies that the PCF8574 is not being read.
:=:=Things to check:
:=:=1. Is there activity on the i2c bus?
:= yes, sometimes i can read data correct from 8574
:=:=2. Are pullup resistors the correct value? 2k2 is good.
:= yes , i have set 4k7 pull up resistor
:=:=3. There is an 'A' version of the PCF8574, the PCF8574A.
:=:=It has a different address. Are address pins A0,A1, and A2 configured to match the address being sent?
:= version without "a" i have a0, a1,a2 connected to gnd and i use 0x40 for writing and 0x41 for reading
:=:=4. i2c_read() should be i2c_read(0) to give the NACK. Not strictly necessary though because the PCF8574 is one of the few i2c devices tolerant of this error.
:=:=
:=
:=Again, Sometimes INT pin not return to high after depressing push button this disable another new interrupt ¿?


Yes, the pin needs to go high again if the interrupt is setup for falling edge.
Could you post your code so we can look for a problem.
Kenny
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516801
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: i/o i2c expander interrupt problem
PostPosted: Fri Aug 08, 2003 2:51 pm     Reply with quote

:=:=:=The main problem for me is that while i press the push button Interrupt pin is low and not return to high until button is depressed . It is a problem because the others buttons cannot generate another interrupts.
:=:=:=
:=:=:=I try to set high interrupt pin when finish ISR but it's not working.
:=:=:=
:=:=:=Datasheet PCF8574 pag12 show when reading data by mean i2c_read() interrupt return to high. But in my project remains low until button is depressed.
:=:=:=
:=:=:=Thanks for your help.
:=:=
:=:=
:=:=Guess it implies that the PCF8574 is not being read.
:=:=Things to check:
:=:=1. Is there activity on the i2c bus?
:= yes, sometimes i can read data correct from 8574
:=:=2. Are pullup resistors the correct value? 2k2 is good.
:= yes , i have set 4k7 pull up resistor
:=:=3. There is an 'A' version of the PCF8574, the PCF8574A.
:=:=It has a different address. Are address pins A0,A1, and A2 configured to match the address being sent?
:= version without "a" i have a0, a1,a2 connected to gnd and i use 0x40 for writing and 0x41 for reading
:=:=4. i2c_read() should be i2c_read(0) to give the NACK. Not strictly necessary though because the PCF8574 is one of the few i2c devices tolerant of this error.
:=:=
:=
:=Again, Sometimes INT pin not return to high after depressing push button this disable another new interrupt ¿?

Reposting.
Yes, the pin needs to go high again if the interrupt is setup for
falling edge.
Could you post your code so we can look for a problem.
Kenny
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516845
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