Exemplo n.º 1
0
/*******************************************************************************
 * @fn     void setup_radio( uint8_t (*callback)(void) )
 * @brief  Initialize radio and register Rx Callback function
 * ****************************************************************************/
void setup_cc2500( uint8_t (*callback)(uint8_t*, uint8_t) )
{
  uint8_t initial_power = 0xFB;				// 0 dBm

  // Set-up rx_callback function
  rx_callback = callback;

  spi_setup();                         // Initialize SPI port

  cc_powerup_reset();               // Reset CCxxxx

  wait_cycles(500);  // Wait for device to reset (Not sure why this is needed)

  writeRFSettings();                        // Write RF settings to config reg
  cc_write_burst_reg( TI_CCxxx0_PATABLE, &initial_power, 1);//Write PATABLE

  cc_strobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
                                            // When a pkt is received, it will
                                            // signal on GDO0 and wake CPU

  // Configure GDO0 port
  GDO0_PxIES |= GDO0_PIN;       // Int on falling edge (end of pkt)
  GDO0_PxIFG &= ~GDO0_PIN;      // Clear flag
  GDO0_PxIE |= GDO0_PIN;        // Enable int on end of packet

}
Exemplo n.º 2
0
uint8_t setup_cc2500(void) {

	uint8_t returnValue=0;
	uint8_t initial_power = 0xFB;				// 0 dBm
	// Set-up rx_callback function

	do
	{
		// Changed
		//spi_init();                         // Initialize SPI port

		// FIXME Add uscib0 files
		cc_powerup_reset();               // Reset CCxxxx

		// TODO implement this
		wait_cycles(500);  // Wait for device to reset (Not sure why this is needed)

		if(writeRFSettings())                        // Write RF settings to config reg
		{
			returnValue = 1; // Failed
			break;
		}

		// FIXME Add uscib0 files
		cc_write_burst_reg( TI_CCxxx0_PATABLE, &initial_power, 1);//Write PATABLE

		// FIXME Add uscib0 files

		cc_strobe(TI_CCxxx0_SIDLE);
		WAIT1_Waitms(10);
		cc_strobe(TI_CCxxx0_SFRX);      // Flush RXFIFO
		WAIT1_Waitms(10);
		cc_strobe(TI_CCxxx0_SFTX);      // Flush RXFIFO
		WAIT1_Waitms(10);




		cc_strobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.



		returnValue = cc_read_status(TI_CCxxx0_MARCSTATE);
		returnValue =0;



		// When a pkt is received, it will
		// signal on GDO0 and wake CPU

		// FIXME
		// Configure GDO0 port
	//	GDO0_PxIES |= GDO0_PIN;       // Int on falling edge (end of pkt)
	//	GDO0_PxIFG &= ~GDO0_PIN;      // Clear flag
	//	GDO0_PxIE |= GDO0_PIN;        // Enable int on end of packet
		CC_2500_SETUP_DONE = true;
	}while(0);

	return returnValue;
}
void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  TI_CC_SPISetup();                         // Initialize SPI port

  TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
  writeRFSettings();                        // Write RF settings to config reg
  TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE

  // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
  TI_CC_SW_PxREN |= TI_CC_SW1+TI_CC_SW2;    // Enable pull-up resistor
  TI_CC_SW_PxOUT |= TI_CC_SW1+TI_CC_SW2;    // Enable pull-up resistor
  TI_CC_SW_PxIES = TI_CC_SW1+TI_CC_SW2;     // Int on falling edge
  TI_CC_SW_PxIFG &= ~(TI_CC_SW1+TI_CC_SW2); // Clr flags
  TI_CC_SW_PxIE = TI_CC_SW1+TI_CC_SW2;      // Activate interrupt enables
  TI_CC_LED_PxOUT &= ~(TI_CC_LED1 + TI_CC_LED2); // Outputs = 0
  TI_CC_LED_PxDIR |= TI_CC_LED1 + TI_CC_LED2;// LED Direction to Outputs

  TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
  TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // Clear flag
  TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // Enable int on end of packet

  TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
                                            // When a pkt is received, it will
                                            // signal on GDO0 and wake CPU

  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, enable interrupts
}
Exemplo n.º 4
0
int main(int argc, char ** argv) {
	int res;
	printf("Start rpiCC2500\n");

	TICC *cc = (TICC *) malloc(sizeof(TICC));

	res = CC_Init(cc, "/dev/spidev0.0", 25 /*GNO0-pin Not yet used*/);
	if (res < 0) {
		printf("Failed to init TICC.");
		return 1;
	}
	perror("SPI init");
	usleep(30000);
	TI_CC_SPIStrobe( cc->fd, TI_CCxxx0_SRES);
	printf("Wait for RF to be Ready\n");
	usleep(40);
	printf("RF ok\n");
		
	writeRFSettings(cc);
	printf("BurstReg\n");
	TI_CC_SPIWriteBurstReg(cc->fd, TI_CCxxx0_PATABLE, paTable, paTableLen);
	printf("Strobe\n");
	//TI_CC_SPIStrobe(cc->fd, TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
										// When a pkt is received, it will
										// signal on GDO0
	char rxBuffer[50];
	printf("entering LOOP\n");
	printf("Part No.: %d\n",TI_CC_SPIReadStatus(cc->fd, TI_CCxxx0_PARTNUM));
	printf("Version No.: %d\n",TI_CC_SPIReadStatus(cc->fd, TI_CCxxx0_VERSION));
	char len = 50;
	int j,i;
	for(j=0;j<10;j++){  // for now send every 500ms a message and check for received packages
		rxBuffer[0] =3;
		rxBuffer[1] =0x01;
		rxBuffer[2] =12;
		rxBuffer[3] =rxBuffer[1]^rxBuffer[2]^0x01;
		printf("Send Package\n");
		RFSendPacket(cc, rxBuffer, 4);
		usleep(500000);
		
		printf("Check for Package\n");
		while(RFReceivePacket(cc, rxBuffer, &len)){
				printf("Got A Package %d\n",len);
				for(i =0; i< len; i++){
						printf("%d ",rxBuffer[i]);
				}
				printf("\n");
				//Receiveddata are stored in rxBuffer
				//Put some intelligence here
				len = 50;
		}
		
	}

	printf("exiting LOOP\n");
	CC_dispose(cc);
	free(cc);

	return 0;
}
Exemplo n.º 5
0
void RF_init()
{
  
  TI_CC_SPISetup();                         // Initialize SPI port
  TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
  writeRFSettings();                        // Write RF settings to config reg
  
  TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
  //TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); // set IDLE
  TI_CC_SPIWriteReg (TI_CCxxx0_PATABLE,paTable[0]); // init at max powerlevel

  // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
  
  TI_CC_SW_PxREN |= TI_CC_SW1;               // Enable Pull up resistor
  TI_CC_SW_PxOUT |= TI_CC_SW1;               // Enable pull up resistor
  TI_CC_SW_PxIES |= TI_CC_SW1;               // Int on falling edge
  TI_CC_SW_PxIFG &= ~(TI_CC_SW1);            // Clr flags
  TI_CC_SW_PxIE |= TI_CC_SW1;                // Activate interrupt enables
  
  TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
  TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // Clear flag
  TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // Enable int on end of packet

  TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
                                            // When a pkt is received, it will
                                            // signal on GDO0 and wake CPU

}
Exemplo n.º 6
0
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    //P2REN |= BIT3; // enable pull up resistor on p2.3
    //P2OUT |= BIT3; // This does not seem to be working as expected.

    // Initialize radio and SPI
    TI_CC_SPISetup();                         // Initialize SPI port
	TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
	writeRFSettings();                        // Write RF settings to config reg
	TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
	// Enable interrupts from radio module
	TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
	TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // Clear flag
	TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // Enable int on end of packet
	// Enable radio
	TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.

    // configure packet
    // --------------------------------------------
	txBuffer[0] = MSGLEN-1;                        // Packet length
	txBuffer[1] = 0x01;                     // Packet address - If this is 0xFF, it's an ack and not data.
	// Begin data
	// --------------------------------------------
	txBuffer[2] = VALID_LEVEL; // default flag is valid. This is set on request from other module.
	txBuffer[3] = 0x30;
	txBuffer[4] = 0x31;
	txBuffer[5] = 0x34;
	txBuffer[6] = 0x35;
	txBuffer[7] = 0x36;
	txBuffer[8] = 0x37;
	txBuffer[9] = 0x38;
	txBuffer[10] = 0x39;		// the rest of this data is used as filler.
	// ------
	// End Data
	txBuffer[11] = 0x00;					// terimate
	// --------------------------------------------

	_BIS_SR(GIE); // turn on interrupts. Initialization must be complete by this point
    while(1) {
    	if(water_level_request) {
    		// Ideally, P2.3 should be pulled high. This is causing strange behavior
    		// 		on the pin that should be investigated.
    		// Check the status of P2.3 and set the r
    		txBuffer[WATER_DATA_TX_INDEX] = (P2IN & BIT3) ? 0 : VALID_LEVEL;// turn on the pump if the water level is valid.
    		RFSendPacket(txBuffer, MSGLEN);		// Send water level data back to controller
    		__delay_cycles(450000); 			// delay a few cycles. Note that this means requests that take place during
    											// a pump cycle will be ignored completely.
    		water_level_request = 0; // clear requested data flag
      	}
    }
}
Exemplo n.º 7
0
void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  // 5ms delay to compensate for time to startup between MSP430 and CC1100/2500
  __delay_cycles(5000);
  
  TI_CC_SPISetup();                         // Initialize SPI port

  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;

  P2SEL = 0;                                // Sets P2.6 & P2.7 as GPIO
  TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
  writeRFSettings();                        // Write RF settings to config reg
  TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE

  // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
  COM_Init();
  TI_CC_SW_PxREN = TI_CC_SW1;               // Enable Pull up resistor
  TI_CC_SW_PxOUT = TI_CC_SW1;               // Enable pull up resistor
  TI_CC_SW_PxIES = TI_CC_SW1;               // Int on falling edge
  TI_CC_SW_PxIFG &= ~(TI_CC_SW1);           // Clr flags
  TI_CC_SW_PxIE = TI_CC_SW1;                // Activate interrupt enables
  TI_CC_LED_PxOUT &= ~(TI_CC_LED1 + TI_CC_LED2); // Outputs = 0
  TI_CC_LED_PxDIR |= TI_CC_LED1 + TI_CC_LED2;// LED Direction to Outputs

  TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
  TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN;      // Clear flag
  TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN;        // Enable int on end of packet

  TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.
                                            // When a pkt is received, it will
                                            // signal on GDO0 and wake CPU
  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM3, enable interrupts
}
Exemplo n.º 8
0
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    P2DIR |= BIT3 | BIT4; 		// output to BLDC and LED
    P2OUT &= ~BIT3; 			// make sure pump is off
    P2OUT &= ~BIT4; 			//make sure LED is off

    // Port 1 pushbutton config
    P1REN |= TI_CC_SW1; 		// enable pullup/down on switch1
    P1OUT |= TI_CC_SW1; 		// configure PUR as pull down (active low)
    P1IES |= TI_CC_SW1; 		// interrupt on falling edge
    P1IFG = 0; // clear all interurpt flags
    P1IE = TI_CC_SW1; // enable interrupts on pushbutton

    // Initialize radio and SPI - This code is derived from TI radio drivers
    TI_CC_SPISetup();                         // Initialize SPI port
	TI_CC_PowerupResetCCxxxx();               // Reset CCxxxx
	writeRFSettings();                        // Write RF settings to config reg
	TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
	// Enable interrupts from radio module
	P2IES |= TI_CC_GDO0_PIN;       // Int on falling edge (end of pkt)
	P2IFG &= ~TI_CC_GDO0_PIN;      // Clear flag
	P2IE |= TI_CC_GDO0_PIN;        // Enable int on end of packet
	// Enable radio
	TI_CC_SPIStrobe(TI_CCxxx0_SRX);           // Initialize CCxxxx in RX mode.

    // configure packet
    // --------------------------------------------
	txBuffer[0] = MSGLEN-1;                        // Packet length -- this will get trimmed off.
	txBuffer[1] = 0x01;                     // Packet address - If this is 0xFF, it's an ack and not data.
	// Begin data
	// --------------------------------------------
	txBuffer[2] = OPERATE_SENSOR; 	// flag for other node to know that it needs to read switch state.
	txBuffer[3] = 0x30; 			// Filler data to be used later on
	txBuffer[4] = 0x31;
	txBuffer[5] = 0x34;
	txBuffer[6] = 0x35;
	txBuffer[7] = 0x36;
	txBuffer[8] = 0x37;
	txBuffer[9] = 0x38;
	txBuffer[10] = 0x39;		// the rest of this data isn't used in ths project
	// Extra data could be used in the event that more controller nodes are added
	// ------
	// End Data
	txBuffer[11] = 0x00;					// terimate
	// --------------------------------------------

	_BIS_SR(GIE); // turn on interrupts. Initialization is now complete.
    while(1) {
    	if(buttonPressed) { 		// buttonPressed is a user interrupt flag
    		P1IE &= ~TI_CC_SW1; 	// disable user interrupts to avoid conflicting pump cycles
    		if (WaterLevelValid()) { // WaterLevelValid() will retrieve water level status from the other node
    			P2OUT |= BIT3; // turn on pump
    			__delay_cycles(1000000); // delay for a second while pump runs
    			P2OUT &= ~BIT3; // turn off pump
    			P2OUT &= ~BIT4; // turn off LED
    		}
    		buttonPressed = 0; 	// clear flag
    		P1IE = TI_CC_SW1; 	// Enable user interrupts (accept a new pump cycle)
    	}
    }
}