These files define the NRF8001 interface for lib-nrf8001. Interaction with this device is done through the ACI routines included with the library. You can use the nRF UART app in Apple* App Store and Google* Play* on Samsung* Galaxy S*4 running Android* 4.3 to interact with a microcontroller running the 'hello world' example.
init_aci_setup ();
while (1) {
static bool setup_required = false;
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
printf ("Evt Device Started: Setup \n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby \n");
if (aci_evt->params.device_started.hw_error) {
usleep (20000);
} else {
printf ("Advertising started \n");
}
break;
}
}
break;
printf ("ACI_EVT_CMD_RSP \n");
}
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
}
break;
printf ("ACI_EVT_CONNECTED");
uart_over_ble_init ();
timing_change_done = false;
aci_state.data_credit_available = aci_state.data_credit_total;
break;
printf ("ACI_EVT_PIPE_STATUS \n");
timing_change_done = true;
char hello[]="Hello World, works";
uart_tx((uint8_t *)&hello[0], strlen(hello));
}
break;
printf ("Evt link connection interval changed \n");
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval),
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
break;
printf ("ACI_EVT_DISCONNECTED \n");
printf ("Advertising started \n");
break;
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
for(int i=0; i<aci_evt->len - 2; i++) {
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
}
uart_buffer_len = aci_evt->len - 2;
}
}
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
}
printf ("Incomming data - %s\n", uart_buffer);
break;
printf ("ACI_EVT_DATA_CREDIT \n");
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
break;
printf ("ACI_EVT_PIPE_ERROR \n");
aci_state.data_credit_available++;
}
break;
printf ("ACI_EVT_HW_ERROR \n");
printf ("Advertising started \n");
break;
}
}
if(setup_required) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);
init_aci_setup ();
while (1) {
static bool setup_required = false;
aci_evt_t * aci_evt;
aci_evt = &aci_data.evt;
switch(aci_evt->evt_opcode) {
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
switch(aci_evt->params.device_started.device_mode) {
case ACI_DEVICE_SETUP:
printf ("Evt Device Started: Setup\n");
setup_required = true;
break;
case ACI_DEVICE_STANDBY:
printf ("Evt Device Started: Standby\n");
printf ("Broadcasting started\n");
break;
}
}
break;
printf ("ACI_EVT_CMD_RSP\n");
while (1);
}
break;
printf ("ACI_EVT_CONNECTED\n");
break;
printf ("ACI_EVT_PIPE_STATUS\n");
break;
printf ("Broadcasting timed out\n");
} else {
printf ("Evt Disconnected. Link Loss\n");
}
break;
printf ("ACI_EVT_DATA_RECEIVED\n");
break;
printf ("ACI_EVT_HW_ERROR\n");
break;
}
}
if (setup_required) {
setup_required = false;
}
}
usleep (100);
}
close_local_interfaces (&aci_state);
Include the services_lock.h to put the setup in the OTP memory of the nRF8001. This would mean that the setup cannot be changed once put in. However this removes the need to do the setup of the nRF8001 on every reset.
Tell the ACI library, the MCU to nRF8001 pin connections. The Active pin is optional and can be marked UNUSED