Commit 7d97fe7c authored by Xin Jin's avatar Xin Jin

20191106

parent 4bfbc2ab
...@@ -119,17 +119,6 @@ static void on_disconnected(ble_advertising_t * const p_advertising, ble_evt_t c ...@@ -119,17 +119,6 @@ static void on_disconnected(ble_advertising_t * const p_advertising, ble_evt_t c
if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle && if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false) p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false)
{ {
uint8_t reason = p_ble_evt->evt.gap_evt.params.disconnected.reason;
if(reason != 0x13)
{
NRF_LOG_INFO("start advertising after disconnect!!!!\r\n");
ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
}
else
{
NRF_LOG_INFO("witout advertising after disconnect!!!!\r\n");
}
if ((ret != NRF_SUCCESS) && (p_advertising->error_handler != NULL)) if ((ret != NRF_SUCCESS) && (p_advertising->error_handler != NULL))
{ {
p_advertising->error_handler(ret); p_advertising->error_handler(ret);
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#include "ble_dfu.h" #include "ble_dfu.h"
#include "lis3dh.h" #include "lis3dh.h"
#include "nrf_delay.h"
#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */ #define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
...@@ -128,6 +129,8 @@ APP_TIMER_DEF(m_tick_timer_id); /**< Polling timer id. */ ...@@ -128,6 +129,8 @@ APP_TIMER_DEF(m_tick_timer_id); /**< Polling timer id. */
APP_TIMER_DEF(m_reset_timer_id); /**< Polling timer id. */ APP_TIMER_DEF(m_reset_timer_id); /**< Polling timer id. */
APP_TIMER_DEF(m_wdt_timer_id); /**< Polling timer id. */ APP_TIMER_DEF(m_wdt_timer_id); /**< Polling timer id. */
APP_TIMER_DEF(m_motion_timer_id); /**< Polling timer id. */ APP_TIMER_DEF(m_motion_timer_id); /**< Polling timer id. */
APP_TIMER_DEF(m_adc_timer_id);
APP_TIMER_DEF(m_test_timer_id);
BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); /**< BLE NUS service instance. */ BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); /**< BLE NUS service instance. */
...@@ -138,11 +141,12 @@ BLE_ADVERTISING_DEF(m_advertising); ...@@ -138,11 +141,12 @@ BLE_ADVERTISING_DEF(m_advertising);
static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Handle of the current connection. */ static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Handle of the current connection. */
static uint16_t m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /**< Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module. */ static uint16_t m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /**< Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module. */
static void advertising_start(void); static void advertising_start(void);
static ble_gap_addr_t userAppMAC;
app_user_data_struct g_app_data; app_user_data_struct g_app_data;
uint16_t uFlagAdcChanelMask = 0; uint16_t uFlagAdcChanelMask = 0;
uint16_t uFlagBleAdverState = 0; uint16_t uFlagBleAdverState = 0;
uint16_t uFlagFactoryTesting = 0;
/* /*
static uint8_t m_enc_advdata[31]; static uint8_t m_enc_advdata[31];
...@@ -335,6 +339,14 @@ static void user_send_reponse(uint8_t r) ...@@ -335,6 +339,14 @@ static void user_send_reponse(uint8_t r)
NRF_LOG_INFO("Send config data ===%d !\r\n", r); NRF_LOG_INFO("Send config data ===%d !\r\n", r);
} }
static void user_send_data(uint8_t* buf, uint16_t len)
{
uint16_t length = len+2;
uint8_t data_arry[20] = {0x10, 0x01, 0};
memcpy(&data_arry[2], buf, len);
ble_nus_data_send(&m_nus, data_arry, &length, m_conn_handle);
}
/**@brief Function for handling the data from the Nordic UART Service. /**@brief Function for handling the data from the Nordic UART Service.
* *
...@@ -403,6 +415,12 @@ static void nus_data_handler(ble_nus_evt_t * p_evt) ...@@ -403,6 +415,12 @@ static void nus_data_handler(ble_nus_evt_t * p_evt)
NRF_LOG_INFO("Send config data array!\r\n"); NRF_LOG_INFO("Send config data array!\r\n");
} }
break; break;
case 0x11:
/////read the factory test command
uFlagFactoryTesting = 1;
app_adc_start_sensor_convert();
app_timer_start(m_test_timer_id, APP_TIMER_TICKS(300), NULL);
break;
default: default:
break; break;
} }
...@@ -970,10 +988,15 @@ static void user_tick_timeout_handler(void * p_context) ...@@ -970,10 +988,15 @@ static void user_tick_timeout_handler(void * p_context)
{ {
g_app_data.tickCounter++; g_app_data.tickCounter++;
NRF_LOG_INFO("user_tick_handler=== %d, %d, %d!\r\n",g_app_data.tickCounter, g_app_data.CompCounter, g_app_data.devMoved); NRF_LOG_INFO("user_tick_handler=== %d, %d, %d!\r\n",g_app_data.tickCounter, g_app_data.CompCounter, g_app_data.devMoved);
if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
{
NRF_LOG_INFO("Device connected, and don't advertising!");
return;
}
if(g_app_data.tickCounter >= g_app_data.CompCounter) if(g_app_data.tickCounter >= g_app_data.CompCounter)
{ {
g_app_data.tickCounter = 0; g_app_data.tickCounter = 0;
...@@ -1025,16 +1048,13 @@ static void user_wdt_timeout_handler(void * p_context) ...@@ -1025,16 +1048,13 @@ static void user_wdt_timeout_handler(void * p_context)
adcBatCnt = 60; adcBatCnt = 60;
adcLight = 30; //// adcLight = 30; ////
} }
uFlagAdcChanelMask++; uFlagAdcChanelMask++;
//NRF_LOG_INFO("feed wdt----%d!\r\n",uFlagAdcChanelMask); //NRF_LOG_INFO("feed wdt----%d!\r\n",uFlagAdcChanelMask);
if((uFlagAdcChanelMask % adcLight) == 0) if((uFlagAdcChanelMask % adcLight) == 0)
{ {
nrf_gpio_pin_dir_set(6, NRF_GPIO_PIN_DIR_OUTPUT); app_timer_start(m_adc_timer_id, APP_TIMER_TICKS(200), NULL);
nrf_gpio_pin_set(6);
nrf_gpio_pin_set(6);
app_adc_start_sensor_convert();
} }
else if(uFlagAdcChanelMask >= adcBatCnt) else if(uFlagAdcChanelMask >= adcBatCnt)
{ {
...@@ -1082,9 +1102,51 @@ void user_reset_motion_timer(void) ...@@ -1082,9 +1102,51 @@ void user_reset_motion_timer(void)
} }
} }
static uint16_t sensor_counter = 0;
static void user_sensor_timeout_handler(void * p_context)
{
app_timer_stop(m_adc_timer_id);
if(uFlagFactoryTesting > 0)
return;
if(sensor_counter++ < 4)
{
app_adc_start_sensor_convert();
app_timer_start(m_adc_timer_id, APP_TIMER_TICKS(100), NULL);
}
else
{
nrf_gpio_pin_clear(6);
sensor_counter = 0;
}
}
static void user_test_timeout_handler(void * p_context)
{
////hasSensor | light*2 | XYZ *2
uint8_t testSendBuffer[20] ={0};
app_timer_stop(m_test_timer_id);
testSendBuffer[0] = g_app_data.perVbat;
testSendBuffer[1] = (g_app_data.lightSensorAdc >> 8) & 0xff;
testSendBuffer[2] = (g_app_data.lightSensorAdc >> 0) & 0xff;
testSendBuffer[3] = g_app_data.hasSensor;
LIS3DH_read_XYZ(&testSendBuffer[4]);
/////MAC addr
memcpy(&testSendBuffer[10], userAppMAC.addr, 6);
user_send_data(testSendBuffer, 16);
NRF_LOG_INFO("user_test_timeout_handler--1!\r\n");
uFlagFactoryTesting = 0;
}
/**@brief Application main function. /**@brief Application main function.
*/ */
int main(void) int main(void)
{ {
log_init(); log_init();
...@@ -1105,6 +1167,14 @@ int main(void) ...@@ -1105,6 +1167,14 @@ int main(void)
app_timer_create(&m_motion_timer_id, app_timer_create(&m_motion_timer_id,
APP_TIMER_MODE_SINGLE_SHOT, APP_TIMER_MODE_SINGLE_SHOT,
user_motion_timeout_handler); user_motion_timeout_handler);
app_timer_create(&m_adc_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
user_sensor_timeout_handler);
app_timer_create(&m_test_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
user_test_timeout_handler);
g_app_data.ncCounter = 0; g_app_data.ncCounter = 0;
g_app_data.perVbat = 100; g_app_data.perVbat = 100;
...@@ -1131,6 +1201,8 @@ int main(void) ...@@ -1131,6 +1201,8 @@ int main(void)
power_management_init(); power_management_init();
ble_stack_init(); ble_stack_init();
sd_ble_gap_addr_get(&userAppMAC);
gap_params_init(); gap_params_init();
gatt_init(); gatt_init();
...@@ -1148,7 +1220,6 @@ int main(void) ...@@ -1148,7 +1220,6 @@ int main(void)
app_timer_start(m_tick_timer_id, APP_TIMER_TICKS(TICK_TIMER_TIM*1000), NULL); app_timer_start(m_tick_timer_id, APP_TIMER_TICKS(TICK_TIMER_TIM*1000), NULL);
if(g_app_data.hasSensor == 1) if(g_app_data.hasSensor == 1)
{ {
app_timer_start(m_motion_timer_id, APP_TIMER_TICKS(MOTION_TIMER_SECOND*1000), NULL); app_timer_start(m_motion_timer_id, APP_TIMER_TICKS(MOTION_TIMER_SECOND*1000), NULL);
...@@ -1157,7 +1228,8 @@ int main(void) ...@@ -1157,7 +1228,8 @@ int main(void)
///this timer used for feed watch dog ///this timer used for feed watch dog
app_timer_start(m_wdt_timer_id, APP_TIMER_TICKS(9313), NULL); app_timer_start(m_wdt_timer_id, APP_TIMER_TICKS(9313), NULL);
NRF_LOG_INFO("App init!\r\n"); NRF_LOG_INFO("App init== %X, %X, %X, %X!\r\n", userAppMAC.addr[0],
userAppMAC.addr[1],userAppMAC.addr[2],userAppMAC.addr[3]);
// Enter main loop. // Enter main loop.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -140,40 +140,7 @@ ...@@ -140,40 +140,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000 -FP0($$Device:nRF52810_xxAA$Flash\nrf52xxx))</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0nrf52xxx -FS00 -FL0200000 -FP0($$Device:nRF52810_xxAA$Flash\nrf52xxx))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint/>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>1114</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>118464</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>E:\work\WITIUM\RAIS\3杞欢璁捐\2浠g爜\Tag_tracker\examples\ble_peripheral\ble_app_uart\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>1121</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>118516</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>E:\work\WITIUM\RAIS\3杞欢璁捐\2浠g爜\Tag_tracker\examples\ble_peripheral\ble_app_uart\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\nrf52810_TAG_V102\../../../main.c\1121</Expression>
</Bp>
</Breakpoint>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>
......
...@@ -363,7 +363,7 @@ ...@@ -363,7 +363,7 @@
<useXO>0</useXO> <useXO>0</useXO>
<VariousControls> <VariousControls>
<MiscControls>--reduce_paths</MiscControls> <MiscControls>--reduce_paths</MiscControls>
<Define>BL_SETTINGS_ACCESS_ONLY NRF_DFU_SVCI_ENABLED NRF_DFU_TRANSPORT_BLE=1 BOARD_PCA10040 CONFIG_GPIO_AS_PINRESET DEVELOP_IN_NRF52832 FLOAT_ABI_SOFT NRF52810_XXAA NRF52_PAN_74 NRF_SD_BLE_API_VERSION=6 S112 SOFTDEVICE_PRESENT SWI_DISABLE0 __HEAP_SIZE=2048 __STACK_SIZE=2048 xDEBUG</Define> <Define>BL_SETTINGS_ACCESS_ONLY NRF_DFU_SVCI_ENABLED NRF_DFU_TRANSPORT_BLE=1 BOARD_PCA10040 CONFIG_GPIO_AS_PINRESET DEVELOP_IN_NRF52832 FLOAT_ABI_SOFT NRF52810_XXAA NRF52_PAN_74 NRF_SD_BLE_API_VERSION=6 S112 SOFTDEVICE_PRESENT SWI_DISABLE0 __HEAP_SIZE=2048 __STACK_SIZE=2048 DEBUG</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>..\..\..\config;..\..\..\..\..\..\components;..\..\..\..\..\..\components\ble\ble_advertising;..\..\..\..\..\..\components\ble\ble_dtm;..\..\..\..\..\..\components\ble\ble_link_ctx_manager;..\..\..\..\..\..\components\ble\ble_racp;..\..\..\..\..\..\components\ble\ble_services\ble_ancs_c;..\..\..\..\..\..\components\ble\ble_services\ble_ans_c;..\..\..\..\..\..\components\ble\ble_services\ble_bas;..\..\..\..\..\..\components\ble\ble_services\ble_bas_c;..\..\..\..\..\..\components\ble\ble_services\ble_cscs;..\..\..\..\..\..\components\ble\ble_services\ble_cts_c;..\..\..\..\..\..\components\ble\ble_services\ble_dfu;..\..\..\..\..\..\components\ble\ble_services\ble_dis;..\..\..\..\..\..\components\ble\ble_services\ble_gls;..\..\..\..\..\..\components\ble\ble_services\ble_hids;..\..\..\..\..\..\components\ble\ble_services\ble_hrs;..\..\..\..\..\..\components\ble\ble_services\ble_hrs_c;..\..\..\..\..\..\components\ble\ble_services\ble_hts;..\..\..\..\..\..\components\ble\ble_services\ble_ias;..\..\..\..\..\..\components\ble\ble_services\ble_ias_c;..\..\..\..\..\..\components\ble\ble_services\ble_lbs;..\..\..\..\..\..\components\ble\ble_services\ble_lbs_c;..\..\..\..\..\..\components\ble\ble_services\ble_lls;..\..\..\..\..\..\components\ble\ble_services\ble_nus;..\..\..\..\..\..\components\ble\ble_services\ble_nus_c;..\..\..\..\..\..\components\ble\ble_services\ble_rscs;..\..\..\..\..\..\components\ble\ble_services\ble_rscs_c;..\..\..\..\..\..\components\ble\ble_services\ble_tps;..\..\..\..\..\..\components\ble\common;..\..\..\..\..\..\components\ble\nrf_ble_gatt;..\..\..\..\..\..\components\ble\nrf_ble_qwr;..\..\..\..\..\..\components\ble\peer_manager;..\..\..\..\..\..\components\boards;..\..\..\..\..\..\components\drivers_nrf\usbd;..\..\..\..\..\..\components\libraries\atomic;..\..\..\..\..\..\components\libraries\atomic_fifo;..\..\..\..\..\..\components\libraries\atomic_flags;..\..\..\..\..\..\components\libraries\balloc;..\..\..\..\..\..\components\libraries\bootloader\ble_dfu;..\..\..\..\..\..\components\libraries\bsp;..\..\..\..\..\..\components\libraries\button;..\..\..\..\..\..\components\libraries\cli;..\..\..\..\..\..\components\libraries\crc16;..\..\..\..\..\..\components\libraries\crc32;..\..\..\..\..\..\components\libraries\crypto;..\..\..\..\..\..\components\libraries\csense;..\..\..\..\..\..\components\libraries\csense_drv;..\..\..\..\..\..\components\libraries\delay;..\..\..\..\..\..\components\libraries\ecc;..\..\..\..\..\..\components\libraries\experimental_section_vars;..\..\..\..\..\..\components\libraries\experimental_task_manager;..\..\..\..\..\..\components\libraries\fds;..\..\..\..\..\..\components\libraries\fifo;..\..\..\..\..\..\components\libraries\fstorage;..\..\..\..\..\..\components\libraries\gfx;..\..\..\..\..\..\components\libraries\gpiote;..\..\..\..\..\..\components\libraries\hardfault;..\..\..\..\..\..\components\libraries\hci;..\..\..\..\..\..\components\libraries\led_softblink;..\..\..\..\..\..\components\libraries\log;..\..\..\..\..\..\components\libraries\log\src;..\..\..\..\..\..\components\libraries\low_power_pwm;..\..\..\..\..\..\components\libraries\mem_manager;..\..\..\..\..\..\components\libraries\memobj;..\..\..\..\..\..\components\libraries\mpu;..\..\..\..\..\..\components\libraries\mutex;..\..\..\..\..\..\components\libraries\pwm;..\..\..\..\..\..\components\libraries\pwr_mgmt;..\..\..\..\..\..\components\libraries\queue;..\..\..\..\..\..\components\libraries\ringbuf;..\..\..\..\..\..\components\libraries\scheduler;..\..\..\..\..\..\components\libraries\sdcard;..\..\..\..\..\..\components\libraries\slip;..\..\..\..\..\..\components\libraries\sortlist;..\..\..\..\..\..\components\libraries\spi_mngr;..\..\..\..\..\..\components\libraries\stack_guard;..\..\..\..\..\..\components\libraries\strerror;..\..\..\..\..\..\components\libraries\svc;..\..\..\..\..\..\components\libraries\timer;..\..\..\..\..\..\components\libraries\twi_mngr;..\..\..\..\..\..\components\libraries\twi_sensor;..\..\..\..\..\..\components\libraries\uart;..\..\..\..\..\..\components\libraries\usbd;..\..\..\..\..\..\components\libraries\usbd\class\audio;..\..\..\..\..\..\components\libraries\usbd\class\cdc;..\..\..\..\..\..\components\libraries\usbd\class\cdc\acm;..\..\..\..\..\..\components\libraries\usbd\class\hid;..\..\..\..\..\..\components\libraries\usbd\class\hid\generic;..\..\..\..\..\..\components\libraries\usbd\class\hid\kbd;..\..\..\..\..\..\components\libraries\usbd\class\hid\mouse;..\..\..\..\..\..\components\libraries\usbd\class\msc;..\..\..\..\..\..\components\libraries\util;..\..\..\..\..\..\components\softdevice\common;..\..\..\..\..\..\components\softdevice\s112\headers;..\..\..\..\..\..\components\softdevice\s112\headers\nrf52;..\..\..\..\..\..\external\fprintf;..\..\..\..\..\..\external\segger_rtt;..\..\..\..\..\..\external\utf_converter;..\..\..\..\..\..\integration\nrfx;..\..\..\..\..\..\integration\nrfx\legacy;..\..\..\..\..\..\modules\nrfx;..\..\..\..\..\..\modules\nrfx\drivers\include;..\..\..\..\..\..\modules\nrfx\hal;..\..\..\..\..\..\modules\nrfx\mdk;..\config;..\..\..\user;..\..\..\..\..\..\components\ble\ble_services\ble_dfu;..\..\..\..\..\..\components\libraries\bootloader;..\..\..\..\..\..\components\libraries\bootloader\ble_dfu;..\..\..\..\..\..\components\libraries\bootloader\dfu;..\..\..\..\..\..\components\libraries\svc</IncludePath> <IncludePath>..\..\..\config;..\..\..\..\..\..\components;..\..\..\..\..\..\components\ble\ble_advertising;..\..\..\..\..\..\components\ble\ble_dtm;..\..\..\..\..\..\components\ble\ble_link_ctx_manager;..\..\..\..\..\..\components\ble\ble_racp;..\..\..\..\..\..\components\ble\ble_services\ble_ancs_c;..\..\..\..\..\..\components\ble\ble_services\ble_ans_c;..\..\..\..\..\..\components\ble\ble_services\ble_bas;..\..\..\..\..\..\components\ble\ble_services\ble_bas_c;..\..\..\..\..\..\components\ble\ble_services\ble_cscs;..\..\..\..\..\..\components\ble\ble_services\ble_cts_c;..\..\..\..\..\..\components\ble\ble_services\ble_dfu;..\..\..\..\..\..\components\ble\ble_services\ble_dis;..\..\..\..\..\..\components\ble\ble_services\ble_gls;..\..\..\..\..\..\components\ble\ble_services\ble_hids;..\..\..\..\..\..\components\ble\ble_services\ble_hrs;..\..\..\..\..\..\components\ble\ble_services\ble_hrs_c;..\..\..\..\..\..\components\ble\ble_services\ble_hts;..\..\..\..\..\..\components\ble\ble_services\ble_ias;..\..\..\..\..\..\components\ble\ble_services\ble_ias_c;..\..\..\..\..\..\components\ble\ble_services\ble_lbs;..\..\..\..\..\..\components\ble\ble_services\ble_lbs_c;..\..\..\..\..\..\components\ble\ble_services\ble_lls;..\..\..\..\..\..\components\ble\ble_services\ble_nus;..\..\..\..\..\..\components\ble\ble_services\ble_nus_c;..\..\..\..\..\..\components\ble\ble_services\ble_rscs;..\..\..\..\..\..\components\ble\ble_services\ble_rscs_c;..\..\..\..\..\..\components\ble\ble_services\ble_tps;..\..\..\..\..\..\components\ble\common;..\..\..\..\..\..\components\ble\nrf_ble_gatt;..\..\..\..\..\..\components\ble\nrf_ble_qwr;..\..\..\..\..\..\components\ble\peer_manager;..\..\..\..\..\..\components\boards;..\..\..\..\..\..\components\drivers_nrf\usbd;..\..\..\..\..\..\components\libraries\atomic;..\..\..\..\..\..\components\libraries\atomic_fifo;..\..\..\..\..\..\components\libraries\atomic_flags;..\..\..\..\..\..\components\libraries\balloc;..\..\..\..\..\..\components\libraries\bootloader\ble_dfu;..\..\..\..\..\..\components\libraries\bsp;..\..\..\..\..\..\components\libraries\button;..\..\..\..\..\..\components\libraries\cli;..\..\..\..\..\..\components\libraries\crc16;..\..\..\..\..\..\components\libraries\crc32;..\..\..\..\..\..\components\libraries\crypto;..\..\..\..\..\..\components\libraries\csense;..\..\..\..\..\..\components\libraries\csense_drv;..\..\..\..\..\..\components\libraries\delay;..\..\..\..\..\..\components\libraries\ecc;..\..\..\..\..\..\components\libraries\experimental_section_vars;..\..\..\..\..\..\components\libraries\experimental_task_manager;..\..\..\..\..\..\components\libraries\fds;..\..\..\..\..\..\components\libraries\fifo;..\..\..\..\..\..\components\libraries\fstorage;..\..\..\..\..\..\components\libraries\gfx;..\..\..\..\..\..\components\libraries\gpiote;..\..\..\..\..\..\components\libraries\hardfault;..\..\..\..\..\..\components\libraries\hci;..\..\..\..\..\..\components\libraries\led_softblink;..\..\..\..\..\..\components\libraries\log;..\..\..\..\..\..\components\libraries\log\src;..\..\..\..\..\..\components\libraries\low_power_pwm;..\..\..\..\..\..\components\libraries\mem_manager;..\..\..\..\..\..\components\libraries\memobj;..\..\..\..\..\..\components\libraries\mpu;..\..\..\..\..\..\components\libraries\mutex;..\..\..\..\..\..\components\libraries\pwm;..\..\..\..\..\..\components\libraries\pwr_mgmt;..\..\..\..\..\..\components\libraries\queue;..\..\..\..\..\..\components\libraries\ringbuf;..\..\..\..\..\..\components\libraries\scheduler;..\..\..\..\..\..\components\libraries\sdcard;..\..\..\..\..\..\components\libraries\slip;..\..\..\..\..\..\components\libraries\sortlist;..\..\..\..\..\..\components\libraries\spi_mngr;..\..\..\..\..\..\components\libraries\stack_guard;..\..\..\..\..\..\components\libraries\strerror;..\..\..\..\..\..\components\libraries\svc;..\..\..\..\..\..\components\libraries\timer;..\..\..\..\..\..\components\libraries\twi_mngr;..\..\..\..\..\..\components\libraries\twi_sensor;..\..\..\..\..\..\components\libraries\uart;..\..\..\..\..\..\components\libraries\usbd;..\..\..\..\..\..\components\libraries\usbd\class\audio;..\..\..\..\..\..\components\libraries\usbd\class\cdc;..\..\..\..\..\..\components\libraries\usbd\class\cdc\acm;..\..\..\..\..\..\components\libraries\usbd\class\hid;..\..\..\..\..\..\components\libraries\usbd\class\hid\generic;..\..\..\..\..\..\components\libraries\usbd\class\hid\kbd;..\..\..\..\..\..\components\libraries\usbd\class\hid\mouse;..\..\..\..\..\..\components\libraries\usbd\class\msc;..\..\..\..\..\..\components\libraries\util;..\..\..\..\..\..\components\softdevice\common;..\..\..\..\..\..\components\softdevice\s112\headers;..\..\..\..\..\..\components\softdevice\s112\headers\nrf52;..\..\..\..\..\..\external\fprintf;..\..\..\..\..\..\external\segger_rtt;..\..\..\..\..\..\external\utf_converter;..\..\..\..\..\..\integration\nrfx;..\..\..\..\..\..\integration\nrfx\legacy;..\..\..\..\..\..\modules\nrfx;..\..\..\..\..\..\modules\nrfx\drivers\include;..\..\..\..\..\..\modules\nrfx\hal;..\..\..\..\..\..\modules\nrfx\mdk;..\config;..\..\..\user;..\..\..\..\..\..\components\ble\ble_services\ble_dfu;..\..\..\..\..\..\components\libraries\bootloader;..\..\..\..\..\..\components\libraries\bootloader\ble_dfu;..\..\..\..\..\..\components\libraries\bootloader\dfu;..\..\..\..\..\..\components\libraries\svc</IncludePath>
</VariousControls> </VariousControls>
......
...@@ -195,7 +195,7 @@ int LIS3DH_Init(void) ...@@ -195,7 +195,7 @@ int LIS3DH_Init(void)
LIS3DH_WriteReg(0x32, 0x17); ///62*16 = 1g LIS3DH_WriteReg(0x32, 0x17); ///62*16 = 1g
LIS3DH_WriteReg(0x33, 0x01); ///duration LIS3DH_WriteReg(0x33, 0x01); ///duration
*/ */
LIS3DH_WriteReg(0x20, 0x17); ///0x20: 10hz, 0x10: 1hz, 0x50: 100hz, bit3: normal mode LIS3DH_WriteReg(0x20, 0x27); ///0x20: 10hz, 0x10: 1hz, 0x50: 100hz, bit3: normal mode
LIS3DH_WriteReg(0x21, 0x01); ///////09, 00 LIS3DH_WriteReg(0x21, 0x01); ///////09, 00
LIS3DH_WriteReg(0x22, 0x40); LIS3DH_WriteReg(0x22, 0x40);
LIS3DH_WriteReg(0x23, 0xA8); ///8g, bit3: normal mode enable, 12bits LIS3DH_WriteReg(0x23, 0xA8); ///8g, bit3: normal mode enable, 12bits
...@@ -217,10 +217,9 @@ int LIS3DH_Init(void) ...@@ -217,10 +217,9 @@ int LIS3DH_Init(void)
uint32_t LIS3DH_read_XYZ(void) uint32_t LIS3DH_read_XYZ(uint8_t* rBuffer)
{ {
int i =0; int i =0;
uint8_t rBuffer[8];
uint16_t x,y,z; uint16_t x,y,z;
//LIS3DH_ReadMultiReg(0x28, rBuffer, 6); //LIS3DH_ReadMultiReg(0x28, rBuffer, 6);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
/////application api////////////// /////application api//////////////
extern int LIS3DH_Init(void); extern int LIS3DH_Init(void);
extern void LIS3DH_IntInit(void); extern void LIS3DH_IntInit(void);
extern uint32_t LIS3DH_read_XYZ(void); extern uint32_t LIS3DH_read_XYZ(uint8_t* buf);
#endif #endif
...@@ -79,6 +79,7 @@ static void app_adc_vdd_init(void) ...@@ -79,6 +79,7 @@ static void app_adc_vdd_init(void)
nrf_saadc_channel_config_t config = nrf_saadc_channel_config_t config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD); NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
err_code = nrf_drv_saadc_channel_init(0, &config); err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
...@@ -87,6 +88,7 @@ static void app_adc_vdd_init(void) ...@@ -87,6 +88,7 @@ static void app_adc_vdd_init(void)
} }
static void saadc_event_light_sensor_handler(nrf_drv_saadc_evt_t const * p_event) static void saadc_event_light_sensor_handler(nrf_drv_saadc_evt_t const * p_event)
{ {
if (p_event->type == NRF_DRV_SAADC_EVT_DONE) if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
...@@ -96,17 +98,17 @@ static void saadc_event_light_sensor_handler(nrf_drv_saadc_evt_t const * p_event ...@@ -96,17 +98,17 @@ static void saadc_event_light_sensor_handler(nrf_drv_saadc_evt_t const * p_event
uint32_t err_code; uint32_t err_code;
adc_result = p_event->data.done.p_buffer[0]; adc_result = p_event->data.done.p_buffer[0];
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1); err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
lux_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + lux_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result);
DIODE_FWD_VOLT_DROP_MILLIVOLTS;
nrfx_saadc_uninit(); nrfx_saadc_uninit();
nrf_gpio_pin_clear(6);
g_app_data.lightSensorAdc = lux_in_milli_volts; g_app_data.lightSensorAdc = lux_in_milli_volts;
NRF_LOG_INFO("light====%d!!!!\r\n", lux_in_milli_volts);
NRF_LOG_INFO("light====%d!!!!", lux_in_milli_volts);
} }
} }
...@@ -117,6 +119,7 @@ static void app_adc_light_sensor_init(void) ...@@ -117,6 +119,7 @@ static void app_adc_light_sensor_init(void)
nrf_saadc_channel_config_t config = nrf_saadc_channel_config_t config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3); NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
err_code = nrf_drv_saadc_channel_init(0, &config); err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
...@@ -153,6 +156,10 @@ void app_adc_start_sensor_convert(void) ...@@ -153,6 +156,10 @@ void app_adc_start_sensor_convert(void)
{ {
ret_code_t err_code; ret_code_t err_code;
nrf_gpio_pin_dir_set(6, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_set(6);
//nrf_delay_ms(10);
app_adc_light_sensor_init(); app_adc_light_sensor_init();
err_code = nrf_drv_saadc_sample(); err_code = nrf_drv_saadc_sample();
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
......
...@@ -89,7 +89,7 @@ extern "C" { ...@@ -89,7 +89,7 @@ extern "C" {
.reference = NRF_SAADC_REFERENCE_INTERNAL, \ .reference = NRF_SAADC_REFERENCE_INTERNAL, \
.acq_time = NRF_SAADC_ACQTIME_10US, \ .acq_time = NRF_SAADC_ACQTIME_10US, \
.mode = NRF_SAADC_MODE_SINGLE_ENDED, \ .mode = NRF_SAADC_MODE_SINGLE_ENDED, \
.burst = NRF_SAADC_BURST_DISABLED, \ .burst = NRF_SAADC_BURST_ENABLED, \
.pin_p = (nrf_saadc_input_t)(PIN_P), \ .pin_p = (nrf_saadc_input_t)(PIN_P), \
.pin_n = NRF_SAADC_INPUT_DISABLED \ .pin_n = NRF_SAADC_INPUT_DISABLED \
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment