示例#1
0
void ble_begin()
{
    	spi_old = SPCR;
    	SPI.setBitOrder(LSBFIRST);
    	SPI.setClockDivider(SPI_CLOCK_DIV8);
    	SPI.setDataMode(SPI_MODE0);

	/* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001 */   
	if (NULL != services_pipe_type_mapping)
	{
			aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
	}
	else
	{
			aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
	}
	aci_state.aci_setup_info.number_of_pipes    = NUMBER_OF_PIPES;
	aci_state.aci_setup_info.setup_msgs         = setup_msgs;
	aci_state.aci_setup_info.num_setup_msgs     = NB_SETUP_MESSAGES;

	/*
		Tell the ACI library, the MCU to nRF8001 pin connections.
		The Active pin is optional and can be marked UNUSED
	*/	  	
	aci_state.aci_pins.board_name = REDBEARLAB_SHIELD_V1_1; //See board.h for details
	aci_state.aci_pins.reqn_pin   = reqn_pin;
	aci_state.aci_pins.rdyn_pin   = rdyn_pin;
	aci_state.aci_pins.mosi_pin   = MOSI;
	aci_state.aci_pins.miso_pin   = MISO;
	aci_state.aci_pins.sck_pin    = SCK;
	
#if defined(__SAM3X8E__)
	aci_state.aci_pins.spi_clock_divider     = 84;
#else
	aci_state.aci_pins.spi_clock_divider     = SPI_CLOCK_DIV8;
#endif
	  
	aci_state.aci_pins.reset_pin             = UNUSED;
	aci_state.aci_pins.active_pin            = UNUSED;
	aci_state.aci_pins.optional_chip_sel_pin = UNUSED;
	  
	aci_state.aci_pins.interface_is_interrupt	  = false;
	aci_state.aci_pins.interrupt_number			  = 1;

	//Turn debug printing on for the ACI Commands and Events to be printed on the Serial
	lib_aci_debug_print(true);

	/*
		We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
		and initialize the data structures required to setup the nRF8001
	*/
	lib_aci_init(&aci_state); 
	delay(100);

	SPCR = spi_old;
	SPI.begin();
}
示例#2
0
void aci_setup(void)
{ 
  
	// Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
	if (NULL != services_pipe_type_mapping)
	{
	aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
	}
	else
	{
	aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
	}
	aci_state.aci_setup_info.number_of_pipes    = NUMBER_OF_PIPES;
	aci_state.aci_setup_info.setup_msgs         = setup_msgs;
	aci_state.aci_setup_info.num_setup_msgs     = NB_SETUP_MESSAGES;

	// Tell the ACI library, the MCU to nRF8001 pin connections.
	// The Active pin is optional and can be marked UNUSED
	aci_state.aci_pins.board_name = REDBEARLAB_SHIELD_V1_1; //See board.h for details REDBEARLAB_SHIELD_V1_1 or BOARD_DEFAULT
	aci_state.aci_pins.reqn_pin   = 9; //SS for Nordic board, 9 for REDBEARLAB_SHIELD_V1_1
	aci_state.aci_pins.rdyn_pin   = 8; //3 for Nordic board, 8 for REDBEARLAB_SHIELD_V1_1
	aci_state.aci_pins.mosi_pin   = MOSI;
	aci_state.aci_pins.miso_pin   = MISO;
	aci_state.aci_pins.sck_pin    = SCK;

	aci_state.aci_pins.spi_clock_divider          = SPI_CLOCK_DIV8;

	aci_state.aci_pins.reset_pin             = UNUSED; //4 for Nordic board, UNUSED for REDBEARLAB_SHIELD_V1_1
	aci_state.aci_pins.active_pin            = UNUSED;
	aci_state.aci_pins.optional_chip_sel_pin = UNUSED;

	aci_state.aci_pins.interface_is_interrupt	  = false;
	aci_state.aci_pins.interrupt_number		  = 1;

        // Turn debug printing on for the ACI Commands and Events to be printed on the Serial
	lib_aci_debug_print(false);

	//We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
	//If the RESET line is not available we call the ACI Radio Reset to soft reset the nRF8001
	//then we initialize the data structures required to setup the nRF8001

//        delay(50);
//        lib_aci_radio_reset();
//        delay(50); 
        
        lib_aci_init(&aci_state, false);
}
示例#3
0
void ble_begin(E_BLE_INIT_MODE eInitMode)
{
	//if(E_BLE_INIT_MODE_POST_LATCH!=eInitMode)
	{
		 /* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001 */   
		if (NULL != services_pipe_type_mapping)
		{
			//shreedee teensy fix
				aci_state.aci_setup_info.services_pipe_type_mapping = (services_pipe_type_mapping_t*) &services_pipe_type_mapping[0];
		}
		else
		{
				aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
		 }
		
		aci_state.aci_setup_info.number_of_pipes    = NUMBER_OF_PIPES;

		//shreedee teensy fix
		aci_state.aci_setup_info.setup_msgs         = (hal_aci_data_t*)setup_msgs;
		
		
		aci_state.aci_setup_info.num_setup_msgs     = NB_SETUP_MESSAGES;

			/*
		Tell the ACI library, the MCU to nRF8001 pin connections.
		The Active pin is optional and can be marked UNUSED
		*/	  	
		aci_state.aci_pins.board_name = REDBEARLAB_SHIELD_V1_1; //See board.h for details
		aci_state.aci_pins.reqn_pin   = reqn_pin;
		aci_state.aci_pins.rdyn_pin   = rdyn_pin;
		aci_state.aci_pins.mosi_pin   = MOSI;
		aci_state.aci_pins.miso_pin   = MISO;
		aci_state.aci_pins.sck_pin    = SCK;
	
#if defined(__SAM3X8E__)
		aci_state.aci_pins.spi_clock_divider     = 84;
#else
		aci_state.aci_pins.spi_clock_divider     = SPI_CLOCK_DIV8;
#endif
	  
		aci_state.aci_pins.reset_pin             = UNUSED;
		aci_state.aci_pins.active_pin            = UNUSED;
		aci_state.aci_pins.optional_chip_sel_pin = UNUSED;
	  
		aci_state.aci_pins.interface_is_interrupt	  = false;
		aci_state.aci_pins.interrupt_number			  = 1;

		if(_interrupt_number!=0xFF)
		{
			aci_state.aci_pins.interface_is_interrupt	  = true;
			aci_state.aci_pins.interrupt_number			  = _interrupt_number;
			aci_state.aci_pins.interrupt_mode = _interrupt_mode;
		}

		//Turn debug printing on for the ACI Commands and Events to be printed on the Serial
		lib_aci_debug_print(true);
	}
	
	/*We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
		and initialize the data structures required to setup the nRF8001*/
	lib_aci_init(&aci_state,eInitMode); 
	
	if(E_BLE_INIT_MODE_PRELATCH!=eInitMode)
	//if(E_BLE_INIT_MODE_POR==eInitMode)
	{
	delay(100);
	}
		/*lib_aci_radio_reset();  
		while (1)
		{
				//Wait for the command response of the radio reset command.
				//as the nRF8001 will be in either SETUP or STANDBY after the ACI Reset Radio is processed  
				if (true == lib_aci_event_get(&aci_state, &aci_data))
				{
					aci_evt_t * aci_evt;      
					aci_evt = &aci_data.evt;    
					if (ACI_EVT_CMD_RSP == aci_evt->evt_opcode)
					{
							if (ACI_STATUS_ERROR_DEVICE_STATE_INVALID == aci_evt->params.cmd_rsp.cmd_status) //in SETUP
							{
									Serial.println(F("Do setup"));
									if (ACI_STATUS_TRANSACTION_COMPLETE != do_aci_setup(&aci_state))
									{
											Serial.println(F("Error in ACI Setup"));
									}              
							}
							else if (ACI_STATUS_SUCCESS == aci_evt->params.cmd_rsp.cmd_status) //We are now in STANDBY
							{*/
									//Looking for an iPhone by sending radio advertisements
									//When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
				//					lib_aci_connect(180/* in seconds */, 0x0050 /* advertising interval 50ms*/);
				/*					Serial.println(F("Advertising started"));              
							}
							break;
					}
					else
					{
							Serial.println(F("Device Started"));
					} 
				}
		}*/
}