cancel
Showing results for 
Search instead for 
Did you mean: 

Help using the ADC

ivancolla9
Associate III
Posted on January 29, 2016 at 16:16

Good morning,

I am trying to activate and use tha A/D converter. After activating the peripheral, I proceed to set the register in this way:

ADC0.NCMR0.R = 0b00000000000000001111111111111111; /* Enable all conversion channel for test.*/
ULONG OWREN_MASK = 1 << 31; /* Enable conversion data to be overwritten. */
ULONG WLSIDE_MASK = 1 << 30; /* Conversion data written right-aligned. */
ULONG MODE_MASK = 1 << 29; /* Continuous scan conversion. */
ULONG START_MASK = 1 << 24; /* Start conversion on enabled channels. */
ADC0.MCR.R = OWREN_MASK | WLSIDE_MASK | MODE_MASK | START_MASK;

when I execute the code on the discovery board, I wait for a valid data on one of the channels.

if (ADC0.CDR0.B.VALID == 1)

Following discovery-board manual, the AD0 port (B7), is accessible via pin A26 of the connector. I connect to that pin a 5 V voltage, expecting to read something. The problem is that I don't read anything. Monitoring the all the CDRn registers, I see that neither of them has a new convertion valued stored: tha data field is 0 and the VALID field is 0. What am I missing? Regards, Ivan #discovery #adc #board
1 ACCEPTED SOLUTION

Accepted Solutions
ivancolla9
Associate III
Posted on February 01, 2016 at 17:25

Hello Erwan,

I discovered the issue and it was more simple that I belevied. It was necessary separate the configuration registry input to the start register input. To be clear, I changed

ADC0.MCR.R = OWREN_MASK | WLSIDE_MASK | MODE_MASK | START_MASK;

with

ADC0.MCR.R = OWREN_MASK | WLSIDE_MASK | MODE_MASK;
ADC0.MCR.R = ADC0.MCR.R | START_MASK;

As you can see, first I configure the MCR registry, than I give the start settin to 1 the NSTART bit field (using the mask). Doing so, the channel configured are activated and I can read the input vlaue of the ADC. Regards, Ivan

View solution in original post

2 REPLIES 2
Erwan YVIN
ST Employee
Posted on February 01, 2016 at 15:42

Hello Ivan ,

Did you solve your issue ? you should receive EOC Interrupt (end Of Conversion)

IRQ_HANDLER(SPC5_ADC1_EOC_HANDLER) {

Best regards Erwan
ivancolla9
Associate III
Posted on February 01, 2016 at 17:25

Hello Erwan,

I discovered the issue and it was more simple that I belevied. It was necessary separate the configuration registry input to the start register input. To be clear, I changed

ADC0.MCR.R = OWREN_MASK | WLSIDE_MASK | MODE_MASK | START_MASK;

with

ADC0.MCR.R = OWREN_MASK | WLSIDE_MASK | MODE_MASK;
ADC0.MCR.R = ADC0.MCR.R | START_MASK;

As you can see, first I configure the MCR registry, than I give the start settin to 1 the NSTART bit field (using the mask). Doing so, the channel configured are activated and I can read the input vlaue of the ADC. Regards, Ivan