SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By grabbo
#143128
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
}
By kibicrealu1
#153778
Hi there,
could anybody provide valid code for receiver based on MSP430 and RFM12B? My transmitter works fine, but i struggle with receiver :(
By marcovansteen
#153850
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.
By maru281
#154401
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.
By stevech
#154445
-15dBm is way too low to be practical at more than 10m or so.

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