MSP430 RFM12

Discussions on how to get your MSP JTAG programmer up and running.

Moderator: phalanx

grabbo
Posts: 9
Joined: Sun Oct 19, 2008 5:38 am

Re: MSP430 RFM12

Post by grabbo » Wed Apr 18, 2012 9:56 am

Somebody asked me to post a code. I include it here. It was a long time ago, I found this test code, it worked as i said earlier, with sequential method which is not mentioned in the documentation for the rfm12b but I had another chip which used it and it had almost the same registers therefore I wanted to try that method.

Code: Select all

//*******************************//
//          PORT init
//*******************************//
void PORT_init()
{
  P3DIR |= BIT1;                                 // Output SDI
  P3SEL |= BIT1 + BIT2;                          // P5.1,2,3 SPI option select
 
  P3DIR |= BIT3;  //CLK output
  P3SEL |= BIT3;  //CLK sEL
  
  P3DIR &= ~BIT2;                                       // SDO input

  P3DIR |= BIT0;                                       	// nSEL/nCS
  P3OUT |= BIT0;	                               	// nSEL HIGH-disable
 
  P4DIR |= BIT0;                                        // DATA
  P4OUT |= BIT0;                                        // DATA high
  
  P4DIR &= ~BIT1;                                       // fINT input                                     
 
  P6DIR |= BIT0;
  P6OUT &= ~BIT0;
}
//*******************************//
//          SPI init
//*******************************//
void SPI_init()
{

  U0CTL |=SWRST;
  U0CTL |= CHAR+SYNC+MM;
  U0TCTL |= CKPH+SSEL1+STC;
  U0BR0=0x04;
  U0BR1=0x0;
  U0MCTL=0x0;
  ME1 |= USPIE0;
  U0CTL &=~SWRST;

  __delay_cycles(100);
}



//*******************************//
//          TIMER
//*******************************//
void Timer() 
{
	CCTL0 = CCIE;                              // CCR0 interrupt enabled
	CCR0 = 32768;                               //32768/50000=0.655=> 1.5s
	TACTL = TASSEL_1 + MC_2;                   // ACLK, contmode

}
//*******************************//
//      TRANSMIT COMMANDS
//*******************************//
void rf12_transmit(uint16_t data)
{
  P3OUT &= ~BIT0;                                     //nSEL low   
  uint8_t byteOfData = 0x00;
  
 while (!(IFG1 & UTXIFG0)){}                       //TX buffer ready?
 byteOfData = (uint8_t)(data>>8);
  U0TXBUF= byteOfData;                           //send upper byte
  while(!(UTCTL0 & TXEPT)) {}                         //

  while (!(IFG1 & UTXIFG0)){}
  byteOfData = (uint8_t)(data);
  U0TXBUF=byteOfData;                              //send lower byte
  while(!(UTCTL0 & TXEPT)) {}

  P3OUT |= BIT0;                                      //nSEL high
}

//*******************************//
//        TRANSMIT DATA
//*******************************//
void transmit(int datawireless)
{

  while (!(IFG1 & UTXIFG0)){}
  U0TXBUF=datawireless;
  while(!(U0TCTL & TXEPT)) {
  }

  while(!(P3IN&BIT2)) {}                           // SDO high?

}

//*******************************//
//            SET TX
//*******************************//
void rfm12b_setTX()
{

rf12_transmit(0x80E8); 
rf12_transmit(0xC483);
rf12_transmit(0x9824);
rf12_transmit(0xA640);
rf12_transmit(0xCA83);
rf12_transmit(0xCEC2);
rf12_transmit(0xC626); 
rf12_transmit(0x8219);
rf12_transmit(0xCC16);
}

//*******************************//
//          RESET FIFO
//*******************************//
void FIFO_reset(void)
{
rf12_transmit(0xCA81);
rf12_transmit(0xCA83);
}

//*******************************//
// Sequential byte write method
//*******************************//
void TX()
{

  int i,b;
rf12_transmit(0x0000);
rf12_transmit(0x8239);    //enable transmitter



P4OUT |= BIT0;            //DATA HIGH
P3OUT &= ~BIT0;           //nSEL LOW
  __delay_cycles (100); 

transmit(0xB8);
transmit(0xAA);
transmit(0xAA);
transmit(0x2D);
transmit(0xC2);

  for (i=0x41;i<0x5A;i++)
  {
  transmit(i);
  }
transmit(0xAA);
transmit(0xAA);

P3OUT |= BIT0;            //nSEL high
P4OUT &= ~BIT0;           //DATA low

rf12_transmit(0x8219);    //disable transmitter

}


//*******************************//
//            MAIN
//*******************************//
void main( void )
{
  int i;
  int y;
  
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  BCSCTL1 &= ~XT2OFF;                       // XT2= HF XTAL
  
  do
  {
  IFG1 &= ~OFIFG;                           // Clear OSCFault flag
  for (i = 0xFF; i > 0; i--);               // Time for flag to set
  }
  while ((IFG1 & OFIFG));                   // OSCFault flag still set?

  BCSCTL2 |= SELM_2+SELS;                        // MCLK+SMCLK= XT2 (safe)

  PORT_init();
  SPI_init();
  Timer();
  __delay_cycles (1000); //POR done
  rfm12b_setTX();
  rf12_transmit(0x0000); 
  _BIS_SR(LPM0_bits + GIE);
  while(1){}
    
}
// Timer_A TACCR0 interrupt vector handler
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA_procedure(void){

  rf12_transmit(0x8219);                        // enable oscillator, synthesizer
  __delay_cycles (9000);                        //wait 1.2ms
  TX();
  rf12_transmit(0x8211);                        //Disale osc & synthesizer
  P6OUT ^= BIT0;	//LED toogle
  CCR0 += 3276;                                // Add offset to CCR0
}

kibicrealu1
Posts: 1
Joined: Wed Jan 02, 2013 11:54 am

Re: MSP430 RFM12

Post by kibicrealu1 » Wed Jan 02, 2013 12:03 pm

Hi there,
could anybody provide valid code for receiver based on MSP430 and RFM12B? My transmitter works fine, but i struggle with receiver :(

WethaGuy
Posts: 73
Joined: Sat Mar 10, 2012 8:00 pm

Re: MSP430 RFM12

Post by WethaGuy » Thu Jan 03, 2013 6:01 pm

I can't help you directly but, you may have better luck at 43oh.com forums

marcovansteen
Posts: 104
Joined: Fri Jun 29, 2007 4:37 am
Location: Eindhoven, Netherlands

Re: MSP430 RFM12

Post by marcovansteen » Fri Jan 04, 2013 8:08 am

i notice this is an old thread, but still: @stevech: can't this be improved with lowleakage x5r cap across the battery?
Fast turnon/turnoff is essential to get into the 98% ballpark... NRF24L01 is much faster: 1.5ms startup time vs 5ms.

maru281
Posts: 1
Joined: Sun Jan 20, 2013 10:54 am

Re: MSP430 RFM12

Post by maru281 » Sun Jan 20, 2013 10:59 am

hello
Can anyone upload his C code for msp430 with rfm12b ?
I'm working with them for few weeks and they are making me crazy. :twisted:
Thanks for help.

stevech
Support Volunteer
Posts: 2907
Joined: Sat Jun 05, 2004 8:51 pm
Location: USA, California

Re: MSP430 RFM12

Post by stevech » Mon Jan 21, 2013 4:54 pm

-15dBm is way too low to be practical at more than 10m or so.

Code: can you start with the C code at JeeLabs?

Post Reply