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 support@ccsinfo.com

Help with i2c communication in MULTI_MASTER MODE between PIC

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



Joined: 26 Apr 2009
Posts: 11

View user's profile Send private message

Help with i2c communication in MULTI_MASTER MODE between PIC
PostPosted: Wed Jan 12, 2011 8:13 am     Reply with quote

Hello everyone, before everything I am going to explain my situation.

We are developing a project that there are some PICs and they “speak” together using two lines I2C bus (we use CCS compiler).
The idea is that there is one MASTER PIC and it manages all communication between other PICs. This PIC is called CEREBRO (Brain in English) and we use the PIC18F2550.
Ideally, we have one tree, on top of, there is CEREBRO and on branches other SLAVES PICs. All communications go through CEREBRO.
The problem is that there are some microcontrollers (not from MICROCHIP) that can’t be SLAVE (only MASTER mode, like GSM and WIFI modules).
This is the first problem, so we need to use MULTI_MASTER mode on CEREBRO PIC to be in some cases SLAVE and other cases MASTER.
After doing some tests (simplifying our problem, communication between one master and one slave; communication between one master and two slaves) trying to write and read on slave. All tests worked ok.
[b]


Last edited by mizzard on Tue Jul 12, 2011 2:35 pm; edited 1 time in total
NeliusMicrocare



Joined: 12 Jul 2011
Posts: 1
Location: South Africa

View user's profile Send private message Send e-mail Visit poster's website

I also have a similar problem.
PostPosted: Tue Jul 12, 2011 8:10 am     Reply with quote

Hello Mizzard.

I also have a similar problem, can you please tell me if you have managed to resolve the problem?

I have started to develop the serial router to route all serial devices to the one Weblynx. The serial router uses a 16F886 pic on each serial port (8 serial ports on a router) to buffer data coming in. All pics are connected via I2C bus and as data comes in the pic sends it to the destination serial port (pic) through the I2C bus.
This means that all PIC's must operate as multi_master.

Before I started this project I looked at your "CCS Form". It looked like a lot of developers were struggling with using I2C in multi_master mode and some of them speculated that there are some bugs in the older versions of your compiler.

For this reason I started off slowly, wrote code for 3 slaves and one master to test the communications. It works fine and as expected. However I can not get the multi_master mode to work.

I have the PCM compiler V4.012.

When I enable SSP interrupt with the PIC in master mode it is able to send off only one byte (the address) then the main loop stops / freezes / hangs.

When I enable SSP interrupt with the PIC in multi_master mode it is no able to send off any data and the main loop stops / freezes / hangs.

When I disable SSP interrupt with the PIC in master mode or in multi_master mode every thing works properly and the master can communicate with the slaves in sequences.

As the slave receives data addressed to it, it will toggle an led.

Here are some of the snip bits of code.
Code:

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Slave's: //////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

   //#use I2C(slave,sda=PIN_C4,scl=PIN_C3, address=0xB0,FORCE_HW)
   //#use I2C(slave,sda=PIN_C4,scl=PIN_C3, address=0xC0,FORCE_HW)
   //#use I2C(slave,sda=PIN_C4,scl=PIN_C3, address=0xD0,FORCE_HW)

#INT_SSP
void i2c_isr(void) {

   int8 state;
   state = i2c_isr_state();
   output_toggle(LED_rx);
   
   if(state == 0){
      // 0 - Address match received with R/W bit clear
      
   }else if(state == 80){
      // 0x80 - Address match received with R/W bit set; respond with i2c_write()
      
   }else if(state > 80){
      // 0x81-0xFF - Transmission completed and acknowledged; respond with i2c_write()
      
   }else if(state > 0){
      // 1-0x7F - Master has written data; i2c_read() will immediately return the data
      state = i2c_read();
   }else{
   
   }

}

void init (void) {
   setup_oscillator(OSC_8MHZ);
   set_tris_a (0b00000000);
   set_tris_b (0b11110000);
   set_tris_c (0b10000100);
   set_tris_e (0b00000000);
   
   SETUP_ADC_PORTS(no_analogs);
   SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_16);         // every 2.048 milisec
   
   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   delay_ms (500);
   
   while(1){
      output_toggle(LED_tx);
      delay_ms(500);
   }
}

void main (void) {
   
   int1 ack;
   
   init ();

}


Code:

////////////////////////////////////////////////////////////////////////////
Master (the master has the same SSP as the slaves); ////////////////////////////////////////////////////////////////////////////

   //#use I2C(MASTER,sda=PIN_C4,scl=PIN_C3, address=0xA0,FORCE_HW)
   //#use I2C(MULTI_MASTER,sda=PIN_C4,scl=PIN_C3, address=0xA0,FORCE_HW)

   // in the main loop otherwise the same as the slave
   while(1){
         output_toggle(LED_tx);
      i2c_start ();        // init I2C protocol
      i2c_write (0xB0); // slave device address
      i2c_write (0x10);      // slave ‘internal memory address’ [0;15]
      i2c_write (0x20);
      i2c_stop();         // stop communication with slave
      delay_ms(500);
            output_toggle(LED_tx);
      i2c_start ();        // init I2C protocol
      i2c_write (0xC0); // slave device address
      i2c_write (0x10);      // slave ‘internal memory address’ [0;15]
      i2c_write (0x20);
      i2c_stop();         // stop communication with slave
      delay_ms(500);
            output_toggle(LED_tx);
      i2c_start ();        // init I2C protocol
      i2c_write (0xD0); // slave device address
      i2c_write (0x10);      // slave ‘internal memory address’ [0;15]
      i2c_write (0x20);
      i2c_stop();         // stop communication with slave
      delay_ms(500);
      
   }
Kind regards
Nelius
_________________
www.microcare.co.za
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 11:45 am     Reply with quote

The 16F886 is buggy in i2c slave mode. Here is the errata sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/80302F.pdf
I suggest that you use a different PIC (not in the 16F882-887 family)
to develop your i2c slave.
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