Advertisement
utroz

MSPBoard CC2500

Sep 27th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.03 KB | None | 0 0
  1. /* ------------------------------------------------------------------------------------------------
  2.  *  MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
  3.  *  Copyright ©2011 - Version 0.02
  4.  *  File: functions.h
  5.  *  Blog: http://OAKcoders.com/ (Access it)!
  6.  *  (Functions by #Utroz# & #Kaddoush#)
  7.  * ------------------------------------------------------------------------------------------------
  8.  */
  9.  
  10. /* Low Power Mode */
  11. #ifdef __LOW_MODE_ON
  12.   #define   __ENERGY_HUNGRY LPM_3   /* Set a low power mode on BIT_SR_register - Options: (LPM_0(G.I) to LPM_4)*/
  13. #endif
  14.  
  15. #include "mrfi.h"
  16.  
  17. void __start_clock_signal(uint32_t arg);
  18. void __push_button_modules(void);
  19. void __board_mode(void);
  20.  
  21. /* This is responsible to check Current LED Color */
  22. typedef int8_t __LED_status;
  23.  
  24. /* Led Default Value */
  25. #define LED_RED BIT0
  26. #define LED_GREEN BIT1
  27.  
  28. /* Define a LED out status */
  29. #define LED_OUT P1OUT
  30.  
  31. /* This function turn LED off */
  32. #define TURN_LED_OFF()      LED_OUT &= 0x00;
  33. #define LED_COLOR_CHECK()   if(i == LED_RED) i++; else i--;
  34.  
  35. /* ---------------------------
  36.  * The line below switches a board status, if argument is a 1, it enter on first mode,
  37.  * that is, enables the (G.I) and (LPM 3) turn on; else if result is other, then it entered only in (G.I). */
  38. #define LPM_0   0x00 // Only Global Interruption
  39. #define LPM_1   0x01 // Low Power Mode 1
  40. #define LPM_2   0x02 // Low Power Mode 2
  41. #define LPM_3   0x03 // Low Power Mode 3
  42. #define LPM_4   0x04 // Low Power Mode 4
  43. //-----------------------
  44.  
  45. /* ------------------------------------------------------------------------------------------------
  46.  *  MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
  47.  *  Copyright ©2011 - Version 0.02
  48.  *  File: functions.c
  49.  *  Blog: http://OAKcoders.com/ (Access it)!
  50.  *  (Functions by #Utroz# & #Kaddoush#)
  51.  * ------------------------------------------------------------------------------------------------
  52.  */
  53.  
  54. #include "functions.h"
  55.  
  56. void __start_clock_signal(uint32_t arg)
  57. {
  58.     /* Clock Signal */
  59.     BCSCTL3 |= LFXT1S_2;
  60.     TACCTL0 = CCIE; /* Enable a timer interruption */
  61.     TACCR0 = arg; // Delay.
  62.     TACTL = MC_1+TASSEL_1;
  63. }
  64.  
  65. void __push_button_modules(void)
  66. {
  67.     /* Enable the internal resistor of
  68.      * the button */
  69.     P1REN |= 0x04;
  70.    
  71.     /* Enable interruption on P1.2 */
  72.     P1IE |= 0x04;
  73. }
  74.  
  75. /* Set a value to low power mode */
  76. void __board_mode(void)
  77. {
  78.      #if (__ENERGY_HUNGRY == LPM_0)  
  79.        __bis_SR_register(GIE);
  80.      #elif (__ENERGY_HUNGRY == LPM_1)
  81.         __bis_SR_register(GIE+LPM1_bits);      
  82.      #elif (__ENERGY_HUNGRY == LPM_2)
  83.         __bis_SR_register(GIE+LPM2_bits);
  84.      #elif (__ENERGY_HUNGRY == LPM_3)
  85.         __bis_SR_register(GIE+LPM3_bits);  
  86.      #elif (__ENERGY_HUNGRY == LPM_3)
  87.         __bis_SR_register(GIE+LPM4_bits);
  88.      #else NULL;
  89.      #endif
  90. }
  91. //-----------------------
  92.  
  93. /* ------------------------------------------------------------------------------------------------
  94.  *  MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
  95.  *  Copyright ©2011 - Version 0.02
  96.  *  File: main.c
  97.  *  Blog: http://OAKcoders.com/ (Access it)!
  98.  *  (CC2500 Transmissor / Receptor by #Utroz# & #Kaddoush#)
  99.  * ------------------------------------------------------------------------------------------------
  100.  */
  101.  
  102. /* Setting Defaults */
  103. #define   __RADIO_ON      /* Enable/Disable a MRFI(RADIO) - Options: (ON/OFF) */
  104. #define   __MRFI_RX       /* Enable Transmissor or Receptor - Op: (TR/RX) */
  105. #define   __LOW_MODE_ON   /* Enable/Disable Low Power Mode - Op: (ON/OFF) */
  106. #define   __BUTTON_ON     /* Enable/Disable a Push Button! - Op: (ON/OFF) */
  107.  
  108. #include "functions.h"
  109.  
  110. /* This variable is responsible to alternative LED */
  111. __LED_status i = 0x01;
  112.  
  113. int main( void )
  114. {
  115.     /* This function disable the watchdog, initialize the MCLK at 8 MHz,
  116.      * set LED ports as outputs and the button port as input */
  117.     BSP_Init();
  118.    
  119.     #ifdef __RADIO_ON    
  120.       /* This function initialize 6 wires between the MSP 430 and the CC2500, powers-up the
  121.        * CC2500 and configures the CC2500 47 registers and turns on interrupts from the CC2500 */
  122.       MRFI_Init();
  123.    
  124.       /* Wakes up the radio, it turns on the 26MHz crystal attach to it without entering
  125.        * RX or TX mode */
  126.       MRFI_WakeUp();  
  127.     #endif
  128.  
  129.     #ifdef __MRFI_RX
  130.       /* Switches the radio to RX mode; from this line on, it can receive packets, in which case
  131.        * the interruption function MRFI_RxCompleteISR is called */
  132.       MRFI_RxOn();    
  133.      
  134.       LED_OUT |= LED_RED;    
  135.       __start_clock_signal(0x9C40); /* Signal Clock modules */
  136.     #else    
  137.       LED_OUT |= LED_GREEN;
  138.     #endif
  139.    
  140.     #ifdef __BUTTON_ON      
  141.       __push_button_modules(); /* Starting a push button modules... */
  142.     #endif
  143.      
  144.     #ifdef __LOW_MODE_ON    
  145.       __board_mode(); /* Enable a global interruption or/and Low Power Mode */
  146.     #endif
  147. }
  148.  
  149. /* Transmissor */
  150. #ifdef __MRFI_TR
  151.   /* Push Button Interrupt */
  152.   #pragma vector =PORT1_VECTOR
  153.   __interrupt void Port_1 (void)
  154.   {
  155.     P1IFG &= ~0x04;    
  156.     mrfiPacket_t packet;
  157.    
  158.     /* The first byte is the length of the payload together with source
  159.      * and destination address */
  160.     packet.frame[0]=8+20;
  161.    
  162.     /* This function is responsible
  163.      * to send packets */
  164.     MRFI_Transmit(&packet , MRFI_TX_TYPE_FORCED);
  165.     P1OUT ^= 0x02;
  166.   }
  167. /* Receptor */
  168. #else
  169.   /* This function is called when a packet is received */
  170.   void MRFI_RxCompleteISR()
  171.   {
  172.     /* This functions is responsible to check delay color */
  173.     LED_COLOR_CHECK();
  174.    
  175.     /* Turns off Led's */
  176.     TURN_LED_OFF();
  177.   }
  178.  
  179.   /* Push Button Interrupt */
  180.   #pragma vector =PORT1_VECTOR
  181.   __interrupt void Port_1 (void)
  182.   {
  183.     P1IFG &= ~0x04;
  184.  
  185.     LED_COLOR_CHECK();
  186.     TURN_LED_OFF();
  187.   }
  188.  
  189. /* Timer Interrupt by Clock Signal */
  190. #pragma vector =TIMERA0_VECTOR
  191. __interrupt void Timer_A (void)
  192. {    
  193.     if(i == LED_RED) LED_OUT ^= LED_RED;
  194.     else LED_OUT ^= LED_GREEN;
  195. }
  196. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement