3376 views|4 replies

256

Posts

0

Resources
The OP
 

Please help me with the problem of unsuccessful ADC reading after using BLE_SensorDemo modification on STEVAL-IDB007V1 [Copy link]

 This post was last edited by viphotman on 2018-1-26 19:13 I just added the function of reading ADC using BLE_SensorDemo under keil, but the read value is 0; The app uses iOS :lightblue android:nRF Connect program based on BLE_SensorDemo, refer to the use of ADC in the project Project\BlueNRG1_Periph_Examples\ADC\Polling; 1 Add #include "BlueNRG1_adc.h" // RK ADD to the file BlueNRG1_conf.h 2 Define functions and data
  1. ADC_InitType xADC_InitType; void ADC_Configuration(void) { SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_ADC, ENABLE); /* Configure ADC */ /* ADC_Input_AdcPin1 == ADC1 */ /* ADC_Input_AdcPin2 == ADC2 */ /* ADC_Input_AdcPin12 == ADC1 - ADC2 */ xADC_InitType.ADC_OSR = ADC_OSR_200; //ADC_Input_BattSensor; //ADC_Input_TempSensor;// ADC_Input_AdcPin1 // ADC_Input_AdcPin12 // ADC_Input_AdcPin2 xADC_InitType.ADC_Input = ADC_Input_AdcPin12; //ADC_Input_AdcPin12; xADC_InitType.ADC_ConversionMode = ADC_ConversionMode_Single; xADC_InitType.ADC_ReferenceVoltage = ADC_ReferenceVoltage_0V6; xADC_InitType.ADC_Attenuation = ADC_Attenuation_9dB54; ADC_Init(&xADC_InitType); /* Enable auto offset correction */ ADC_Calibration(ENABLE); ADC_AutoOffsetUpdate(ENABLE); }
复制代码
3 Call ADC related setting functions in the main() function
  1. /* ADC Initialization */ ADC_Configuration(); /* Start new conversion */ ADC_Cmd(ENABLE);
复制代码
4 Read ADC value in while(1) in main(); if( ADC_GetFlagStatus(ADC_FLAG_EOC)) { /* Read converted data */ adc_value = ADC_GetConvertedData(xADC_InitType.ADC_Input, xADC_InitType.ADC_ReferenceVoltage); //SdkDelayMs(100); adc_value = adc_value/1000; Clock_Wait(100); //adc_value = 0x2345; //Use this to directly transfer to the App; ADC_Cmd(ENABLE); } 5 Transfer the value of adc_value to the App. Here, I modify the data transfer function of the 3D sensor to transfer the value of adc_value, and then use the App to read the value;
  1. extern float adc_value; tBleStatus Acc_Update(AxesRaw_t *data) { uint8_t buff[6]; tBleStatus ret; HOST_TO_LE_16(buff,-data->AXIS_Y); HOST_TO_LE_16(buff+2,data->AXIS_X); HOST_TO_LE_16(buff+4,-data->AXIS_Z); //adc_value buff[0]= 0xfe; buff[1]= 0xff; buff[2]= 0xff; buff[3]= 0xfe; buff[4]= adc_value/256; buff[5]= adc_value; ret = aci_gatt_update_char_value(accServHandle, accCharHandle, 0, 6, buff); if (ret != BLE_STATUS_SUCCESS){ PRINTF("Error while updating Acceleration characteristic: 0x%02X\n",ret) ; return BLE_STATUS_ERROR ; } return BLE_STATUS_SUCCESS; }
复制代码
6 The result shows that the ADC value is always 0. I haven't found the problem yet. I would like to ask for help online.


This post is from ST - Low Power RF

Latest reply

Is the code stuck somewhere or does ADC_GetFlagStatus(ADC_FLAG_EOC) always return 0?  Details Published on 2018-1-27 18:30
 
 

9721

Posts

24

Resources
2
 
1. Make sure AdcPin12 has voltage input. 2. Try to read the voltage by running ADC\Polling. 3. Then check the value of adc_value in debug mode in the BLE_SensorDemo code you modified to see if it is correct. 4. If ADC\Polling is normal but BLE_SensorDemo is not normal, compare the differences between the two routines in ADC configuration and reading.

This post is from ST - Low Power RF

Comments

I just added UART DEBUG log, and found that if I only print the ADC value when reading ADC, I can only see it printed once; the code is as follows, [mw_shl_code=c,true]if( ADC_GetFlagStatus(ADC_FLAG_EOC)) { /* Read converted data */ adc_value =  Details Published on 2018-1-27 17:29
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

256

Posts

0

Resources
3
 
littleshrimp posted on 2018-1-26 19:41 1. Make sure AdcPin12 has voltage input 2. You can try to read it by downloading an ADC\Polling first 3. Then in the BLE_SensorDemo you modified ...
I just added UART DEBUG log, and found that if you only print the ADC value when reading the ADC, you can only see it printed once; the code is as follows,
  1. if( ADC_GetFlagStatus(ADC_FLAG_EOC)) { /* Read converted data */ adc_value = ADC_GetConvertedData(xADC_InitType.ADC_Input, xADC_InitType.ADC_ReferenceVoltage); PRINTF("ADC value: %.0f mV\r\n", adc_value*1000.0); //uart log adc_value = adc_value*1000.0; Clock_Wait(100); ADC_Cmd(ENABLE); timeRun++; }
复制代码
But if you add a print message in the main loop, you can keep running.
  1. /* Application Tick */ APP_Tick(); PRINTF("BlueNRG-1 BLE Sensor Demo APP_Tick() TIME=%d \n",timeRun);
复制代码
At present, I have used this to test it, and the APP can read the data. I also tested it with a capacitor. I disconnected the JP1 and JP2 lines of the STEVAL-IDB007V1 development board, connected the negative pole of the supercapacitor (this capacitor is provided by the forum) to the 3rd pin of JP1, charged the positive pole to 3.3V through the 1st pin of JP1, and then switched the positive pole to the 2nd pin of JP2. After a preliminary test, the power consumption was very fast. It may be that the LED was not turned off, and other IOs were not configured. I will optimize it later.
This post is from ST - Low Power RF

Comments

Is the code stuck somewhere or does ADC_GetFlagStatus(ADC_FLAG_EOC) always return 0?  Details Published on 2018-1-27 18:30
 
 
 

9721

Posts

24

Resources
4
 
viphotman posted on 2018-1-27 17:29 I have just added UART DEBUG log, and found that if I only print the ADC value when reading ADC, I can only see it printed once; the code is as follows, [mw_shl_code ...
Is the code stuck somewhere or does ADC_GetFlagStatus(ADC_FLAG_EOC) always return 0?
This post is from ST - Low Power RF

Comments

When testing at that time, the ADC value was only printed once after reset, such as ADC_GetFlagStatus(ADC_FLAG_EOC) always returned 0, but now I have modified some codes and there is no problem. The specific reason is still being found;  Details Published on 2018-1-29 10:32
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

256

Posts

0

Resources
5
 
littleshrimp posted on 2018-1-27 18:30 Is the code stuck somewhere or does ADC_GetFlagStatus(ADC_FLAG_EOC) always return 0?
When testing at that time, the ADC value was only printed once after reset, and ADC_GetFlagStatus(ADC_FLAG_EOC) always returned 0, but now I have modified some code and there is no problem. The specific reason is still being found;
This post is from ST - Low Power RF
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list