View previous topic :: View next topic |
Author |
Message |
farazwan
Joined: 26 Apr 2012 Posts: 13
|
How to transmit and receive adc data using zigbee? |
Posted: Thu Apr 26, 2012 3:31 am |
|
|
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
|
|
Posted: Thu Apr 26, 2012 6:14 am |
|
|
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
For zigbee, if you use mrf24j40, you can search for easybee3 examples and port it to CCS. |
|
|
farazwan
Joined: 26 Apr 2012 Posts: 13
|
|
Posted: Thu Apr 26, 2012 7:35 am |
|
|
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
|
|
Posted: Thu Apr 26, 2012 7:55 am |
|
|
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
|
|
Posted: Thu Apr 26, 2012 8:15 am |
|
|
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
|
|
Posted: Thu Apr 26, 2012 9:01 am |
|
|
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: 9224 Location: Greensville,Ontario
|
|
Posted: Thu Apr 26, 2012 3:25 pm |
|
|
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
|
|
Posted: Fri Apr 27, 2012 3:50 am |
|
|
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
|
|
Posted: Fri Apr 27, 2012 7:52 am |
|
|
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
|
|
Posted: Fri Apr 27, 2012 9:15 am |
|
|
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
|
|
Posted: Fri Apr 27, 2012 1:08 pm |
|
|
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 |
|
|
|