Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic Microcontroller Slave and Master

Status
Not open for further replies.

dfullmer

Full Member level 5
Joined
Jun 7, 2006
Messages
252
Helped
36
Reputation
72
Reaction score
9
Trophy points
1,298
Location
Some place Hot - Not an Island
Activity points
2,864
pic microcontroller i2c

Hi Everyone,

I am thinking about running several Pic's in a slave and master mode. Has anyone had experiance in doing this? Can you give me any advice that might save some stumbling block?

Thanks


dfullmer
 

sspadd slave

I've never worked with PICs but I am not sure if PIC comes with such capabilites in hardware. If you want to implement it in software its quite easy. I've done it with AVRs and 8051s.

I2C/SPI is a definite go if its available as it allows such communication.
You can memory map the slaves in masters address range thereby making slave PICs as peripherals to the master.

More exotic stuff like shared memory based message passing is too much overhead for such simple applications.
 

    dfullmer

    Points: 2
    Helpful Answer Positive Rating
master slave microcontroller

dfullmer said:
Thanks kishore2k4,

I'll take all the info I can get.

regards

dfullmer

What exactly are you looking for? Let us know your requirements so forumers can give to-the-point answers, Instead of re-writing entire chapters :)
 

pic i2c slave

Your right I should be more descriptive,


Okay, so I want to put together four or five pic16F877A with a slave/master relationship. As you stated I2C or SPI with addresses for each. I have set up an I2c display driver and I am starting to get a handle on how to do the I2C comunication. I have also done SPI (a little) in the past and have used this successfully. It would be great if someone had some software example of a slave/master code for MicroCode studio that I could expand on. Each of the devices will have its own tasks to perform and I need to understand how to call each one independantly and talk to it. Is it an iterupt basis or poll. This is part of my lack of knowledge. Based on the data sheet for the 877A it seems to have this capability. I was hoping to get an example from someone. My forhead is flat enough from banging against my desk I don't need to add to it. :D

Thanks again any info you have would be appreciated.

Regards

dfullmer
 

sspcon ckp slave

Attached are a couple of code snippets for master transmission/reception and 10-bit slave reception.

These were test cases so pins have been driven to indicate status (e.g. BF flag set, Interrupt Routine entered, etc.)

We have many customers developing multi-core systems as, when you step or debug in Proteus, the whole system advances/pauses in time so you don't have secondary processors charging off whilst you are debugging the primary.

The I2C and SPI protocol analysers can also act as either Master or Slave devices so you can simply type in sequence and inject them onto the bus to test TX/RX to or from a mc.
 

    dfullmer

    Points: 2
    Helpful Answer Positive Rating
master salve microcontroller

Wow Iain,

Thanks this will be helpful. I can follow the code for the most part and can work on adapting it to my application. Unfortunatly I am not a programmer I am a hardware guy and the assembly code takes me a bit of thinking. The "basic" coding is where my head normally can reach. If you come across anything is basic this would be appreciated also. Thanks again

cheers

dfullmer
 

master slave microcontroler

No basic I'm afraid but heres a very basic <grin> 7-bit slave reception (16f887) in C.

Code:
#include <system.h>

#pragma CLOCK_FREQ   16000000
#pragma DATA _CONFIG1, _HS_OSC & _MCLRE_ON & _WDT_OFF
#pragma DATA _CONFIG2, _WRT_1FOURTH & _BOR21V

// Test I2C in Slave mode with mask address register. 


// I2C Addresses and Commands
#define I2C_ADDRESS 0xA8

void interrupt (void)
 { if (pir1.SSPIF) 
    { portc.7 = pir1.SSPIF;      // mirror the SSPIF state. 
      portc.7 = pir1.SSPIF=0;
      portc.6 = sspstat.BF;
      if (sspstat.S & sspstat.BF) 
         // Slave receives address/data after start
         portb = sspbuf;
      
      portc.6 = sspstat.BF;
    } 
 }

void main()
 { portc.7  = 0;
   portc.6  = 0;
   trisc.3  = 1;  // SCL as inputs (release bus)
   trisc.4  = 1;	// SDA as inputs (release bus)
   trisc.6  = 0;  // used to flag BF bit
   trisc.7  = 0;  // used to mirror the state of SSPIF
   portb    = 0;
   trisb    = 0;   
   // Make low nibble bits as "don't care" bit address.
   // This register *must be* initiated prior to setting SSPM<3:0> bits to select the I2C Slave mode (7-bit or 10-bit address). 
   // Note that SSPMASK coincides with SSPADD and that we should write SSPCON with 0b1001 in order to have access to it. 
   sspcon.SSPM0 = 1;
   sspcon.SSPM1 = 0;
   sspcon.SSPM2 = 0;            
   sspcon.SSPM3 = 1;
   sspadd = 0xF0;
   // Activate I2C, Slave mode, 7Bit, with Start/Stop bit interrupt 
   sspcon.SSPM0 = 0;   
   sspcon.SSPM1 = 1;
   sspcon.SSPM2 = 1;            
   sspcon.SSPM3 = 1;
   // SSPSTAT Status Register
   sspstat.SMP  = 0;	      // Slewrate Control disabled
   sspstat.CKE  = 0;	      // SMBUS specific inputs disabled
   // CKP, Release Clock
   sspcon.CKP   = 1;
   // Disable Address 0x0 General Call
   sspcon2.GCEN = 1;
   // Disable clock stretching
   sspcon2.SEN  = 0;	
   // Set I2C Slave address 
   sspadd = I2C_ADDRESS;	
   // Synchronous Serial Port Enable
   sspcon.SSPEN  = 1;	
   // dummy read clears BF
   unsigned int dummy = sspbuf;         
   // Clear Buffer Overflow
   sspcon.SSPOV = 0;	      
   // Receive Enable
   sspcon2.RCEN = 1;       
   // Enable Global,  Peripheral and SSP module interrupts
   intcon.GIE   = 1;       
   intcon.PEIE  = 1;       
   pie1.SSPIE   = 1;	      
  
   // do it forever   
   while(1) ;
 }
 
  • Like
Reactions: kjagdish

    dfullmer

    Points: 2
    Helpful Answer Positive Rating

    kjagdish

    Points: 2
    Helpful Answer Positive Rating
microcontroller i2c master/slave

**broken link removed**
 

pic als slave

pl consider PSP (parallel slave port) also, as i feel its simpler.

i ve seen working examples of TI DSP as a master and 16f87* as a slave
 

can microcontroller be a master

One nice thing about PIC chips is that they can be easily synchronised - run them on the same clock source and the same reset signal, you can write code that works in parallel. I had a situation where I used 3 PIC 18F devices, two were between them transmitting a 10Mb/s bit stream (alternating 5Mb/s each at offset instruction cycles), whilst receiving data from a third PIC at 1.25MByte/s via PSP! Great fun to develop (nightmare to debug) but worked really well!

If you don't need rapid transfer though, the I2C slave/master is probably a good choice....:D
 

    dfullmer

    Points: 2
    Helpful Answer Positive Rating
pic sspm i2c

Is I2C/SPI interface is a feasible solution for inter communications of MultiCore.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top