/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free, non-transferable use of the information. NO * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * * $LastChangedRevision: 40042 $ */ /** * This project requires that a device that runs the * @ref gzll_device_m_ack_payload_example is used as a counterpart for * receiving the data. This can be on either an nRF5x device or an nRF24Lxx device * running the \b gzll_device_m_ack_payload example in the nRFgo SDK. * * This example listens for a packet and sends an ACK * when a packet is received. The contents of the first payload byte of * the received packet is output on the GPIO Port BUTTONS. * The contents of GPIO Port LEDS are sent in the first payload byte (byte 0) * of the ACK packet. */ #include "nrf_gzll.h" #include "bsp.h" #include "app_timer.h" #include "app_error.h" #include "nrf_gzll_error.h" #define NRF_LOG_MODULE_NAME "APP" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "app_uart.h" #include "nrf_delay.h" /*****************************************************************************/ /** @name Configuration */ /*****************************************************************************/ #define PIPE_0 0 ///< PIPE_NUMBER 0 is used in this example. #define PIPE_1 1 #define TX_PAYLOAD_LENGTH 1 ///< 1-byte payload length is used when transmitting. #define APP_TIMER_PRESCALER 0 ///< Value of the RTC PRESCALER register. #define APP_TIMER_OP_QUEUE_SIZE 8u ///< Size of timer operation queues. #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */ #define UART_TX_BUF_SIZE 32 /**< UART TX buffer size. */ #define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */ #define LEDAS 4 #define NRF_GZLL_CHANNEL_TAB {17, 11} //{11, 17, 19, 3, 9, 27} ///< Redefine channel table. #define NRF_GZLL_CHANNEL_TAB_SIZE 2 int16_t data_acc[6]; float acc[3]; int16_t data_gyr[6]; float DPS[3]; float g=9.81; float C_BAT; double vbat; bool output_present; bool pipes_enabled; static uint8_t data_payload[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH+4]; ///< Placeholder for data payload received from host. static uint8_t ack_payload[TX_PAYLOAD_LENGTH]; ///< Payload to attach to ACK sent to device. extern nrf_gzll_error_code_t nrf_gzll_error_code; ///< Error code. bool UART_send_success; uint8_t PIPE_NUMBER; uint32_t enabled_pipes=6; /** * @brief Function to control the LED outputs. * * @param[in] val Desirable state of the LEDs. */ /** * @brief Initialize the BSP modules. */ /*****************************************************************************/ /** @name Gazell callback function definitions. */ /*****************************************************************************/ /** * @brief RX data ready callback. * * @details If a data packet was received, the first byte is written to LEDS. */ uint32_t data_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH; uint32_t data_payload_length2 = 0; void nrf_gzll_host_rx_data_ready(uint32_t pipe, nrf_gzll_host_rx_info_t rx_info) { // Pop packet and write first byte of the payload to the GPIO port. bool result_value = nrf_gzll_fetch_packet_from_rx_fifo(pipe, &data_payload[4], &data_payload_length); if (data_payload_length > 0) // if data received - send trhough UART to PC { data_payload[0] = 'D'; //app_uart_put('D'); data_payload_length2=24+4; //TODO data_payload[1] = ((0xFFFF&data_payload_length2)>>8); data_payload[2] = (0xFF&data_payload_length2); data_payload[3] = '!'; //app_uart_put('!'); for(int i=0; ievt_type == APP_UART_COMMUNICATION_ERROR) { APP_ERROR_HANDLER(p_event->data.error_communication); } else if (p_event->evt_type == APP_UART_FIFO_ERROR) { APP_ERROR_HANDLER(p_event->data.error_code); } } void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info) { } /** * @brief Gazelle callback. * @warning Required for successful Gazell initialization. */ void nrf_gzll_device_tx_failed(uint32_t p, nrf_gzll_device_tx_info_t tx_info) { } /** * @brief Gazelle callback. * @warning Required for successful Gazell initialization. */ void nrf_gzll_disabled() { } /*****************************************************************************/ /** * @brief Main function. * @return ANSI required int return type. */ /*****************************************************************************/ int main() { nrf_gpio_cfg_output(LEDAS); nrf_gpio_pin_set(LEDAS); uint32_t err_code; const app_uart_comm_params_t comm_params = { 18, //RX_PIN_NUMBER, 15,//TX_PIN_NUMBER, 16,//RTS_PIN_NUMBER, 11,//,CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_DISABLED, false, UART_BAUDRATE_BAUDRATE_Baud921600//UART_BAUDRATE_BAUDRATE_Baud38400 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); // Initialize Gazell. pipes_enabled=nrf_gzll_set_rx_pipes_enabled(enabled_pipes); bool result_value = nrf_gzll_init(NRF_GZLL_MODE_HOST); GAZELLE_ERROR_CODE_CHECK(result_value); result_value=nrf_gzll_set_timeslots_per_channel(2); result_value = nrf_gzll_set_timeslot_period(600); result_value = nrf_gzll_set_datarate(NRF_GZLL_DATARATE_2MBIT); uint8_t table[] = NRF_GZLL_CHANNEL_TAB; result_value = nrf_gzll_set_channel_table(table, NRF_GZLL_CHANNEL_TAB_SIZE); pipes_enabled=nrf_gzll_set_rx_pipes_enabled(enabled_pipes); // Load data into TX queue. ack_payload[0] = 1; // Enable Gazell to start sending over the air. result_value = nrf_gzll_enable(); GAZELLE_ERROR_CODE_CHECK(result_value); while (1) { __WFE(); } }