Initializing ADC causes LCD to not display anything

I have been having some trouble getting my ADC to work so I have decided to give it a try by manipulating the registers. I have a textbook which outlines the steps and I think I have it finished, but I can't get it to output anything since the LCD display won't print anything.

The board is an STM32L476 Discovery with a built-in ADC

Here is the code:

char lcd_buffer[6];    // LCD display buffer
__IO uint32_t measuredValue;

int main(void)
{

//int n;
//UART2_Init();
//n = sprintf((char *)buffer, "%.2f ", measuredReading);
//USART_Write(USART2, buffer, n);

HAL_Init();
SystemClock_Config();
HAL_InitTick(0x0000); // set systick's priority to the highest.
BSP_LED_Init(LED4);
BSP_LED_Init(LED5);
BSP_LCD_GLASS_Init();

RCC->CR &= ~(0x1 << 10);
// Turn on HSI
RCC->CR |= (1 << 8);
// Wait for it to be ready
while (!(RCC->CR & (0x1 << 10))) {}

// Enable clock for GPIOC
RCC->AHB2ENR |= 0x1 << 2;
// Reset port mode, while setting PIN 0 as analog input (0b11)
GPIOC->MODER = 0xFFFFFFFF;
// Reset PUPD register, while setting PIN 0 as NOPUSHPULL (0b00)
GPIOC->PUPDR = 0x00000000;

// Turn on the ADC clock
RCC->AHB2ENR |= 0x1 << 13;
// Set length of regular channel to 1 (0b0000)
// Set channel 10 as the 1st conversion in regular sequence
ADC1->SQR1 = (ADC1->SQR1 & ~(63<<6)) | ( 10 << 6 & 63 << 6); //setting SQ1 to channel 10. 0b111111 (63) << 6 is the mask.
// Configure the sample time register for channel 10
// Enable end of conversion interrupt
// Enable continuous conversion mode
// Configure delay selection as delayed until the converted data have been read

// Enable and configure the interrupt handler for ADC1

// Configure alignment and resolution
ADC1->CFGR &= ~( 0x1 << 5 ); // right alignment
ADC1->CFGR &= ~( 0x3 << 3 ); // 12 bit resolution

// Starts conversion.

// prints output data register
sprintf(lcd_buffer,"%d",measuredValue);
BSP_LCD_GLASS_Clear();
BSP_LCD_GLASS_DisplayString((uint8_t*)lcd_buffer);

while (1)
{
BSP_LED_On(LED5);
}
}


Just before the dead loop, I try to display the value from the data register, but the LCD displays nothing. If I move those four lines to just after the LCD init function and disable the ADC code it works fine. When I run the ADC code it disables the LCD for some reason.

The program does reach the dead loop, since LED5 turns on.

• It might be helpful if you specified what microcontroller you're using, and if it's not a built-in ADC, the ADC as well. – Hearth Jan 24 at 21:31
• what happens if you comment out all the ADC code? – jsotola Jan 24 at 21:40
• @Hearth The board is an STM32L476 Discovery with a built-in ADC – Alexander Jan 24 at 22:00
• @jstola Oh, when I moved the four lines, I also brought the while loop, so the ADC code was never run. – Alexander Jan 24 at 22:01
• @jstola I just tried to print to the LCD, then run the ADC code and it does not work. The ADC code must be disabling the LCD for some reason. – Alexander Jan 24 at 22:04