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

wireless comms between pics

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

wireless comms between pics
PostPosted: Mon Jul 04, 2011 3:03 am     Reply with quote

FROM : http://www.ccsinfo.com/forum/viewtopic.php?t=23953

Hi Guys, I am trying to use this code with the following transceivers TRM-433 from http://www.linxtechnologies.com/resources/data-guides/trm-xxx-lt.pdf linx technologies. For now I have omitted the transceivers and connected the tx microcontroller board straight to the RX.. But for some reason the Interrupts are not firing.

Can some please check if my fuses are correct as this is the first time I am working with the 24 series. compiler 4.120

The TX code:
Code:


#include <24FJ32GA004.h>
#device ICD=TRUE
#device ADC=10
#include <STRING.H>
#include <STDIO.H>
#include <STDLIB.H>


//#include "hardware_tx.c"
#define LED_GREEN PIN_A9
#define LED_RED PIN_A4

#define WireTX PIN_C4
#define WireRX PIN_A8

#define TRSEL PIN_C3

//setup global variables

#use delay(clock=8M)
//#include "comms_tx.c"
#use rs232(baud=1200, xmit=WireTX, rcv=WireRX, ERRORS, STREAM=Wireless) 
//Fuses

#FUSES PR                  //Use Primary oscillator
#FUSES NOWDT               //No Watch Dog Timer
#FUSES NOJTAG               //JTAG disabled
#FUSES NOPROTECT            //Code not protected from reading
#FUSES NOWRT               //Program memory not write protected
#FUSES NODEBUG               //No Debug mode for ICD
#FUSES ICSP3                  //ICD communication channel 3
#FUSES NOIOL1WAY            //Allows multiple reconfigurations of peripheral pins
#FUSES OSCIO               //OSC2 is IO output
#FUSES XT                  //High speed Primary Oscillator 4 - 10 MHz
#FUSES I2C1SELD               //I2C pin location select

void main()
{
   //init();
set_tris_c(0x00);
set_tris_a(0x00);
output_high(TRSEL);
while(TRUE)
   {
     output_low(LED_RED);
      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 Rocks\r"); // I'm going to get the RX code to look for "Dave " as the ID...
      // ...and "Rocks" as the command/data
   
      delay_ms(5000);
   output_high(LED_RED);    
   }
   
}





THE RX CODE :
Code:

#include <24FJ32GA004.h>
#device ICD=TRUE
#device ADC=10

//#include "hardware_rx.c"
//Setup Pin Definitions
//Global Pins
#define LED_GREEN PIN_A9
#define LED_RED PIN_A4
#pin_select U1RX = PIN_C4

#define WireRX PIN_C4
#define PcTX PIN_B4

#define TRSEL PIN_C3

//setup global variables

#use delay(clock=8M)
//#include "comms_rx.c"
#use rs232(baud=1200,rcv=WireRX, ERRORS, STREAM=Wireless)
#use rs232(baud=1200, xmit=PcTX, ERRORS, STREAM=Pc) 
//Fuses

#FUSES PR                  //Use Primary oscillator
#FUSES NOWDT               //No Watch Dog Timer
#FUSES NOJTAG               //JTAG disabled
#FUSES NOPROTECT            //Code not protected from reading
#FUSES NOWRT               //Program memory not write protected
#FUSES NODEBUG               //No Debug mode for ICD
#FUSES ICSP3                  //ICD communication channel 3
#FUSES NOIOL1WAY            //Allows multiple reconfigurations of peripheral pins
#FUSES OSCIO               //OSC2 is IO output
#FUSES XT                  //High speed Primary Oscillator 4 - 10 MHz
#FUSES I2C1SELD               //I2C pin location select

#define RX_BUFFER_SIZE 80
#define TX_BUFFER_SIZE 80

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;
     //output_high(LED_GREEN);
   }
   
   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() {

   set_tris_c(0b0000100000);
   set_tris_a(0x00);
   output_low(TRSEL);  // TCTX is in receive mode

   enable_interrupts(INT_RDA);
   //enable_interrupts(INT_TBE);
   enable_interrupts(INTR_GLOBAL);

   set_tris_b(0x00);
   fprintf(Pc,"TX is working");

   while (TRUE) {
      //restart_wdt();

      if (data_avail) {
         data_avail = FALSE;
         fprintf(Pc,"\r\n\r\nData is now available\r\nData: ");
       //output_high(LED_GREEN);
         for (i = 0; i < 5; i++) {
            fprintf(Pc,"%c",rx_buffer[i]);
         }
      }
   }
}


[/url]
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 04, 2011 4:55 am     Reply with quote

Quik comment.

divide and conquer !

Breadboard the system without the wireless modules and get the two PICs talking to each other using just the hardware RS232 connections.

Once that's 100% THEN add the wireless modules as debug them.

That way YOU knw the PICs are OK as well as 99% of your code !
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Mon Jul 04, 2011 6:39 am     Reply with quote

I just did, I used a 18f4550 as the receive side as no matter what I try I cant get the pic 24 to interrupt on the serial. So the code works now its just the modules..
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

wireless comms between pics
PostPosted: Mon Jul 04, 2011 11:59 am     Reply with quote

I have successfully implemented the wireless connection between my RX and TX but now the issue remains to structure the data and to formulate a protocol and error correction.

I think its fairly safe to say that avoid pure cable replacement transceivers, if you are not able to do some level of protocol and error correction.

Thanks

O yea.. I solved my issue by lower the tx code delay from 5000 ms to 100ms. As when there is no communication the RX transceiver picks up so much noise that its basically unusable
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
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