Skip to main content
Associate II
June 15, 2026
Question

Reading ADC4 on WBA25CE1

  • June 15, 2026
  • 0 replies
  • 32 views

Hi,

I modified the BLE_HeartRate example for Nucleo-WBA25CE1 by adding another channel - IN8 - to read the voltage of a solar panel. The input is between 0V and 3V because i use the divider. In CubeMX I added an additional channel IN8 and generated the code. In the code I define the handle for ADCCTRL:

ADCCTRL_Handle_t LLVoltageRequest_Handle =
{
.Uid = 0x00,
.State = ADCCTRL_HANDLE_NOT_REG,
.InitConf =
{
.ConvParams =
{
.TriggerFrequencyMode = LL_ADC_TRIGGER_FREQ_LOW,
.Resolution = LL_ADC_RESOLUTION_12B,
.DataAlign = LL_ADC_DATA_ALIGN_RIGHT,
.TriggerStart = LL_ADC_REG_TRIG_SOFTWARE,
.TriggerEdge = LL_ADC_REG_TRIG_EXT_RISING,
.ConversionMode = LL_ADC_REG_CONV_SINGLE,
.DmaTransfer = LL_ADC_REG_DMA_TRANSFER_NONE,
.Overrun = LL_ADC_REG_OVR_DATA_OVERWRITTEN,
.SamplingTimeCommon1 = LL_ADC_SAMPLINGTIME_814CYCLES_5,
.SamplingTimeCommon2 = LL_ADC_SAMPLINGTIME_1CYCLE_5
},
.SeqParams =
{
.Setup = LL_ADC_REG_SEQ_CONFIGURABLE,
.Length = LL_ADC_REG_SEQ_SCAN_DISABLE,
.DiscMode = LL_ADC_REG_SEQ_DISCONT_DISABLE
},
.LowPowerParams =
{
.AutoPowerOff = DISABLE,
.AutonomousDPD = LL_ADC_LP_AUTONOMOUS_DPD_DISABLE
}
},
.ChannelConf =
{
.Channel = LL_ADC_CHANNEL_8,
.Rank = LL_ADC_REG_RANK_1,
.SamplingTime = LL_ADC_SAMPLINGTIME_COMMON_1
}
};

I register the handle and read the ADC4 in the task triggered by the WakeUp timer.

void Task_AdcSample(void)
{
LOG_INFO_APP("\r\nADC Sample\r\n");

uint16_t raw = 0;
ADCCTRL_Cmd_Status_t ret;

/* Enter limited critical section : disable all the interrupts with priority higher than RCC one
* Concerns link layer interrupts (high and SW low) or any other high priority user system interrupt
*/
UTILS_ENTER_LIMITED_CRITICAL_SECTION(RCC_INTR_PRIO<<4);

/* Turn ADC on */
ret = ADCCTRL_RequestIpState(&LLVoltageRequest_Handle, ADC_ON);
if (ret != ADCCTRL_OK)
{
LOG_INFO_APP("ADC ON failed: %d\r\n", ret);
return;
}

/* Read raw value */
ret = ADCCTRL_RequestRawValue(&LLVoltageRequest_Handle, &raw);
if (ret != ADCCTRL_OK)
{
LOG_INFO_APP("ADC read failed: %d\r\n", ret);
}
else
{
LOG_INFO_APP("ADC4 raw = %u\r\n", raw);
}

/* Turn ADC off — release back to BLE stack */
ADCCTRL_RequestIpState(&LLVoltageRequest_Handle, ADC_OFF);

/* Exit limited critical section */
UTILS_EXIT_LIMITED_CRITICAL_SECTION();

LOG_INFO_APP("ADC4 raw = %u\r\n", raw);
uint32_t voltage_mv = (uint32_t)(raw * 3300 * 2) / 4095;
LOG_INFO_APP("ADC4 raw=%u voltage=%lu.%03lu V\r\n",
raw,
voltage_mv / 1000,
voltage_mv % 1000);
}

I keep getting the same value irrespective if i connect the solar panel or if i connect PA1 to GND:

ADC4 raw=301 voltage=0.485 V

I can read the temperature channel and get values around 960.

I wonder if it is possible to concurrently read external channel and have the internal temperature channel for BLE Stack.