/* Copyright (c) 2009 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. * */ /** @file * @brief Example template project. * @defgroup nrf_templates_example Example Template * */ #include #include "nrf_gpio.h" #include "nrf_drv_twi.h" #include "bsp.h" #include "app_error.h" #include "nrf_drv_config.h" #include "app_util_platform.h" #include "nrf_delay.h" // TWI event handler. Processing TWI events originating from // nrf_drv_twi_tx() static void twi_event_handler(nrf_drv_twi_evt_t *evt){ // Light up LED 1 if device found if(evt->type == NRF_DRV_TWI_TX_DONE) { nrf_gpio_pin_set(LED_3); // nrf_gpio_pin_clear(LED_3); } } static void gpio_init() { nrf_gpio_cfg_output(LED_3); } /** * @brief Function for application main entry. */ uint8_t dummy_data1; int main(void) { gpio_init(); ret_code_t ret_code; const nrf_drv_twi_t p_twi_instance = NRF_DRV_TWI_INSTANCE(1); // Set up TWI instance 1 with default values // EITHER CONFIGURE THE TWI MODULE WITH DEFAULT VALUES: // nrf_drv_twi_config_t p_twi_config = NRF_DRV_TWI_DEFAULT_CONFIG(1);// Set up TWI configuration default values // OR CHOOSE YOU OWN TWI MODULE SETTINGS LIKE THIS: nrf_drv_twi_config_t p_twi_config; p_twi_config.scl = 7; p_twi_config.sda = 30; p_twi_config.frequency = NRF_TWI_FREQ_400K; p_twi_config.interrupt_priority = APP_IRQ_PRIORITY_LOW; ret_code = nrf_drv_twi_init(&p_twi_instance, &p_twi_config, twi_event_handler); // Initiate twi driver with instance and configuration values APP_ERROR_CHECK(ret_code); // Check for errors in return value nrf_drv_twi_enable(&p_twi_instance); // Enable the TWI instance static uint8_t dummy_data[2] = {0x20,0x55}; // Declare some dummy data to use for our search for devices on the TWI bus //WRITE nrf_drv_twi_tx(&p_twi_instance, 0x6F,dummy_data, 2, false); nrf_delay_ms(500); //READ nrf_drv_twi_tx(&p_twi_instance, 0x6F,&dummy_data[0], 1, true); nrf_drv_twi_rx(&p_twi_instance, 0x6F,&dummy_data1, 1, false); while (true) { // Do nothing } } /** @} */