View previous topic :: View next topic |
Author |
Message |
waranet
Joined: 05 Jan 2006 Posts: 10 Location: France
|
Transceiver MRF89X |
Posted: Mon Jan 31, 2011 10:32 am |
|
|
Hi,
Has anybody did some test with the transceiver from Microchip MRF89x, I'm looking for a C code to check performances and maybe use it in my next RF projects.
Your help will be welcome.
regards
JP |
|
|
Itronica
Joined: 16 Feb 2012 Posts: 2
|
|
Posted: Thu Feb 16, 2012 8:15 am |
|
|
Good morning, found some examples? I'm also looking for a base with CCS but I have not yet found. thanks |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Feb 16, 2012 12:10 pm |
|
|
Microchip has their Application Software library with some examples I believe.
You should look there. Won't compile under CCS (yet) but will at least give you an idea of what to do. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Thu Oct 25, 2012 9:30 am |
|
|
Hi,
Has anybody worked on that in CCS environment?
Where can I find some example code to show me how to make it work?
Thanks in advance. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Oct 25, 2012 9:36 am |
|
|
Not for the 89... but I did make a 49 work with CCS...
It's a different chip in some important ways though.
Did you download the example drivers from Microchip yet?
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Thu Oct 25, 2012 10:29 am |
|
|
Ok it's better for me
I just bought the MRF49XA evaluation daughter board.
I download the AN1252.zip from microchip. |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Tue Oct 30, 2012 8:04 am |
|
|
hi all
I have trouble to translante into CCS this part of code from Microchip C18 v3.04 source code for MRF49XA
C part
Code: | #if defined(__18CXX)
#pragma interrupt HighISR
void HighISR(void)
#elif defined(__dsPIC30F__) || defined(__dsPIC33F__) || defined(__PIC24F__) || defined(__PIC24H__)
void _ISRFAST __attribute__((interrupt, auto_psv)) _INT2Interrupt(void)
#endif
{
if( RFIE && RFIF )
{
nCS = 0;
if( SPI_SDI == 1 )
{
BYTE RxPacketPtr;
BYTE tmpPacketLen;
WORD counter;
// There is data in RX FIFO
nCS = 1;
nFSEL = 0; // FIFO selected
tmpPacketLen = SPIRead();
if( tmpPacketLen >= PAYLOAD_LEN || tmpPacketLen == 0 || hasPacket )
{
IGNORE_HERE:
nFSEL = 1; // bad packet len received
RegisterSet(PMCREG); // turn off the transmitter and receiver
RegisterSet(FIFORSTREG); // reset FIFO
RegisterSet(GENCREG); // disable FIFO, TX_latch
RegisterSet(GENCREG | 0x0040); // enable FIFO
RegisterSet(PMCREG | 0x0080); // turn on receiver
RegisterSet(FIFORSTREG | 0x0002); // FIFO synchron latch re-enabled
goto RETURN_HERE;
}
RxPacketLen = tmpPacketLen;
RLED = 1;
nFSEL = 1;
RxPacketPtr = 0;
counter = 0;
while(1)
{
if( counter++ == 0xFFFF )
{
goto IGNORE_HERE;
}
else if( FINT == 1)
{
nFSEL = 0;
counter = 0;
RxPacket[RxPacketPtr++] = SPIRead();
if( RxPacketPtr >= RxPacketLen )
{
WORD received_crc;
WORD calculated_crc;
BYTE i;
nFSEL = 1;
RegisterSet(FIFORSTREG);
RLED = 0;
RxPacketLen -= 2; // do not count CRC
received_crc = ((WORD)RxPacket[RxPacketLen+1]) + (((WORD)RxPacket[RxPacketLen]) << 8);
calculated_crc = CRC16((BYTE *)RxPacket, RxPacketLen);
if( received_crc != calculated_crc )
{
RxPacketPtr = 0;
RxPacketLen = 0;
RegisterSet(FIFORSTREG | 0x0002); // FIFO synchron latch re-enable
goto IGNORE_HERE;
}
RegisterSet(FIFORSTREG | 0x0002);
hasPacket = TRUE;
goto RETURN_HERE;
}
nFSEL = 1;
}
}
}
else // read the rest of the interrupts
{
SPIRead();
nCS = 1;
}
RETURN_HERE:
RFIF = 0;
}
} |
H part
Code: |
#define RFIE INTCON3bits.INT3IE
#define RFIF INTCON3bits.INT3IF
|
thanks for your help |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Tue Oct 30, 2012 1:05 pm |
|
|
No SPI read function working
whats wrong
Code: |
/*******************************************************//**
***********************************************************/
#include <18F87J11.h>
//#############################################################################
//#
//# DIRECTIVES AU COMPILATEUR
//#
//#############################################################################
#fuses HS //Osc Externe
#fuses NOWDT // No WDT
//#fuses XINST // Extended Instruction set not support
#use delay(clock=10000000, restart_wdt) // inclure procédure de délais (delay_ms() et delay_us())
#use rs232( baud=19200, parity=n, xmit=PIN_C6, rcv=PIN_C7, bits=8 )
//#use RS232(BAUD=2400, UART1) // interface série
/**************************************************************************//**
* Accès direct à certains registres
*****************************************************************************/
/**************************************************************************//**
* Position des pins.
*****************************************************************************/
//-----------------------------------------------------------------------------
// PORT A
//-----------------------------------------------------------------------------
//#define PIN_ PIN_A0 //
//#define PIN_ PIN_A1 //
//#define PIN_ PIN_A2 //
//#define PIN_ PIN_A3 //
//#define PIN_ PIN_A4 //
#define PIN_BUTTON2 PIN_A5 // PIN_A5 button 2, active low input
//#define PIN_ PIN_A6 //
//#define PIN_ PIN_A7 //
//-----------------------------------------------------------------------------
// PORT B
//-----------------------------------------------------------------------------
#define PIN_BUTTON1 PIN_B0 // PIN_B0 button 1, active low input
//#define PIN_ PIN_B1 //
//#define PIN_ PIN_B2 //
#define PIN_nIRQ PIN_B3 // PIN_B3 MRF49XA interrupt
#define PIN_FINT PIN_B4 // PIN_B4
#define PIN_nRES PIN_B5 // PIN_B5 MRF49XA reset
//#define PIN_ PIN_B6 //
//#define PIN_ PIN_B7 //
//-----------------------------------------------------------------------------
// PORT C
//-----------------------------------------------------------------------------
#define PIN_SPI_SDO PIN_C0 // PIN_C5 SDO
//#define PIN_ PIN_C1 //
#define PIN_nCS PIN_C2 // PIN_C2 chip select
#define PIN_SPI_SCK PIN_C3 // PIN_C3 SPI clock
#define PIN_SPI_SDI PIN_C4 // PIN_C4 SDI
//#define PIN_ PIN_C5 //
//#define PIN_ PIN_C6 //
//#define PIN_ PIN_C7 //
//-----------------------------------------------------------------------------
// PORT D
//-----------------------------------------------------------------------------
#define PIN_TLED PIN_D0 // #define TLED LATDbits.LATD0 // PIN_D0
#define PIN_RLED PIN_D1 // #define RLED LATDbits.LATD1 // PIN_D1
//#define PIN_ PIN_D2 //
//#define PIN_ PIN_D3 //
//#define PIN_ PIN_D4 //
//#define PIN_ PIN_D5 //
//#define PIN_ PIN_D6 //
//#define PIN_ PIN_D7 //
//-----------------------------------------------------------------------------
// PORT E
//-----------------------------------------------------------------------------
//#define PIN_ PIN_E0 //
//#define PIN_ PIN_E1 //
//#define PIN_ PIN_E2 //
#define PIN_nFSEL PIN_E3 //PIN_E3 fifo select, active low output
//#define PIN_ PIN_E4 //
//#define PIN_ PIN_E5 //
//#define PIN_ PIN_E6 //
//#define PIN_ PIN_E7 //
//--------------------------------------------------------------------
// MRF49XA selction de la BAND et configuration
//--------------------------------------------------------------------
//#define BAND_915
//#define BAND_868
#define BAND_434
#define XTAL_LD_CAP 0x0003 // crystal load 10pF
#if defined(BAND_434)
#define FREQ_Band 0x0010 //434MHz
#define CFSREG 0xA640 // Center Frequency: 434MHz
#elif defined(BAND_868)
#define FREQ_Band 0x0020 //868MHz
#define CFSREG 0xA640 // Center Frequency: 868MHz
#elif defined(BAND_915)
#define FREQ_Band 0x0030 //915MHz
#define CFSREG 0xA7D0 // Center Frequency: 915.000MHz
#endif
#define GENCREG (0x8000 | XTAL_LD_CAP |FREQ_Band)
#define AFCCREG 0xC4F7
#define TXCREG 0x9850 // Deviation: 75kHz
#define TXBREG 0xB800
#define RXCREG 0x9481 // BW 200KHz, LNA gain 0dB, RSSI -97dBm
#define FIFORSTREG 0xCA81
#define DRVSREG 0xC623 // Data Rate:9579Baud
#define PMCREG 0x8201
#define NODATA 0
#define DATA_RECEIVED 1
#define PACKET_RECEIVED 2
#define PAYLOAD_MAX 4
#define RX_PACKET_SIZE 10
#define PAYLOAD_LEN 40 // the maximum payload size
#define PACKET_LEN PAYLOAD_LEN + 2
//#############################################################################
//#
//# DÉCLARATION DES VARIABLES (globales)
//#
//#############################################################################
int16 tableau[34];
/*********************************************************************
* BYTE SPIRead(void)
*
* Overview:
* This function read one byte from the SPI interface.
* This function use bit-bang to access the SPI port, so
* any digital I/O pins can access MRF49XA transceiver
* SPI interface
*
* PreCondition:
* MRF49XA transceiver has been configured properly
*
* Input: None
*
* Output:
* BYTE One byte of data received from the SPI interface
*
* Side Effects: None
*
********************************************************************/
SPIRead(void)
{
int8 i;
int16 data;
data=0;
output_low(PIN_SPI_SDO);
output_low(PIN_SPI_SCK);
for(i = 0; i < 8; i++)
{
data = (data << 1) | input(PIN_SPI_SDI);
output_high(PIN_SPI_SCK);
output_low(PIN_SPI_SCK);
}
return data;
}
/********************************************************************
* void RegisterSet(WORD setting)
*
* Overview:
* This function access the control register of MRF49XA.
* The register address and the register settings are
* the input
*
* PreCondition:
* None
*
* Input:
* WORD setting The address of the register and its
* corresponding settings
*
* Output: None
*
* Side Effects: Register settings have been modified
*
********************************************************************/
void RegisterSet(int16 setting){
output_low(PIN_nCS);
SPI_Write(setting >> 8);
SPI_Write(setting);
output_high(PIN_nCS);
}
/*********************************************************************
* void BoardInit( void )
*
* Overview: This function configures the board. This routine
* needs to be called before the function to
* initialize demo board
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: Board is initialized for demo
*
********************************************************************/
void BoardInit(void)
{
// enable RF INT
// INTCON2bits.INTEDG3 = 0;
// RFIF = 0;
// RFIE = 1;
output_high(PIN_nRES); // no reset
output_high(PIN_nCS); // nCS inactive
output_high(PIN_nFSEL); // nFSEL inactive
// blink LEDs on start up
output_high(PIN_TLED);
delay_ms(50);
output_high(PIN_RLED);;
delay_ms(50);
output_low(PIN_TLED);
delay_ms(50);
output_low(PIN_RLED);;
delay_ms(50);
output_high(PIN_TLED);
}
/*********************************************************************
* void MRF49XAInit(void)
*
* Overview:
* This functions initialize the MRF49XA transceiver
*
* PreCondition: None
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
********************************************************************/
void MRF49XAInit(void)
{
// configuring the MRF49XA radio
// RFIE = 0;
RegisterSet(FIFORSTREG);
RegisterSet(FIFORSTREG | 0x0002); // enable synchron latch
RegisterSet(GENCREG);
RegisterSet(AFCCREG);
RegisterSet(CFSREG);
RegisterSet(DRVSREG);
RegisterSet(PMCREG);
RegisterSet(RXCREG);
RegisterSet(TXCREG);
// antenna tuning on startup
RegisterSet(PMCREG | 0x0020); // turn on the transmitter
delay_ms(5); // wait for oscillator to stablize
// end of antenna tuning
RegisterSet(PMCREG | 0x0080); // turn off transmitter, turn on receiver
RegisterSet(GENCREG | 0x0040); // enable the FIFO
RegisterSet(FIFORSTREG);
RegisterSet(FIFORSTREG | 0x0002); // enable synchron latch
RegisterSet(0x0000); // read status byte (read ITs)
// RFIE = 1;
}
/**************************************************************************//**
* Fonction principale
*****************************************************************************/
void main() {
//-------------------------------------------------------------------------
// Configuration des registres
//-------------------------------------------------------------------------
// Setup SPI
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);
enable_interrupts(GLOBAL);
//-------------------------------------------------------------------------
// Initialiser les variables
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Boucle principale
//-------------------------------------------------------------------------
int8 My8bitVar;
int8 i;
BYTE phrase_order = 0;
BYTE line_order = 0;
BYTE SleepMode = 2;
BoardInit();
// ConsoleInit();
MRF49XAInit();
Printf("\r\n*****************************************************");
Printf("\r\n MRF49XA Demo Program");
Printf("\r\n*****************************************************");
#if defined(BAND_915)
Printf("\r\n Frequency Band: 915MHz");
#elif defined(BAND_868)
Printf("\r\n Frequency Band: 868MHz");
#elif defined(BAND_434)
Printf("\r\n Frequency Band: 434MHz");
#endif
Printf("\r\n Data Rate: 9600bps");
Printf("\r\nDemo Instruction: 1. Power On the Other Device");
Printf("\r\n 2. Press Button 1 (RB0) to cycle");
Printf("\r\n power states of transceiver");
Printf("\r\n 3. Press Button 2 (RA5) on other");
Printf("\r\n device continuously to receive");
Printf("\r\n transmitted data");
Printf("\r\n\r\n");
while(1) {
if( input(PIN_BUTTON1) == 0 )
{
while(input(PIN_BUTTON1) == 0);
switch(SleepMode)
{
case 0:
RegisterSet(PMCREG | 0x0008); // switch on oscillator
Printf("\r\nMRF49XA wakes up to idle mode");
SleepMode++;
break;
case 1:
RegisterSet(PMCREG | 0x0080);
RegisterSet(GENCREG | 0x0040 );
RegisterSet(FIFORSTREG | 0x0002);
Printf("\r\nMRF49XA set to receive mode\r\n");
SleepMode++;
break;
case 2:
RegisterSet(FIFORSTREG); // turn off FIFO
RegisterSet(GENCREG); // disable FIFO, TX_latch
RegisterSet(PMCREG); // turn off both receiver and transmitter
output_high(PIN_nFSEL); // nFSEL = 1;
output_low(PIN_nCS); // nCS = 0;
spi_write(0); //SPIWrite(0);
output_high(PIN_nCS); //nCS = 1; // reset all non latched interrupts
Printf("\r\nMRF49XA goes to sleep now");
SleepMode = 0;
break;
default:
break;
}
}
// if received any packet, display it
if( input(PIN_BUTTON2) == 0 )
{
while(input(PIN_BUTTON2) == 0);
int8 index;
int8 i;
for(index=0; index<33; index++) {
output_low(PIN_nFSEL);
output_low(PIN_nCS); // nCS = 0;
tableau[index] = spi_read();
// My8bitVar=0xB2;
output_high(PIN_nCS); //nCS = 1;
output_high(PIN_nFSEL);
for(i = 0; i < sizeof(tableau); i++)
putc(tableau[i]);
// putc(My8bitVar);
}
}
}
}
|
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Oct 30, 2012 1:18 pm |
|
|
you need to understand that Microchip's libraries are written to use Microchip's compilers (like C18, C30 and C32).
SPI_Write is not a built in CCS function but a function in Microchip's compilers (or possibly hand written in code elsewhere in the project).
You will need to learn to identify and alter incompatible code from Microchip's library to make it work with CCS.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Tue Oct 30, 2012 1:44 pm |
|
|
SPI_Write is a built in CCS function.
I don't understand your comment. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Oct 30, 2012 2:54 pm |
|
|
in_nursery wrote: | SPI_Write is a built in CCS function.
I don't understand your comment. |
sorry, I'm so used to spi_xfer...
check spi_read() to make sure in the assy it waits for the buffer to empty before continuing to where you release nCS.
If it does not - you'll need to put in an operation to do that otherwise you raise the nCS flag while in the middle of receiving the desired byte.
Do you have an oscilloscope? those are always super helpful here.
Additionally, if you're going to use hardware SPI (setup_spi only works on hardware MSSP's), make sure the pins you're using for SCK, SDI and SDO are hardware allocated pins. (I didn't check the datasheet for your PIC)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Fri Nov 02, 2012 6:03 am |
|
|
Hi
I stop trying to translate from C18 to ccs.
I rewrote everything and this time it's work fine, very nice chip...
thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Nov 02, 2012 9:18 am |
|
|
Hi,
You code will probably help someone just like you, so you should consider
posting it in the code library!
Cheers,
John |
|
|
|