Connect Temperature Sensor in ADC VAL 1

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
3 posts / 0 new
Last post
advanchip@pacbe...
Offline
Last seen:3年8个月前
加入:2017-05-10 23:35
Connect Temperature Sensor in ADC VAL 1

I am using DA14585-00ATDEVKT-P Development Kit - Pro with DA14585_SDK 6.0.2.243 and Keil uVersion V5.23.0.0.

I am following Pillar 3 (peripheral) example to connect a temperature sensor into ADC to read temperature.

1)线63 of user_periph_setup.c: void periph_init(void)
At the end of this function, I added
adc_init(GP_ADC_SE, 0, GP_ADC_ATTN3X );
adc_enable_channel(0);

2) line 48 of user_periph_setup.c: void set_pad_functions(void)
At the end of this function, I added
GPIO_ConfigurePin(GPIO_ADC_PORT, GPIO_ADC_PIN, INPUT, PID_ADC, false);

3) after line 142 of user_periph_setup.h
I added
/****************************************************************************************/
/* ADC configuration */
/****************************************************************************************/

#if HW_CONFIG_BASIC_DK
#define GPIO_ADC_PORT GPIO_PORT_0
#define GPIO_ADC_PIN GPIO_PIN_0

#elif HW_CONFIG_PRO_DK
#define GPIO_ADC_PORT GPIO_PORT_0
#define GPIO_ADC_PIN GPIO_PIN_0

#elif HW_CONFIG_EXPERT_DK
#define GPIO_ADC_PORT GPIO_PORT_0
#define GPIO_ADC_PIN GPIO_PIN_0

#else // (other configuration)
# endif

4) At line 153 of user_custs1_impl.c, I commented out
//sample = (sample <= 0xffff) ? (sample + 1) : 0; and added
sample = adc_get_sample();

When executed the line on above 2) GPIO_ConfigurePin(GPIO_ADC_PORT, GPIO_ADC_PIN, INPUT, PID_ADC, false);
It stopped at gpio.c line 201:
#if DEVELOPMENT_DEBUG
#ifndef GPIO_DRV_PIN_ALLOC_MON_DISABLED
if ( !(GPIO_status & ( ((uint64_t)1 << pin) << (port * 16) )) )
__asm("BKPT #0\n"); // this pin has not been previously reserved!
# endif//GPIO_DRV_PIN_ALLOC_MON_DISABLED
# endif//DEVELOPMENT_DEBUG

Please guide me how to use ADC to read data from a real device instead of generated data.

Thanks

Keywords:
Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2015-06-08 11:34
Hi advanchip,

Hi advanchip,

The reason you get the error is because you dont reserve the pin before using it. In the user_periph_setup.c file before the set_pad_functions() implementation there is an additional function named GPIO_reservations(), in that function you should reserve each pin that you are using before actually use it, if you dont do that and while you are in development mode the assertion that you ve posted will occur. So if you just add the RESEVE_GPIO(ADC_PIN, GPIO_ADC_PORT, GPIO_ADC_PIN, PID_ADC) you will not get the assertion. Regarding how to use the ADC functions, i would recommend to follow the example in the peripheral_examples\adc\bat_lvl and perform the adc_init() and adc_enable_channel() just before reading the actual value, also please apply the corresponding delays in the given example (only if you use the 3 X attenuator you will need he extra 1us delay during the sampling phase). Also please use the adc_calibrate() before using the ADC and you should also recalibrate if sleep mode is used.

Thanks MT_Dialog

advanchip@pacbe...
Offline
Last seen:3年8个月前
加入:2017-05-10 23:35
Thanks.

Thanks.