The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 06, 2016, 09:10:11 09:10


Login with username, password and session length


Pages: [1]
Print
Author Topic: i could not communicate 18f2550 and 16f877 via i2c  (Read 2779 times)
0 Members and 1 Guest are viewing this topic.
ugur
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 0
-Receive: 0


« on: August 01, 2008, 11:44:40 23:44 »

Please help me,

I was communicated 2 877 each other in CCS. I tryed circuit in proteus. It's worked. And then I tryed communicate 18f2550 and 16f877 via i2c in CCS. 2550 is master. 877 is slave. But it's not worked.

SDA and SCL pins are true. is there an update in CCS or Proteus?
« Last Edit: August 15, 2008, 09:27:05 21:27 by ugur » Logged
lead_inovation
Junior Member
**
 Muted
Offline Offline

Posts: 37

Thank You
-Given: 85
-Receive: 3


« Reply #1 on: August 13, 2008, 05:45:14 17:45 »

Ugur! i can help u, but i would like u upload your source code!
Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #2 on: August 14, 2008, 01:26:10 01:26 »

make sure of the following.
- the clock and data line "high" pulses are in fact high on the receiving end.
- the tris of each pin are correct for the purpose.

Communication is simple but before you jump into large codes, try small one byte (or even a bit) transfer.
Small steps make it easier to debug.

Good luck

Logged

If I have said something that offends you, please let me know, so I can say it again later.
snoopy
Newbie
*
Offline Offline

Posts: 20

Thank You
-Given: 10
-Receive: 0


« Reply #3 on: August 14, 2008, 07:40:30 07:40 »

Do you have pull up in SDA and SCL lines, if not try with 10k.

Snoopy
Logged
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #4 on: August 15, 2008, 12:42:51 12:42 »

I guess you mentioned '16f877' not '18f877'? If that's true there is a bug in '16f877' hardware which you have to implement an 'i2c_stop()' function in standart CCS i2c functions. Below is the edited functions I used for 'eeprom' read and writes with '16f877', modify these functions for your own needs and give them a try. I recomend using a real hardware for the tests as 'proteus' in not very reliable for this kind of tasks!

Code:
void write_ext_eeprom(long int address, BYTE data, int dev_adr)
{
   short int status;
   i2c_start();
   i2c_write(0xa0|((dev_adr&0x03)<<1));
   i2c_write(address>>8);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   do {
      i2c_start();
      status=i2c_write(0xa0|((dev_adr&0x03)<<1));
      i2c_stop();
   } while(status==1);
}

BYTE read_ext_eeprom(long int address, int dev_adr) {
   BYTE data;
   i2c_start();
   i2c_write(0xa0|((dev_adr&0x03)<<1));
   i2c_write(address>>8);
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1|((dev_adr&0x03)<<1));
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

'dev_adr' is the device address which you set by connecting the appropriate eeprom pins to GND or VDD. You can get rid of that if you don't need it. The important part here is the 'i2c_stop()' function in the 'write_ext_eeprom' function in the 'do...while' loop. That's the part to fix the bug in '16f877' hardware!

Regards...
Logged

Regards...
ugur
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 0
-Receive: 0


« Reply #5 on: August 15, 2008, 09:25:10 21:25 »

thanks all,

for master (2550); some of my codes;

   #use i2c(Master,Fast,sda=PIN_B0,scl=PIN_B1)

int8 Birim_Oku(int8 BirimID, int8 Komut)
{
int Deger_Donen, Deger_Birim_Adresi;
         Deger_Birim_Adresi = Birim_Tablosu[BirimID];
         i2c_start ();           
         i2c_write (Deger_Birim_Adresi);       //Köle adresi
         i2c_write (Komut);       //Komut  gönder
         i2c_stop();             
//         delay_us(50);
         i2c_start ();           
         i2c_write (Deger_Birim_Adresi + 1);       
         Deger_Donen = i2c_read();   
         i2c_stop ();           
return Deger_Donen;         
}



Posted on: August 15, 2008, 09:10:35 21:10 - Automerged

for slave (877) some of my codes

#INT_SSP
void ssp_interupt ()
{
   I2C_Durumu = i2c_isr_state();
   if(I2C_Durumu < 0x80)                 //efendi bilgi gönderiyor
   {
   if(I2C_Durumu == 0)
   {
   }
   if(I2C_Durumu == 1)                   //ilk bayt komut
   {
      Komut = i2c_read();
      Tampon_Gonder  = BK_KOMUT_YOK;
      switch(Komut)
      {
..........................
            break;
      default: break;
      }
   }
   if(I2C_Durumu == 2)                   //alınan ikinci byte
   {
      buffer[Adres] = i2c_read();
   }
   }
   if(I2C_Durumu == 0x80)                //efendi bilgi istiyor
   {     
      switch(Tampon_Gonder)
      {
.......................
            i2c_write (Donecek_Deger);
            break;
      default: break;
      }
   
   }
}


Posted on: August 15, 2008, 09:16:53 21:16 - Automerged

i used these codes for communicate 877 (master) with 877 (slave). And there isn't any problem. it is working with 877 to 877. but not worked 2550 (master) to 877 (slave).



Posted on: August 15, 2008, 09:20:57 21:20 - Automerged

i tryed with 3k...

i'm building aircraft cockpit...
« Last Edit: August 15, 2008, 09:28:14 21:28 by ugur » Logged
omeryld
Newbie
*
 Muted
Offline Offline

Posts: 11

Thank You
-Given: 14
-Receive: 13


« Reply #6 on: January 19, 2009, 07:47:38 07:47 »

hi,
i think your code is right. sometimes proteus is working wrong with i2c.
try it in a breadboard. it must work.

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