Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 18, 2024, 01:57:54 01:57


Login with username, password and session length


Pages: [1]
Print
Author Topic: Need help...... i2c 1master + 2 slave (PIC)  (Read 7741 times)
0 Members and 1 Guest are viewing this topic.
pecpys
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 4
-Receive: 3


« on: October 28, 2008, 03:16:46 15:16 »

Could you please to help me.....
In simulation by use proteus. CCS v4.047 PIC18F45J10
I use Pic for master and another one is slave.
It can communication good.
but if I add RTC IC (DS1307) to bus. the communication is fail.

I see the slave PIC address = 0xA0) has interrupt every time. although master read RTC IC (address = 0xD0) the slave PIC has interrupt too. Why?

Anybody could you check this for me?
Proteus error or CCS error? Huh Huh

Thanks you very much
Logged
FriskyFerret
Hero Member
*****
Offline Offline

Posts: 560

Thank You
-Given: 513
-Receive: 360


Put it in, take it out.


WWW
« Reply #1 on: October 28, 2008, 03:35:46 15:35 »

Quote
Proteus error or CCS error?

I find it amusing that you didn't even consider a third reason for the problem was an error on your part.
Logged

Dancing pants and leotards, that's what I'm talkin' about!
pecpys
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 4
-Receive: 3


« Reply #2 on: October 28, 2008, 03:56:46 15:56 »

I'm sure the problem is not come from code.
because the problem is it has interrupt although the address is not it's address.


The master is use library 24512.c for reading.

The slave code is..

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xA0, FORCE_HW)
#INT_SSP
void ssp_interupt ()
{
BYTE state, data;
   state = i2c_isr_state();
   if(state < 0x80)                        //Master is sending data
   {
      if(state == 0)                        //First received byte is high address
      {
      }
      else if(state == 1)                        //First received byte is high address
      {
         while(!i2c_poll()) ;
         data =i2c_read();
          high_address = data;
      }
      else if(state == 2)               //Second received byte is low address
      {
         while(!i2c_poll()) ;
         data =i2c_read();
         low_address = data;     
      }
      else
      {
         while(!i2c_poll()) ;
         data =i2c_read();
         if (high_address == 0)
         {
            coils_status[low_address] = data;
            low_address++;
         }
         else if(high_address == 1)
         {
            inputs_status[low_address] = data;
            low_address++;
         }
         else if(high_address == 2)
         {
            hold_regs[low_address] = data;
            low_address++;
         }
         else if(high_address == 3)
         {
            input_regs[low_address] = data;
            low_address++;
         }
      }
   }
   if(state >= 0x80)                     //Master is requesting data
   {
      output_bit( PIN_C2,0);
      if (high_address == 0)
      {
         i2c_write(coils_status[low_address]);
         low_address++;
      }
      else if(high_address == 1)
      {
         i2c_write(inputs_status[low_address]);
         low_address++;
      }
      else if(high_address == 2)
      {
         i2c_write(hold_regs[low_address]);
         low_address++;
      }
      else if(high_address == 3)
      {
         i2c_write(input_regs[low_address]);
         low_address++;
      }
      else
      {
         i2c_write(0x00);
      }
   }
}
Logged
pecpys
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 4
-Receive: 3


« Reply #3 on: October 29, 2008, 08:52:26 08:52 »

OK, Today I test by use real hardware.
The error is in proteus.
i2c interrupt in pic has interupt every time (although it is not correct address)
Logged
future
Newbie
*
Offline Offline

Posts: 16

Thank You
-Given: 10
-Receive: 7


« Reply #4 on: October 31, 2008, 02:14:35 14:14 »

I've noticed the same thing, proteus is not right. You can make your code work though.

Make the pic interrupt on every i2c event, clear overruns if needed.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC