cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Issue

dwarnke
Associate II
Posted on May 25, 2017 at 16:57

Hello,

I'm using the STM8AL Discovery board. Im trying to get the ADC working using the ST drivers. When I initialize the code Nothing shows up in the ADC registers. Below is my initialization code:

/* --- ADC --- */

// Initialize the IO

GPIO_Init(GPIOA,GPIO_Pin_6,GPIO_Mode_In_FL_No_IT);

// Initialize the ADC

ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);

ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_96Cycles);

// Enable ADC1

ADC_Cmd(ADC1, ENABLE);

// Enable ADC1 Channels 0

ADC_ChannelCmd(ADC1, ADC_Channel_0, ENABLE);

// Enable ADC Interrupt

ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

Yet none of the ADC registers are getting written with my Initialization.

Does anyone know what could be causing this? 

Regards,

Doug

#adc #stm8-discovery
6 REPLIES 6
Peter Suranyi
Associate
Posted on May 27, 2017 at 21:49

Hello! I'm just getting to know the STM8L family and I'm learning assembler programming,

but I'm trying to help. You should check that the DMA_OFF bit in the ADC_SQR1 register should be '1'.

This may cause you to see nothing in the ADC result registers. Of course, something has to be triggered by the actual conversion.

Softver have to write '1' to the START bit in the register ADC_CR1,

or select another trigger source.

Regards: Peter

must be '1'. This may cause you to see nothing in the ADC result registers. Of course, something has to be triggered by the actual conversion. Write the START bit of the register ADC_CR1 in '1' or select another trigger source.

dwarnke
Associate II
Posted on May 30, 2017 at 16:35

Thank you Peter for the reply. My follow up code attempts to set the DMA bit. The problem is I cannot write to the ADC registers. Cannot set the prescaler. Cannot turn on the AD. Cannot start the conversion. Any bit i try and set does not get set. I have tried this on 2 different stm8a-discovery boards and neither works. Its as if the ADC registers are locked.

Regards,

Szymon PANECKI
Senior III
Posted on May 31, 2017 at 22:13

Hello Doug,

Please find below the minimum code, which allows to configure one ADC channel and make an AD conversions in the loop. You can test it directly on STM8 Discovery kit. My code doesn't use EOC interrupt to indicate conversion end, but instead I use checking of EOC flag.

#include 'stm8l15x.h'

uint16_t ADC_value = 0;

main()

{

CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);

ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

ADC_Cmd(ADC1, ENABLE);

ADC_ChannelCmd(ADC1, ADC_Channel_5, ENABLE);

while (1)

{

ADC_SoftwareStartConv(ADC1);

while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)

{

}

ADC_value = ADC_GetConversionValue(ADC1);

}

}

Just in case it would be helpful, I attach also a complete project for STVD IDE.

Szymon

________________

Attachments :

stm8l_test.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hydh&d=%2Fa%2F0X0000000bAN%2FAYutSX71vbOKnU5GcDwZ0rN3r4gZtyghvy2IA1WZiPk&asPdf=false
Posted on June 02, 2017 at 19:13

Thank you for the reply Szymon. That is near the same code as I created. The problem is the registers will not write the init values. Its not just the data register not updating. None of them are. None of the CR registers. Nothing. So the code does not work because the registers are not getting written.

I am using the STM8AL Discovery board. Could the LCD connections be whats giving me my issue.
suresh kumar1
Associate
Posted on June 04, 2017 at 11:14

Go to stm8_it.c file and search for interrupt service routine(ISR) of ADC1  that u are using. In that service routine use function GETADC1CONVERSIONresult() .  Also as u are using single mode of conversation ADC will give only one value....better to use continuous mode of conversation.

Hope it will be helpful for u.

dwarnke
Associate II
Posted on June 05, 2017 at 16:37

I really appreciate all of the comments. But I think you guys are misunderstanding whats happening. Let me try and explain it like this:

ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);

I call the above function in my initialization. The CR1,2, or 3 registers DO NOT change values. It is not accepting my initialization request.

ADC_Cmd(ADC1, ENABLE);

I call the above function in my initialization. None of the registers get updated.

It is acting as if the ADC is locked and will not allow any configuration.