- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am working on a project to read a voltage from GPIO pin (e.g. P10_0) and send the ADC data with BLE link to a cellphone. This project is based on:
PSoC 6
ModusToolbox
cyhal_adc library
I started with “BLE Battery Level FreeRTOS” example code.
In main.c, I added the following code to start adc
...
/*Initialize GPIO Pin*/
cyhal_gpio_init((cyhal_gpio_t)P10_0, CYHAL_GPIO_DIR_INPUT,
CYHAL_GPIO_DRIVE_PULLDOWN, 1U);
/* Turn on the ADC for the specified pin */
cyhal_adc_t adc;
cyhal_adc_channel_t channel;
cy_rslt_t m_result =cyhal_adc_init( &adc, (cyhal_gpio_t)P10_0, (cyhal_clock_divider_t*)NULL );
cyhal_adc_channel_init( &channel, &adc, (cyhal_gpio_t)P10_0 );
if (CY_RSLT_SUCCESS == m_result){
cyhal_gpio_write((cyhal_gpio_t)CYBSP_USER_LED2, CYBSP_LED_STATE_ON);
}
......
m_result is to check if adc initialization is successful. It is NOT. I am wondering if I missed something before these codes? Any help would be greatly appreciated.
Ping
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You don't need to call gpio_init() on P10_0. That's handle internally by the adc_init() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You don't need to call gpio_init() on P10_0. That's handle internally by the adc_init() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the advice. I did some debugging into “cyhal_adc.c”. It seems that ADC channel enabling failed at:
cyhal_resource_inst_t pinRsc = cyhal_utils_get_gpio_resource(pin);
if (CY_RSLT_SUCCESS != (result = cyhal_hwmgr_reserve(&pinRsc))){
return result;
}
I do not know where to set “pinRsc” within ModusToolbox. I think this may be the cause of the ADC reading failed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's because you have called the gpio_Init on P10_0. It allocates this pin, so you can't use for other things, like the an ADC input.
The CYHAL uses a hardware manager for allocating peripherals, pins and clocks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many Thanks!
You are right: I deleted gpio_Init on P10_0 and also cleaned settings in “Device Configuration”. It is working now 🙂