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

How to transmit and receive adc data using zigbee?

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



Joined: 26 Apr 2012
Posts: 13

View user's profile Send private message

How to transmit and receive adc data using zigbee?
PostPosted: Thu Apr 26, 2012 3:31 am     Reply with quote

I'm trying to transmit data at remote and receive data at centre using zigbee pro. I'm using pic18f252 (28pin) at remote and pic18f4525 (40pin) at centre and using temperature sensor, TSiC 301. I've tried many coding that i searched from internet but i don't get solution. Please help me!!!
Code:

//transmit coding

#include <18f252.h>
#device ADC=8
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, rcv=PIN_C7, xmit=PIN_C6, PARITY=N)
#include <stdlib.h>

void main()
{

int32 fvalue;

setup_port_a(ALL_ANALOG);
set_tris_a(0x03);
set_tris_c(0x80);

set_adc_channel(0);
delay_ms(10);
fvalue=read_adc();
putc(fvalue);

}


Code:

//receive coding

#include <18f4525.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOLVP, NOPROTECT
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, PARITY=N)
#include <lcd.c>
#include <stdlib.h>


void main()
{
int32 fvalue;
int32 v1;

set_tris_a(0xff);
set_tris_b(0xff);
set_tris_c(0x80);
set_tris_d(0x00);
set_tris_e(0x00);
port_b_pullups(true);
lcd_init();
lcd_putc("\f");
lcd_gotoxy(3,1);
lcd_putc("HEALTH CARE");

while(true)
{

if(!input(pin_a0) )
{
fvalue=getc();
v1=(5*((int)fvalue)/255);
printf(lcd_putc,"\ftemp = %u",(int)v1);
}

}
}
}
Tak



Joined: 22 Apr 2012
Posts: 6

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 6:14 am     Reply with quote

From your code, i think you try to use A0 for ADC. Set up ADC with this:
Code:
 setup_adc_ports(AN0);//or setup_adc_ports(ALL_ANALOG)
 set_adc_channel(0);
 setup_adc(ADC_CLOCK_DIV_8);

the setup_adc_ports command will auto set A0 for input. fvalue and vl should be int8, delay 10ms 's a bit too much
Rolling Eyes
For zigbee, if you use mrf24j40, you can search for easybee3 examples and port it to CCS.
farazwan



Joined: 26 Apr 2012
Posts: 13

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 7:35 am     Reply with quote

i've tried the coding but it still not function..there is no data transmission occured..anyone has any suggestion??
ezflyr



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

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 7:55 am     Reply with quote

Hi,

Yes, spend a lot more time reading the forum, because your code, your project development strategy, and your request for help are all very flawed!

Why your request for help is flawed: You did not tell us what you NOT get "a solution" for???? Are your PICs actually running? Can you blink an LED at a predictable rate? Is the A/D working? Is everything working except for the wireless connection?? What exactly is the problem?? We are NOT mind readers.

Why your development strategy is flawed: You should be developing this project in stages. First, get each PIC running with a simple LED blink program. Then get the A/D working on the Transmit PIC using a connection to your PC and Hyperterminal for debugging. Then use the PC and Hyperterminal to send data to your Receive PIC to verify that you can receive data. Then connect the Transmit PIC and the Receive PIC together with a wire connection to test data transfer, and finally, once ALL THAT IS WORKING, test it with a wireless connection. Take it step-by-step, and divide and conquer each stage along the way to finishing your project!

Why your coding is flawed: You need to add the Errors keyword to the #use rs232 staement of your Receive code, and you need to get rid of the TRIS statements in all your code. These two points have been mentioned (literally) thousands of times here on the forums!

John
farazwan



Joined: 26 Apr 2012
Posts: 13

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 8:15 am     Reply with quote

For your information, I've tested for both pic and it functions well. I've also tested my sensor with ADC and its function well too. My LCD also working. The problem now is i can't transmit and receive the data using zigbee.
ezflyr



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

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 9:01 am     Reply with quote

Hi,

OK, but you should have said that in your 1st post in order to define the scope of your problem!

Post a link to the zigbee module you are using, and post your schematic of how you have it hooked up!

Thanks,

John
temtronic



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

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 3:25 pm     Reply with quote

Get rid of the zigbee modules and go PIC to PIC via RS232(MAX232s) and confirm it all works. THEN add the Zigbee modules. It should work, if not then it's a Zigbee problem..not your code.
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 3:50 am     Reply with quote

Hi
In your transmitter i think you forgot a while loop?

Code:
while (1) {
 fvalue=read_adc();
 putc(fvalue);
 delay_ms(1000);
}
ezflyr



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

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 7:52 am     Reply with quote

Hi hmmpic,

Of course, the way the original transmit code is written, the code would send one byte, and then go to sleep (via the hidden sleep instruction automatically added by the compiler). This would have been immediately obvious to the OP if he was taking a step-by-step approach to his project rather than trying to get everything working simultaneously! This is what happens if you treat code like a 'black box'. Instead, you've got to rip it apart and tackle small pieces until you can put them all together with confidence to achieve the whole project!

John
farazwan



Joined: 26 Apr 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 9:15 am     Reply with quote

I have try connecting pic to pic using max232 but it doesnt work. is it possible that my coding is wrong?
ezflyr



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

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 1:08 pm     Reply with quote

Hi farazwan,

Personally, I don't know why it was suggested that you connect PIC to PIC using MAX232 IC's as this is un-needed complication. Simply connect the Tx pin of the transmit board to the Rx pin on the receive board, and vice versa. Also be sure that each board shares a common GND connection.

Add the while loop to your code so that the data is being sent from the transmit board continuously.

Also, I asked you to post the type of zigbee module you are using, and a schematic of how you are hooking it up. If you don't do that, this is my last post on this thread.

John
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