![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
Wireless serial comunication. |
Posted: Tue Jun 20, 2006 5:19 pm |
|
|
Hi,
I've read all posts of this forum about wireless comunication between PICS but i still can't interface them.
I've already used RS232 communication between PIC with good results. Now i'm trying to do it using FSK 433MHZ modules. I try to send one or more caracthers from Transimmetr and apparently it seems send something. But receiver can't get data. I used both INT_RDA or KBHIT without results. Using INT_RDA as i power up receiver it enter in interrupt routine even if transmitter is off. when i put on transmitter it sends but receiver doesn''t receive what i want . i don't know if it receive and if it enter again in interrupt routine.
I'll put her my code: TX
Code: | #include <16f88.h>
#fuses INTRC, NOPROTECT, NOPUT, NOWDT, MCLR, NOLVP , NOBROWNOUT
#use delay(clock = 4000000)
//#use fast_io(A)
//#use fast_io(B)
#use rs232(baud=2400, xmit=PIN_B5,rcv=PIN_B2, PARITY=e )
#define INTS_PER_1S 488 // (8000000/(4*16*256))
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
char codice=8;
char premuto=0;
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 60 times
if(--int_count==0) // per second.
{
int_count=INTS_PER_1S;
}
}
main(void)
{
SET_TRIS_A(0b11111101);
SET_TRIS_B(0b11011111);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
output_low(PIN_A1);
output_high(PIN_B5);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_8MHZ);
//setup_wdt(WDT_576MS);
int_count=INTS_PER_1S;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
delay_ms(25);
while(TRUE)
{
premuto=0b10101010;
while ( !input(PIN_B1) )
{
printf("%C",premuto);
OUTPUT_toggle(PIN_A1);
delay_us(10);
}
}
}
|
RX
Code: |
#include <16f88.h>
#fuses INTRC, NOPROTECT, NOPUT, NOWDT, MCLR, NOLVP , NOBROWNOUT
#use delay(clock = 4000000)
//#use fast_io(A)
//#use fast_io(B)
#use rs232(baud=2400, xmit=PIN_B5,rcv=PIN_B2, PARITY=e )
#define INTS_PER_1S 488 // (8000000/(4*16*256))
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
char codice=0;
char comando=0;
int t;
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 60 times
if(--int_count==0) // per second.
{
int_count=INTS_PER_1S;
}
}
#define BUFFER_SIZE 30
char buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_rda
void serial_isr() {
int t;
buffer[next_in]=0;
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
codice=buffer[next_in];
comando=getc();
output_high(PIN_A2);
if (comando==0b10101010)
output_high(PIN_B3);
}
#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);
}
main()
{
SET_TRIS_A(0b00000000);
SET_TRIS_B(0b00000100);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_8MHZ);
//setup_wdt(WDT_576MS);
buffer[12]=0;
setup_spi(FALSE);
int_count=INTS_PER_1S;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_16);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
output_high(PIN_A2);
delay_ms(1000);
while(TRUE)
{
/* if(kbhit())
{
comando=getc();
output_toggle(PIN_B3);
}
*/
if (comando!=0)
output_high(PIN_A2);
if (comando==0b10101010)
output_high(PIN_B3);
if(comando== 0b10101010)
output_high(PIN_A1);
//else
// output_low(PIN_A1);
}
}
|
i'm sorry it is a little confused but i made several tests.
what should i change?? |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
![](templates/subSilver/images/spacer.gif) |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Wed Jun 21, 2006 2:56 am |
|
|
Thanks but as I sayed I already read that post. I took my inspiration from it.
I also tryed it in my device without success:
RX
Code: |
#include <16F88.h>
#define Fosc 40000000
#define WireTX PIN_B5
#define WireRX PIN_B2
#use delay(clock = Fosc,RESTART_WDT)
#fuses INTRC, NOPROTECT, NOPUT, NOWDT, NOLVP , NOBROWNOUT
#use rs232(baud=9600, xmit=WireTX, rcv=WireRX, ERRORS, STREAM=Wireless)
#define RX_BUFFER_SIZE 40
#define TX_BUFFER_SIZE 40
int8 rx_wr_index = 0, tx_rd_index = 0, tx_wr_index = 0, tx_counter = 0, received = 0;
int8 lock_state = 0, rxd, i, valid_data_count;
unsigned int8 rx_buffer[RX_BUFFER_SIZE + 1], tx_buffer[TX_BUFFER_SIZE + 1];
int1 data_avail = FALSE, got_id = FALSE;
#int_RDA
void RDA_isr(void) {
rx_buffer[rx_wr_index] = getc();
rxd = rx_buffer[rx_wr_index]; // this just makes it easier typing-wise later on
rx_wr_index++;
if (rx_wr_index > RX_BUFFER_SIZE) {
rx_wr_index = 0;
}
// now look for unique ID: "Dave "
if (rxd == 'D' && lock_state == 0) {
lock_state++;
}
else if (rxd == 'a' && lock_state == 1) {
lock_state++;
}
else if (rxd == 'v' && lock_state == 2) {
lock_state++;
}
else if (rxd == 'e' && lock_state == 3) {
lock_state++;
}
else if (rxd == ' ' && lock_state == 4) { // got the entire string "Dave ", in that order
lock_state = 0; // reset our "combination lock"
got_id = TRUE;
valid_data_count = 0xff; // get ready to count the number of data bytes - we know we have to expect 5 (Rocks)
// also going to reset the buffer write index back to 0, so that I know where my valid data will be
rx_wr_index = 0;
}
else { // we didn't receive "Dave ", so reset the lock back to the beginning
lock_state = 0;
}
if (got_id && ++valid_data_count == 5) {
data_avail = TRUE;
got_id = FALSE;
}
}
#int_TBE
void TBE_isr(void) {
if (tx_counter != 0) {
putc(tx_buffer[tx_rd_index]);
if (++tx_rd_index > TX_BUFFER_SIZE) {
tx_rd_index = 0;
}
tx_counter--;
if (tx_counter == 0) {
disable_interrupts(INT_TBE);
}
}
}
void bputc(int c) {
int restart = 0;
while (tx_counter > (TX_BUFFER_SIZE - 1));
if (tx_counter == 0) {
restart = 1;
}
tx_buffer[tx_wr_index++] = c;
if (tx_wr_index > TX_BUFFER_SIZE) {
tx_wr_index = 0;
}
tx_counter++;
if (restart == 1) {
enable_interrupts(INT_TBE);
}
}
void main() {
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
enable_interrupts(INT_RDA);
//enable_interrupts(INT_TBE);
enable_interrupts(global);
output_high(PIN_A2);
while (TRUE) {
restart_wdt();
if (data_avail) {
data_avail = FALSE;
output_toggle(PIN_B3);
};
}
}
|
TX
Code: |
#include <16F88.h>
#include <STRING.H>
#include <STDIO.H>
#include <STDLIB.H>
#define Fosc 40000000
//-------------------------------------------------------------------------------------
// DEFINES
#define WireTX PIN_B5
#define WireRX PIN_B2
//-------------------------------------------------------------------------------------
// COMPILER DIRECTIVES and HARDWARE CONFIGURATION
#use delay(clock = Fosc)
#fuses INTRC, NOPROTECT, NOPUT, NOWDT, NOLVP , NOBROWNOUT
#use rs232(baud=9600, xmit=WireTX, rcv=WireRX, ERRORS, STREAM=Wireless)
void main()
{
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
output_low(PIN_A1);
//output_low(PIN_B5);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
while(1)
{
output_toggle(PIN_A1);
fprintf(Wireless, "%c", 0xBA); // LAM - something for the RX's USART to "lock onto"
fprintf(Wireless, "%c", 0xBE); // LAM - something for the RX's USART to "lock onto"
fprintf(Wireless, "%c", 0xFA); // LAM - something for the RX's USART to "lock onto"
fprintf(Wireless, "%c", 0xCE); // LAM - something for the RX's USART to "lock onto"
fprintf(Wireless,"Dave Nice\r"); // I'm going to get the RX code to look for "Dave " as the ID...
// ...and "Rocks" as the command/data
delay_ms(500);
}
}
|
It's like as i power up receiver it goes enter immediately in INT_RDA and never get out of it.
I put HIGH PIN_A2 in INT RDA and in while true I also put some code but as i power up device it set high PIN A2 and doesn't execute code in while(true).
can you help me?? |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jun 21, 2006 9:57 am |
|
|
So, help me here. Have you been able to communicate between PIC's with this code? If not, I would try to establish communications between the PIC's directly first and prove that your code works before you start to enter outside problems. Once the code will allow the two PIC's to talk to each other, when hard-wired together, then try to put the wireless components into the circuit. A scope would be of tremendous help to ensure that you have an RF output, too. I've never tried to use one of those modules so I'm not sure how to get them going. I like to take the easy route and used a wireless module from www.maxstream.net called the XBEE. It's very compact and works quite well.
Good luck!
Ronald |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Wed Jun 21, 2006 10:13 am |
|
|
Ditto what Ronald said. Directly connect TX pic and RX pic - no RF modules between them. Get them talking first, then insert the RF tx & rx.
One thing I did notice, though - are you using the pic's internal oscillator (INT_RC fuse is set)? Be careful with the internal oscillator - it's not very stable. You may have troubles matching baud rates between TX and RX. |
|
![](templates/subSilver/images/spacer.gif) |
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Wed Jun 21, 2006 10:45 am |
|
|
Finally i got it!!
i don't know if it's only my fault or compiler fault too.
I added an instruction to force rs232 rx as INPUT as variable=input(PIN_B2); in main() and after it the code worked perfectly.
in my first code i set tris as input but i hadn't results so in homfray's code i didn't do it as he did.
what do you think about it?? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|