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

Communicating two PICs via the MRF89XA

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



Joined: 15 Nov 2013
Posts: 2
Location: Argentina

View user's profile Send private message Send e-mail

Communicating two PICs via the MRF89XA
PostPosted: Fri Nov 15, 2013 7:25 am     Reply with quote

Hi to everyone,
I'm doing the final project of my career and when are using two PIC18LF2520 and two MRF89XA transceivers. We have made the two independent PCBS where to put the pics and the transceivers and they are working ok. We have bought the MRF89XAM8A integrated where it is the transceiver and also the antenna.
We configure the registers via the SPI and we can read the configurations correctly but when we want to communicate both transceivers via RF it doesn't work. We checked the signals with the oscilloscope (SPI signals) and they are fine. We don't know what the problem could be. Can anyone help us? We have been stuck in this problem for three weeks. This is the code we have made and we are using packet mode, FSK mode, SOFTWARE SPI.
Thank you very much,
Jhon Ignace
Code:

#include"C:\Users\Juan\Desktop\Proyecto\codigos\transmisor_prueba_2\main.h"
#include <float.h>
#include <math.h>
#use spi(DI=PIN_C4, DO=PIN_C5, CLK=PIN_C3,MODE=0,BAUD=25000,STREAM=cu)
#define DATOS PIN_C6
#define CONFIG PIN_C7

void configuracion(int8 a){
   
   output_high(DATOS);   // NO DATOS
   output_low(CONFIG);   // SI CONFIGURACION
   if (a==0)
        spi_xfer(cu,0x0090,16) ; // Para transmitir, se elige 868 Mhz, se usa R1,P1,S1
   else
       spi_xfer(cu,0x0070,16) ; // Para recepcion, se elige 868 Mhz, se usa R1,P1,S1
       
   spi_xfer(cu,0x028C,16) ; //  Se va a usar modo paquete y una trasmisión FSK
// Bit rate se dejó por default a 25 kbs
   spi_xfer(cu,0x0C43,16); // El valor de R1 =67
   spi_xfer(cu,0x0E35,16) ;// El valor de P1=53
   spi_xfer(cu,0x1031,16) ;// El valor de S1 = 49
// Registros de configuración de recepción
   spi_xfer(cu,0x2438,16) ;// Habilito bit de sincronización, tamaño de la palabra de sincronización=32 bis
// Se usa una potencia de transferencia igual a la default e igual a 10dbm
// Registros del control de paquete
   spi_xfer(cu,0x3808,16);   
   spi_xfer(cu,0x028C,16) ; //  Se va a usar modo paquete y una trasmisión FSK
}

void main()
{   
   
   configuracion(0);  // 0 TX; 1 RX

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_1MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
   
   set_tris_b(0b00000000); // PIN_B4 = LED
   output_low(PIN_B4);
   set_tris_c(0b00010110) ; // CSDATA,CCCON,SDO,SDI,SCK,IRQ1,IRQ0,RESET
     
   output_high(PIN_B4);
   for(;;){
   
// MAIN  TX
   
   output_low(DATOS);   //  DATOS
   output_high(CONFIG);   // NO CONFIGURACION
   
   spi_xfer(cu,0xA5,8);
   
   // to read from the rf communication we use:
  // ref=spi_xfer(cu,0x00,8)
   
   output_high(DATOS);
      
 } 
}
 
temtronic



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

View user's profile Send private message

PostPosted: Fri Nov 15, 2013 8:12 am     Reply with quote

first thing I'd do is put 'MRF89XA' into the 'search' feature of this forum !

you'll get 4 or 5 hits...odds are good one of them should get you 'up and running'!

if not, google 'MRF89XA CCS C code' or similar and see what pops up.

hth
jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Nov 15, 2013 9:59 am     Reply with quote

have you tested using something like
what is in

AN1340

??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 16, 2013 1:35 am     Reply with quote

Quote:
#use spi(DI=PIN_C4, DO=PIN_C5, CLK=PIN_C3,MODE=0,BAUD=25000,STREAM=cu)

You didn't specify the number of bits to send, so #use spi() will default to
sending 32 bits. Also, you didn't specify FORCE_HW, so it will default to
software SPI.


Quote:
setup_spi(SPI_SS_DISABLED);

If you have a #use spi() statement, you should not have a setup_spi()
statement. #use spi is a newer method of setting the SPI. It can
be configured for hardware SPI (on the hardware pins) or for software
SPI on any suitable i/o pins. The setup_spi() function can only configure
the hardware SPI. Don't use both functions in the same program.

Quote:
main.h

You should post this file so we can see your #fuses, etc.


Quote:
setup_oscillator(OSC_1MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

Do you really want to run the PIC at 1 MHz ? This means the instruction
clock is only 250 KHz. That's very slow.

Also, post your CCS compiler version.
Excatter



Joined: 15 Nov 2013
Posts: 2
Location: Argentina

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 25, 2013 12:26 pm     Reply with quote

Thank you all for your answers. We manage to communicate both transceivers but now we have another problem. We manage to send one message but when we want to send more than one , the IRQ1, the interrupt that tells the pic that the payload is ready, never goes down. So, we cant receive more than one message. We have looked up for a solution in this forum but we couldnt find it. Can anyone help us? Please ask for anything you need in order to help us.
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