STM32F103R8 is teasing with its ADC.

mikroC, mikroBasic and mikroPascal for PRO ARM® MCUs, supporting STM32, Tiva, Kinetis, & CEC devices
Post Reply
Author
Message
Malmir
Posts: 23
Joined: 11 Jan 2016 23:00
Location: Copenhagen Denmark

STM32F103R8 is teasing with its ADC.

#1 Post by Malmir » 25 May 2018 13:18

Hi.
I have tryed almost everything (almost, cause I missed get it working), but my chip is laughting at me and will not show the ADC result on a display. I have read RM0008 Reference Manual many times. I have tryed to see examples from Libstock and results from ST Cube, but still cannot guess what it is I am missing.
I wish to run ADC 1 channel 0 alone as a single channel continious run, with interrupt support. But I am lost now.
Any clus any one ?+?
Sincerely
Klavs

Code: Select all

#include  "ddb_mkii_global.h"
#include  "ddb_mkii_local.h"

void  Initiate_IO(void)
{
  RCC_CR       = 0x01010000;
  do
  {
  }
  while (!RCC_CR.B17);
  RCC_CFGR     = 0x001D8402;
  do
  {
  }
  while (!RCC_CR.B25);
  RCC_AHBENR   = 0x00000017;
  RCC_APB1ENR  = 0x10000005;
  RCC_APB2ENR  = 0x00000FFD;
  ADC1_SR      = 0x00000000;
  ADC1_CR1     = 0x00000020;
  ADC1_CR2     = 0x000E7003;
  ADC1_SMPR1   = 0x00000000;
  ADC1_SMPR2   = 0x00000000;
  ADC1_HTR     = 0x00000C00;
  ADC1_LTR     = 0x00000008;
  ADC1_SQR1    = 0x00000000;
  ADC1_SQR2    = 0x00000000;
  ADC1_SQR3    = 0x00000000;
  AFIO_MAPR    = 0x02000000;
  AFIO_EXTICR1 = 0x00000000;
  AFIO_EXTICR2 = 0x00000000;
  AFIO_EXTICR3 = 0x00000000;
  AFIO_EXTICR4 = 0x00000000;
  EXTI_IMR     = 0x000001F8;
  EXTI_EMR     = 0x00000000;
  EXTI_RTSR    = 0x000001F8;
  EXTI_FTSR    = 0x000001F8;
  GPIOA_CRL    = 0x88888800;
  GPIOA_CRH    = 0x88888888;
  GPIOA_ODR    = 0x00000180;
  GPIOB_CRL    = 0x11144111;
  GPIOB_CRH    = 0x11114411;
  GPIOC_CRL    = 0x44004422;
  GPIOC_CRH    = 0x11411444;
  NVIC_IntEnable(IVT_INT_RCC);
  NVIC_IntEnable(IVT_INT_EXTI3);
  NVIC_IntEnable(IVT_INT_EXTI4);
  NVIC_IntEnable(IVT_INT_EXTI9_5);
  NVIC_IntEnable(IVT_INT_ADC1_2);
}

void  Extern_Interrupt_3(void) iv IVT_INT_EXTI3
{
  if((EXTI_PR & 0x00000008) != 0)
  {
    if (GPIOA_IDR.B3 == 1)
    {
      End = 1;
      Select = 1;
    }
    if ((GPIOA_IDR.B3 == 0) && (GPIOA_IDR.B4 == 0) &&
        (GPIOA_IDR.B5 == 0) && (GPIOA_IDR.B6 == 0))
    {
      End    = 1;
      Select = 2;
    }
    EXTI_PR |= 0x00000008;
  }
}

void  Extern_Interrupt_4(void) iv IVT_INT_EXTI4
{
  if((EXTI_PR & 0x00000010) != 0)
  {
    if (GPIOA_IDR.B4 == 1)
    {
      End    = 1;
      Select = 4;
    }
    if ((GPIOA_IDR.B3 == 0) && (GPIOA_IDR.B4 == 0) &&
        (GPIOA_IDR.B5 == 0) && (GPIOA_IDR.B6 == 0))
    {
      End    = 1;
      Select = 2;
    }
    EXTI_PR |= 0x00000010;
  }
}

void  Extern_Interrupt_9_5(void) iv IVT_INT_EXTI9_5
{
  if((EXTI_PR & 0x00000020) != 0)
  {
    if (GPIOA_IDR.B5 == 1)
    {
      End    = 1;
      Select = 6;
    }
    EXTI_PR |= 0x00000020;
  }

  if((EXTI_PR & 0x00000040) != 0)
  {
    if (GPIOA_IDR.B6 == 1)
    {
      End    = 1;
      Select = 3;
    }
    EXTI_PR |= 0x00000040;
  }

  if ((GPIOA_IDR.B3 == 0) && (GPIOA_IDR.B4 == 0) &&
      (GPIOA_IDR.B5 == 0) && (GPIOA_IDR.B6 == 0))
  {
    End    = 1;
    Select = 2;
  }
}

void  ADC_Interrupt(void) iv IVT_INT_ADC1_2
{
  Bar_Read = ADC1_DR & 0x0FFF;
  ADC_DONE = 1;
}

//Timer2 Prescaler :119; Preload = 59999; Actual Interrupt Time = 100 ms
//Place/Copy this part in declaration section
void  Initiate_Timer2(void)
{
  TIM2_CR1 = 0x0080;
  TIM2_PSC = 7200;
  TIM2_ARR = 999;
  NVIC_IntEnable(IVT_INT_TIM2);
  TIM2_DIER = 0x0001;
  TIM2_SR.UIF = 0;
}

void  Timer2_interrupt(void) iv IVT_INT_TIM2
{
  if(Venting_Clock)
    Venting_Clock--;
  else
    TIM2_CR1.CEN = 0;
  TIM2_SR.UIF = 0;
}

//Timer6 Prescaler : 10; Preload = 7199; Actual Interrupt Time = 1ms
//Place/Copy this part in declaration section
void  Initiate_Timer4(void)
{
  TIM4_CR1  = 0x0080;
  TIM4_PSC  = 10;
  TIM4_ARR  = 7199;
  NVIC_IntEnable(IVT_INT_TIM4);
  TIM4_DIER = 0x0001;
  TIM4_SR.UIF = 0;
}

void  Timer4_interrupt(void) iv IVT_INT_TIM4
{
  if (Digit == 0)
  {
    Bar_Temp = (unsigned int)((Bar_Read * Scale));
    Bar_Read_Digit[3] = Bar_Temp % 10;
    Bar_Temp = (unsigned int)(Bar_Temp / 10);
    Bar_Read_Digit[2] = Bar_Temp % 10;
    Bar_Temp = (unsigned int)(Bar_Temp / 10);
    Bar_Read_Digit[1] = Bar_Temp % 10;
    Bar_Temp = (unsigned int)(Bar_Temp / 10);
    Bar_Read_Digit[0] = Bar_Temp % 10;

    if (Locked == 0)
    {
      Locked_Pressure = Bar_Read;
      Bar_Read_Digit[4] = Bar_Read_Digit[0];
      Bar_Read_Digit[5] = Bar_Read_Digit[1];
      Bar_Read_Digit[6] = Bar_Read_Digit[2];
      Bar_Read_Digit[7] = Bar_Read_Digit[3];
    }
    else
    {
      Bar_Temp = Locked_Pressure;
      Bar_Read_Digit[7] = Bar_Temp % 10;
      Bar_Temp = (unsigned int)(Bar_Temp / 10);
      Bar_Read_Digit[6] = Bar_Temp % 10;
      Bar_Temp = (unsigned int)(Bar_Temp / 10);
      Bar_Read_Digit[5] = Bar_Temp % 10;
      Bar_Temp = (unsigned int)(Bar_Temp / 10);
      Bar_Read_Digit[4] = Bar_Temp % 10;
    }
  }
  GPIOB_BSRR = 0xF3FF0000;
  GPIOC_BSRR = 0xF8000000;
  GPIOB_BSRR = Display_Digit[Digit][0];
  GPIOC_BSRR = Display_Digit[Digit][1];
  GPIOB_BSRR = Display_Number[Bar_Read_Digit[Digit]][0];
  GPIOC_BSRR = Display_Number[Bar_Read_Digit[Digit]][1];
  Digit++;
  if (Digit == 8) Digit = 0;

  TIM4_SR.UIF = 0;
}

void  Introduce(void)
{
  unsigned short  Ciffer = 0;
  
  Venting_Clock = 50;
  TIM2_CR1.CEN = 1;
  do
  {
    GPIOB_BSRR = 0xF3FF0000;
    GPIOC_BSRR = 0xF8000000;
    GPIOB_BSRR = Display_Intro[Ciffer][0];
    GPIOC_BSRR = Display_Intro[Ciffer][1];
    Ciffer++;
    if (Ciffer == 8) Ciffer = 0;
    Delay_ms(2);
  }
  while (Venting_Clock);
  GPIOB_BSRR = 0xF3FF0000;
  GPIOC_BSRR = 0xF8000000;
}

void  main(void)
{
  Initiate_IO();
  Initiate_Timer2();
  Initiate_Timer4();
  EnableInterrupts();
  Introduce();
  ADC1_CR2.B0  = 1;
  Delay_ms(1);
  ADC1_CR2.B0  = 1;
  TIM4_CR1.CEN = 1;

  do
  {
    switch (Select)
    {
      case 1  : Prefill();
                break;
      case 2  : Opening();
                break;
      case 3  : Leak();
                break;
      case 4  : Venting();
                break;
      case 5  : Seal();
                break;
      case 6  : Atomise();
                break;
      default : Prefill();
    }
  }
  while (1);
}

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: STM32F103R8 is teasing with its ADC.

#2 Post by petar.suknjaja » 29 May 2018 16:24

Hi,

As you probably know, there isn't any ADC code example for F103R8,
I'll review the code you posted and try to resolve this issue.

Kind regards,
Petar

Malmir
Posts: 23
Joined: 11 Jan 2016 23:00
Location: Copenhagen Denmark

Re: STM32F103R8 is teasing with its ADC.

#3 Post by Malmir » 07 Aug 2018 14:17

This is solved by one from LibStock. Actually it turned out that some initialisation was deeply wrong.

Case closed :D.

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: STM32F103R8 is teasing with its ADC.

#4 Post by petar.suknjaja » 08 Aug 2018 14:03

Hi,
Thank you for letting us know.
Kind regards,
Petar

Post Reply

Return to “ARM PRO Compilers”