2017-05-25 07:57 AM
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 IOGPIO_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-discovery2017-05-27 12:49 PM
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: Petermust 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.
2017-05-30 07:35 AM
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,
2017-05-31 01:13 PM
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=false2017-06-02 12:13 PM
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.2017-06-04 02:14 AM
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.
2017-06-05 07:37 AM
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.