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

1 master and 2 slave

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



Joined: 21 May 2012
Posts: 11

View user's profile Send private message

1 master and 2 slave
PostPosted: Sun Jun 03, 2012 3:49 am     Reply with quote

can anyone give idea what type of instruction needed to receive data from 2 slaves...please!!!!really need help..
temtronic



Joined: 01 Jul 2010
Posts: 9218
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 5:24 am     Reply with quote

You could look at some of the examples that CCS has kindly supplied in the 'examples' folder...there are SEVERAL great examples in there!
You should specify the PICs you're using...
Distance between the PICs? inches or miles? I've done both for 20 years...
Data? small(a few bits) or large(dozens of bytes)..
Rate? slow(once in a blue moon), fast( 1/2 megabaud?
Security? none..easy to do, just send data...some...better...encrypted ?
Linkage? wire, wireless, IR, RF, sonar, current loop, piezo, 3state, 2state, rs485, rs232, rs422?
How soon must this project be done?
Which compiler and version?

The more information YOU supply the better and faster you'll get answers here.
RHA



Joined: 25 Apr 2006
Posts: 31
Location: Germany

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 11:15 pm     Reply with quote

An easy way should be CAN.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 11:26 pm     Reply with quote

This thread has three i2c slave PICs connected to an i2c Master PIC.
The master reads an 8-bit ADC value from each slave. The slave
PICs update their ADC value every 500 ms.
http://www.ccsinfo.com/forum/viewtopic.php?t=39242&start=15
LoVeLy



Joined: 21 May 2012
Posts: 11

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 2:05 am     Reply with quote

Master = PIC18F4525..only received data from 2 slaves and display on LCD.

Slave = PIC18F252 for both slaves..only transmit 8 bit data.

I'm using zigbee in order to transmit and receive data.

Supposely this project must be done less than 2 weeks.
I can received and display only data from 1 slave.
But I've a problem when receive data from 2 slaves.
LoVeLy



Joined: 21 May 2012
Posts: 11

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 2:49 am     Reply with quote

is there another method instead of using i2c??
in my project, master only receive data and slave only transmit data..
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 3:11 am     Reply with quote

LoVeLy,

I2C is good, but only for a wire distance up to 3 meters and maximum 400 kbit/s. You mention Zigbee, this is wireless and then I2C can not be used.

You really have to answer all of Temtronic's questions, and perhaps give even more information. Right now you answered only 2 or 3 of his questions and that is why you get suggestions that are only making you more confused.

Do you need wireless?
If yes, then Zigbee is possible. Mention the brand and type number of your modules (and answer _all_ Temtronic's questions).
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 3:20 am     Reply with quote

I don't think you actually have a 'master/slave' situation. Master/slave, implies _two way_ communication, with one device 'asking' the other(s) for their data. To do this using Zigbee modules would mean you would have to have both a receiver and a transmitter module attached to each unit.

What it sounds as if you have is single receiver, multiple transmitter communication. If so, this is relatively harder.

First, you would need to design your data packet that the sensors are going to send, to be identifiable, and testable for interference. So something like the device number, preceding a block of data, followed by a checksum on the whole thing.

Then you would have to design an algorithm to randomise the transmission intervals between the modules. Problem here is that generating anything truly 'random' is very difficult, but if you take a count from a timer, since the chip was powered up, providing the units are not coming from the same PSU, this gives at least a starting point. Use this to select an 'interval' from a list stored as a const array. So something like
Code:

   int16 tick;
   const int8 delays[20,30,50,70,110,130,170,190];

   do {
      send_message(); //Transmit the sensor data block
      tick=get_timer0();
      delay_ms(delays[tick & 7]+UNITID);
   }

Now, the receiver unit, then listens for the packets, and when it receives something, looks for the ID, and a valid checksum, if these are OK, decodes the data.

Key is that if both slaves transmit at similar times, the data _will_ be corrupted, so the 'master' will ignore it. But unless you are incredibly unlucky, provided the packets are quite short (no more than 10mSec for the delays given here), the chances are tiny that the next block will also clash. UNITID, is assumed to be an integer, perhaps 1,2,3 etc., for the remote senders. Adding it to the delay, ensures that in the nasty case that both units wake up 'in sync', and start sending in sync, they will slowly drift apart. Packets _will_ be lost occasionally, but more should get through, than are lost.

Best Wishes
LoVeLy



Joined: 21 May 2012
Posts: 11

View user's profile Send private message

PostPosted: Wed Jun 20, 2012 9:56 am     Reply with quote

I've something to ask.
I can receive two data from two different Zigbee by using delay.
I want the lcd display TEMP1 from Zigbee 1 and TEMP2 from Zigbee 2.
but the problem is sometimes TEMP1 display data from Zigbee 2 and vice versa.
So, anyone has an idea how to solve this problem?
Really need help.
temtronic



Joined: 01 Jul 2010
Posts: 9218
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 20, 2012 10:35 am     Reply with quote

Without seeing all your code it is hard to correctly answer however one solution is to have each slave send an 'id number' as well as it's data.
This way there is a unique 'link' between the slave data and the actual PIC slave .
Since the master PIC now KNOWS what data came from WHICH slave PIC, it can display on the LCD as required.
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Wed Jun 20, 2012 11:47 am     Reply with quote

Exactly. The line beginning 'First', in my reply. The packets, _must_ have an ID, plus the data, plus a checksum, so you know who the packet is from, and whether the packet is valid.

Best Wishes
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Jun 20, 2012 11:51 am     Reply with quote

Hi LoVely,

You seem to favor posing impossibly vague questions with not a shred of code to help illustrate what it is you want, or have in mind. Might I be so bold as to suggest that this is not a great long-term strategy for asking for help here on the forum?

John
djaxudsuer@yahoo.com



Joined: 08 Jul 2012
Posts: 1

View user's profile Send private message

2 sensor nodes and 1 coordinator using xbee
PostPosted: Sun Jul 22, 2012 7:34 pm     Reply with quote

I have the problem that Ttelmah state...when sending data from 1 node, there is no problem at all, but by send by two nodes, the data start to collide and sometimes it separate from id and data. Here i attach my code my result when 2 sensor nodes transmit data to coordinator.
First of all my PIC will send +++ to coordinator to give node identifier to coordinator (ATNI). Then, it will read the adc from sensor LM35 and send the data.

Code:

#include "18f2525.h"
#fuses NOLVP,NOWDT,PUT,BROWNOUT,INTRC_IO
#use delay(clock=2000000)
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7, ERRORS, PARITY=N, BITS=8, STOP=1)
#include <stdlib.h>
#include <stdio.h>

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr() {
   int t;
   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;   
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;
   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main(){
   int16 temp_adc=0; //16 bit integer, safer than using int because
                  //int is only 8 bit which might lead to overflow problems for add, multiply
   int x=0;
   float temp;
                 
   setup_adc(ADC_CLOCK_INTERNAL); //configure analog to digiral converter
   setup_adc_ports(ALL_ANALOG);   //set pins AN0-AN7 to analog (can read values from 0-255 instead of just 0,1)

   
   while(true){ //loop forever
   for (x=0; x<20; ++x){
      set_adc_channel(0);//set the pic to read from AN0
      delay_us(20);//delay 20 microseconds to allow PIC to switch to analog channel 0
      temp_adc=read_adc(); //read input from pin AN0: 0<=photo<=255
      temp = temp_adc * 0.7; // convert reading to Celsius
      delay_us(20);
     
      {

   enable_interrupts(int_rda);
   enable_interrupts(global);
   delay_ms(2000);
 
   
      delay_ms(2000);
      printf("+++");
      delay_ms(2000);
      printf("ATNI\r");
      delay_ms(2000);
      printf("ATCN\r");
      delay_ms(2000);
      while(bkbhit)
      putc( bgetc() );
      delay_ms(1000);
     
      printf("t %d :  ",x);
      printf("%2.1f ",temp);
      printf("\r");
      delay_ms(1000);
      delay_ms(1000);
      delay_ms(1000);
      delay_ms(1000);
      }
}


Result on terminal

When 1 sensor node:

OK
R1
OK
t0 : 11.9
OK
R1
OK
t1 : 16.8
OK
R1
OK
t2 : 16.8
OK
R1
OK
t3 : 16.1
OK
R1
OK
t4 : 16.1

This node is identified as R1.

When 2 sensor nodes:

OK
PRO2
OK
t2 0 : 12.5
OK
R1
OK
OK
PRO2
OK
.5
t0 : 14.0
OK
R1
OK
OK
PRO2
OK
.5
.0
OK
t2 1 : 15.4
OK
R1
OK
OK
R1
OK
OK
PRO2

1st node identified as R1 and, another is PRO2.

The data is totally lost and collide =( , from what we know, Zigbee has MAC layer that enable CSMA/CA. But it seems like that is not applied here.
The data is sometimes sent at the same time since it must for monitoring system.

I already think to send data by packet like Ttelmah said, but until now, I don't know how? How about the array? Please help me since i need to test my networking (mesh network), but if this collide matter cannot resolve, the networking part cannot perform well.
Thanks
Confused Crying or Very sad
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