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

Proteus I2C have a problem, help me !

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



Joined: 12 Mar 2011
Posts: 7

View user's profile Send private message

Proteus I2C have a problem, help me !
PostPosted: Wed Mar 16, 2011 11:16 pm     Reply with quote

Code:
#include<18F4520.h>
#include"DEF_18F4520.c"
#fuses HS
#use delay(clock = 4000000)
#use I2C(MASTER , SDA = PIN_C4, SCL = PIN_C3)
#use FAST_IO( A B)
#use FAST_IO ( C D )
#define slave_address 0x41
int8 data_in ;
void i2c_send(data_in)
{
   i2c_start();
   i2c_write(slave_address);
   i2c_write(data_in);
   i2c_stop();
}
void main()
{   
   while(true)
   {
      data_in = input_B();
      i2c_send(data_in);
      
   }
   
}



Code:
#include<18F4520.h>
#include"DEF_18F4520.c"
#fuses HS
#use delay(clock = 4000000)
#use I2C(SLAVE , SDA = PIN_C4, SCL = PIN_C3, address = 0x41)
#use FAST_IO(B)
int8 data_out ;
#INT_SSP
void i2c_isr()
{
   int8 state;
    state = i2c_isr_state();
    if(state<0x80)
    {
         if (state == 1)
        {
          data_out = i2c_read();
         output_b(data_out);
        }
      
     
    }
   
   if(state >= 0x80)
   {
   }
   clear_interrupt(INT_SSP);
}

    
    

void main()
{
   trisb = 0x00;
   enable_interrupts(GLOBAL);
    enable_interrupts(INT_SSP);
   while(true)
   {   
   }
}






Port B at Slave do not show the input from Master. Please help me to fix my problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 16, 2011 11:33 pm     Reply with quote

Your program has some mistakes. For example, you have an odd
number as the i2c slave address. But it must be an EVEN number.
Also, the pull-up resistors on your schematic should be changed to
4.7K (4700 ohms).

If you can't make your program work, then I suggest that you 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
iVoVa



Joined: 12 Mar 2011
Posts: 7

View user's profile Send private message

PostPosted: Thu Mar 17, 2011 5:36 am     Reply with quote

Thanks PCM so much, you help me get a lot of knowledges.
My program worked.
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