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

fail to connect through I2C

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







fail to connect through I2C
PostPosted: Mon May 08, 2006 5:08 am     Reply with quote

The program was programmed to send a data to the the slave processor. but the slave program started the I2C interrupt but failed to read the data from mater mode and stay on the command "I2C_Data_Rx=i2c_read(0);".
here are the master and slave code

MASTER CODE
_____________________________________________________________
#include <16F877.H>
#fuses HS,NOWDT,NOPUT,NOBROWNOUT,NOLVP,NOPROTECT
#use delay(clock=20000000)
#use I2C(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)

#define SCL PIN_C3
#define SDA PIN_C4

char I2C_Data_Tx;
void main()
{
output_float(SCL);
output_float(SDA);

I2C_Data_Tx = 0x01;

while(1)
{
i2c_start();
delay_us(50);
i2c_write(0xA1);
delay_us(50);
i2c_write(I2C_Data_Tx);
delay_us(50);
i2c_stop();
}

}

SLAVE CODE
_____________________________________________________________
#include <16F877.H>
#fuses HS,NOWDT,NOPUT,NOBROWNOUT,NOLVP,NOPROTECT
#use delay(clock=20000000)
#use I2C(slave,sda=PIN_C4,scl=PIN_C3,address = 0xA1,FORCE_HW)

#define SCL PIN_C3
#define SDA PIN_C4

char I2C_Data_Rx;

#INT_SSP
void I2C_Recieve()
{
output_b(0x00);
while(!i2c_poll())
I2C_Data_Rx=i2c_read(0);
}
void main()
{
output_float(SCL);
output_float(SDA);

enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);

I2C_Data_Rx = 0x00;
output_b(0xff);

while(1)
{
if(I2C_Data_Rx != 0x00)
{
Output_b(I2C_Data_Rx);
I2C_Data_Rx = 0x00;
}

}


}

Please help me finding out what is the error on it?
I have already connect the pins with 10kohm pull-up resistor
Ttelmah
Guest







PostPosted: Mon May 08, 2006 6:31 am     Reply with quote

There are quite a few problems. Do a search on the group, some working I2C routines have been published here in the past. However as a quick overview just of the problems in the interrupt routine:
1) You are reading a character when I2c_poll is false. It will _always_ be true when the interrupt occurs. When false, it means there is not a character waiting. If true, you do not read the byte, which then doesn't reset the I2C interrupt.
2) You have an address of '0xA1'. This is not a legitimate I2C address. I2C addresses occupy only the top seven bits of the address byte. Having a '1' in the low bit, implies the I2C transaction, is a read. You then try to write data...
3) You try to use I2C_read(NACK) for all bytes. Look at where ACK should be sent, and not sent.
4) Your receive routine, needs to distiguish what state the I2C bus is in. look at I2C_ISR_STATE...

There is a basic I2C slave example, in the CCS example files included wth the compiler.

Best Wishes
Jason
Guest







PostPosted: Tue May 09, 2006 3:21 am     Reply with quote

thank you.

but the program still running i2c_read() continuously.
I have checked the assembly list, it is waiting for the 7 bit address..
isn't that there are some problem in my master code?
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