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 CCS Technical Support

16F689 I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
[email protected]



Joined: 16 May 2006
Posts: 39

View user's profile Send private message

16F689 I2C
PostPosted: Fri Feb 12, 2010 7:26 pm     Reply with quote

I am using 16F689 to build 2 boards to test the I2C operation but found that it is not working.

Master
Code:

#include <16F689.h>
#device *=16
#device adc=8

#FUSES NOWDT
#FUSES MCLR, HS, NOBROWNOUT
#use delay(clock=20000000)
#use i2c(master,sda=PIN_B4,scl=PIN_B6)
#users232(baud=19200,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,errors, stream=PC)

main()
{
   int c;

   delay_ms(2000 );
   fprintf(PC,"Ready..\n\r");

   while (true) {
      i2c_start();
      i2c_write(0xa0);
      //  delay_ms(100);
      i2c_write(50);
      //  delay_ms(100);
      i2C_start();
      i2c_write(0xa1);
      //  delay_ms(100);
      c =  i2c_read(0);
      fprintf(PC, "%c\n\r", c );
   }
}


Slave
Code:

#include <16F689.h>
#device *=16
#device adc=8

#FUSES NOWDT
#FUSES MCLR, HS, NOBROWNOUT
#use delay(clock=20000000)
#use i2c(Slave,sda=PIN_B4,scl=PIN_B6,address=0xa0,force_hw)

int n;

#int_SSP
SSP_isr()
{
   int state;

   state = i2c_isr_state();

   if ( state >= 0x80 )
      i2c_write( n );
   else if (state > 0 ) {
      output_toggle( pin_c4 );
      n = i2c_read();
   }
   else {
       output_toggle( pin_c3 );
   }
}

Problem

1. Master never work with force_hw
2. Slave - no data was read BUT the READ ADDRESS MATCH (pin_c3 toggled).
3. Slave - no data was read because PIN_C4 not toggled.

Work around

1. I put some extra delay_ms() instruction but no help.
2. Slave can write data (Master can read).

Any idea?
Ttelmah
Guest







PostPosted: Sat Feb 13, 2010 2:52 am     Reply with quote

You need to read the address (state==0). The flag saying that a byte has been received, is not cleared unless you do....

Best Wishes
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