2018-09-20 03:23 PM
I have F303RE.
The pin config are:
The ADC config is:
The Adc init code is generated as well the Analog Gpios. That is not a problem.
I want to read one after each other.
I added a function to select to config, but I dont know what SHould I pass the rank or the channel (or both). Here is the Adc select channel or rank function.
void select_adc(uint32_t rank_or_channel)
{
ADC_ChannelConfTypeDef sConfig;
sConfig.Channel = rank_or_chammel; // ADC_CHANNEL_1;
sConfig.Rank = rank_or_chammel; // ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
And here is how do I call it.
int RORC=1; // PA0=1 PA1=2 PA2=3
while ( 1 )
{
HAL_ADC_Start(&hadc1);
select_adc(RORC );
if(HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK)
{
uint32_t av = HAL_ADC_GetValue(&hadc1);
printf("%d adc = %d \r\n",RORC, av);
}
HAL_ADC_Stop(&hadc1);
HAL_Delay(1000);
if(RORC++>3)
PIN_RANK_OR_CHANNEL=1;
}
Which way is the correct way read, one after each-other
What values in sConfig have to pinpoint the PA pin ?.
Thank you very much.
Solved! Go to Solution.
2018-09-20 08:46 PM
SOLVED
Hi,
Thank you for that channels / rank hint and the data sheet.
I relied on channel from STCBubeMx tool PA0-IN1 PA1-IN2 PA2-IN3 PC0-IN6 PC1-IN7 PC2-IN8 PC3-IN9 which is wrong. I also messed channel /rank trying things.
The correct channels on pins for 303 are:
PA0-IN2 PA1-IN3 PA2-IN4 PC0-IN7 PC1-IN8 PC2-IN9 PC3-IN1
I can read the value just fine.
uint32_t read_analogue(struct MyPinDef* pd)
{
uint32_t retval=-1;
ADC_ChannelConfTypeDef sConfig;
HAL_ADC_Start(&hadc1);
sConfig.Channel = pd->channel; //ADC_CHANNEL_1 .. 9;
sConfig.Rank = pd->rank; // pd->rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if(HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK)
{
retval = HAL_ADC_GetValue(&hadc1);
}
HAL_ADC_Stop(&hadc1);
return retval;
}
2018-09-20 03:43 PM
For multi-channel you should DMA into an array. You can trigger manually if you want, and use DMA TC as equivalent to ADC EOC signal.
Rank defines ordering in array.
Channel number defines pin, pins listed in Data Sheet, ADC123_IN8 translates to Channel 8, supported on ADC1, 2 and 3
2018-09-20 08:46 PM
SOLVED
Hi,
Thank you for that channels / rank hint and the data sheet.
I relied on channel from STCBubeMx tool PA0-IN1 PA1-IN2 PA2-IN3 PC0-IN6 PC1-IN7 PC2-IN8 PC3-IN9 which is wrong. I also messed channel /rank trying things.
The correct channels on pins for 303 are:
PA0-IN2 PA1-IN3 PA2-IN4 PC0-IN7 PC1-IN8 PC2-IN9 PC3-IN1
I can read the value just fine.
uint32_t read_analogue(struct MyPinDef* pd)
{
uint32_t retval=-1;
ADC_ChannelConfTypeDef sConfig;
HAL_ADC_Start(&hadc1);
sConfig.Channel = pd->channel; //ADC_CHANNEL_1 .. 9;
sConfig.Rank = pd->rank; // pd->rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if(HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK)
{
retval = HAL_ADC_GetValue(&hadc1);
}
HAL_ADC_Stop(&hadc1);
return retval;
}
2018-09-21 05:50 AM
You can configure one channel as regular channel and up to 4 channels as injected channels. Set up the ADC to convert first the regular, then the injected channels. Trigger conversion and read the regular and the injected results in their apropriate register.