cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I use UART1 and ADC1 together?

VSchu.1
Associate II

Hi. I made a code that uses ADC1 in single conversion mode and UART in asynchronous mode.

But when I do the ADC1_Init() for some reason the RX interrupt of the UART doesn't work, if I don't use the ADC1 it works normally. Can someone help me?

Peripheral Settings

CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); 

GPIO_DeInit(GPIOA); // GPIOA reset

GPIO_DeInit(GPIOB); // GPIOB reset

GPIO_DeInit(GPIOC); // GPIOC reset

GPIO_DeInit(GPIOD); // GPIOD reset

GPIO_DeInit(GPIOE); // GPIOD reset

//SAIDAS

GPIO_Init(DIG1, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(DIG2, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(DIG3, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGA, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGB, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGC, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGD, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGE, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGF, GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(SEGG, GPIO_MODE_OUT_OD_LOW_SLOW);

GPIO_Init(SEGDP, GPIO_MODE_OUT_OD_LOW_SLOW);

GPIO_Init(DIGITALOUT, GPIO_MODE_OUT_PP_LOW_FAST);

//CONFIGURACAO EEPROM

FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

 

//BASE DE TEMPO 1MS TIM4

TIM4_TimeBaseInit(TIM4_PRESCALER_128, 124);

TIM4_ClearFlag(TIM4_FLAG_UPDATE);

 TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);

 TIM4_Cmd(ENABLE);

//ADC CONFIG

ADC1_DeInit();

ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, 

        ADC1_CHANNEL_4,

        ADC1_PRESSEL_FCPU_D4, 

        ADC1_EXTTRIG_TIM,DISABLE, 

ADC1_ALIGN_RIGHT, 

        ADC1_SCHMITTTRIG_ALL,DISABLE);

ADC1_ScanModeCmd(ENABLE);

ADC1_Cmd(ENABLE);*/

 //CONFIG UART1 CALIBRACAO E *****

UART1_DeInit();

UART1_Init((uint32_t)9600, 

UART1_WORDLENGTH_8D, 

UART1_STOPBITS_1, 

UART1_PARITY_NO, 

UART1_SYNCMODE_CLOCK_DISABLE, 

UART1_MODE_TXRX_ENABLE);

UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);

enableInterrupts();

RX reading (only works if ADC is not started)

 INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)

 {

 

buffer[counter] = UART1_ReceiveData8();

 counter++;

if(counter > 10)UART1_ITConfig(UART1_IT_RXNE_OR, DISABLE);

 

}

ADC input reading

ADC1_StartConversion();

while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == RESET);

voltageAverage[averageCounter] = (unsigned int)ADC1_GetBufferValue(ADC1_CHANNEL_4);

ADC1_ClearFlag(ADC1_FLAG_EOC);

Thanks

1 REPLY 1
VSchu.1
Associate II

Can solve the problem, if someone has the same problem.

The pins I'm using as serial RX and TX are the analog inputs Ain5 and Ain6, so I had to modify the following registered:

ADC1->TDRL &= 0b10011111;