STM32F103 ADC1 + DMA1 It's not working

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

STM32F103 ADC1 + DMA1 It's not working

#1 Post by Vit2 » 17 Apr 2024 19:00

Hey, everybody!
I can't figure out DMA, I've tried everything, it doesn't work. Separately Procedure MyAdcInit(); works fine, but DMA_Buffer is empty. What am I doing wrong?

Code: Select all

procedure AdcDmaInit();
begin
  //  ADC1_Init;
 MyAdcInit();
 // Delay_ms(100);
   RCC_AHBENR.B0 := 1;
  DMA1_CPAR1 := DWORD(@ADC1_DR); 
  DMA1_CMAR1 := DWORD(@DMA_Buffer[0]);
  DMA1_CNDTR1 := dword(sizeof(ADC_BUFFER_SIZE)); 

  //DMA1_CCR1 := MINC or CIRC or PSIZE0 or MSIZE0 or TCIE; 
  //DMA1_CCR1 :=  $000025A0; 

   MINC_bit := 1;
   PSIZE0_bit := 1;
   MSIZE1_bit := 1;
   CIRC_bit := 1;
   TCIE_bit := 1;
   EN_bit := 1;
end; 
  
    Procedure MyAdcInit();
begin
  // GPIOA
  RCC_APB2ENR := RCC_APB2ENR or RCC_APB2ENR.IOPAEN;

  //  GPIOA.3
  GPIOA_CRL.MODE30 := 0; //
  GPIOA_CRL.MODE31 := 0; //
  GPIOA_CRL.CNF30 := 0;  //
  GPIOA_CRL.CNF31 := 0;  //

  ADC1_CR2.TSVREFE := 1;

  RCC_APB2ENR.ADC1EN := 1;

  RCC_CFGR.ADCPRE0 := 0; //
  RCC_CFGR.ADCPRE1 := 1; //

  // 
  ADC1_CR1 := 0;
  ADC1_SQR1 := 0;

  //
  ADC1_CR2.CAL := 1;
  while (ADC1_CR2.CAL) = 0 do; //

 //  ADC1_CR2.B1 := 1;  // CONT
   ADC1_CR2.B8 := 1; //  ADC
  //(SWSTART)
  ADC1_CR2.EXTSEL0 := 1;
  ADC1_CR2.EXTSEL1 := 1;
  ADC1_CR2.EXTSEL2 := 1;
  ADC1_CR2.EXTTRIG := 1;

  // 
  ADC1_CR2.ADON := 1;
end;

  function DMAReadADC2(numb: integer): word;
begin
 ADC1_SQR3 := (numb  shl (5 * 0));
 ADC1_CR2.SWSTART := 1; // ADC
// while (ADC1_SR.EOC) = 0 do ;
  // 
  Result := {@ADC1_DR;//}@DMA_Buffer;
end;

Thank you!

AntiMember
Posts: 135
Joined: 02 Jan 2020 19:00

Re: STM32F103 ADC1 + DMA1 It's not working

#2 Post by AntiMember » 18 Apr 2024 18:06

DMA1_CNDTR1 := dword(sizeof(ADC_BUFFER_SIZE));
sizeof ADC_BUFFER_SIZE ???

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F103 ADC1 + DMA1 It's not working

#3 Post by Vit2 » 18 Apr 2024 18:11

Code: Select all

 const
  ADC_BUFFER_SIZE = 8;
var
  DMA_Buffer: array[0..ADC_BUFFER_SIZE - 1] of Word;

AntiMember
Posts: 135
Joined: 02 Jan 2020 19:00

Re: STM32F103 ADC1 + DMA1 It's not working

#4 Post by AntiMember » 19 Apr 2024 12:03

OK. Then: DMA1_CNDTR1 := dword(ADC_BUFFER_SIZE);
Or DMA1_CNDTR1 := ADC_BUFFER_SIZE;

Code: Select all

  RCC_AHBENR.DMA1EN_bit := 1;
  DMA1_CPAR1 := DWORD(@ADC1_DR); 
  DMA1_CMAR1 := DWORD(@DMA_Buffer[0]);
  DMA1_CNDTR1 := ADC_BUFFER_SIZE; 

   //DMA1_CCR1 :=  $25A0;  if DMA enable = $25A1

   DMA1_CCR1.DIR_bit := 0;
   DMA1_CCR1.PINC_bit := 0;
   DMA1_CCR1.MINC_bit := 1;
   DMA1_CCR1.PSIZE0_bit := 1;     //16bit
   DMA1_CCR1.MSIZE0_bit := 1;    //16bit
   DMA1_CCR1.CIRC_bit := 1;
   DMA1_CCR1.TCIE_bit := 1;            //interrupt must have a handler...
   DMA1_CCR1.EN_bit := 1;

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F103 ADC1 + DMA1 It's not working

#5 Post by Vit2 » 19 Apr 2024 17:34

Hi AntiMember!
It doesn't work, I don't know.
I don't need an interruption!
// PL0_bit ?

Code: Select all

procedure AdcDmaInit();
begin
 MyAdcInit();
 RCC_AHBENR.B0 := 1;
 // RCC_AHBENR := RCC_AHBENR or DMAEN1_bit;
  DMA1_CPAR1 := DWORD(@ADC1_DR);
  DMA1_CMAR1 := DWORD(@DMA_Buffer[0]);
  DMA1_CNDTR1 := ADC_BUFFER_SIZE;

   //DMA1_CCR1 :=  $25A0;  if DMA enable = $25A1
    DIR_bit := 0;
 DMA1_CCR1 := 0x000005A1;
 { // PINC_bit := 0;
   MINC_bit := 1;
   PSIZE0_bit := 1;     //16bit
   MSIZE0_bit := 1;    //16bit
   CIRC_bit := 1;
  // TCIE_bit := 1;            //interrupt must have a handler...
   EN_bit := 1;}
   end;

AntiMember
Posts: 135
Joined: 02 Jan 2020 19:00

Re: STM32F103 ADC1 + DMA1 It's not working

#6 Post by AntiMember » 19 Apr 2024 19:56

Hi, Vit2.
DMA1_CCR1.PINC_bit := 0; //peripheral increment off

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F103 ADC1 + DMA1 It's not working

#7 Post by Vit2 » 19 Apr 2024 20:03

Code: Select all

  DIR_bit := 0;
  DMA1_CCR1.PINC := 1;
  DMA1_CCR1.MINC := 1; //
  DMA1_CCR1.MSIZE0 := 1; // 
  DMA1_CCR1.PSIZE0 := 1; // 
  DMA1_CCR1.CIRC := 1; // 

  DMA1_CCR1.EN := 1; //DMA1 Channel 1
It's not working

AntiMember
Posts: 135
Joined: 02 Jan 2020 19:00

Re: STM32F103 ADC1 + DMA1 It's not working

#8 Post by AntiMember » 19 Apr 2024 20:44

Code: Select all

  RCC_AHBENR.B0 := 1;
  DMA1_CPAR1 := DWORD(@ADC1_DR);
  DMA1_CMAR1 := DWORD(@DMA_Buffer[0]);
  DMA1_CNDTR1 := ADC_BUFFER_SIZE;

   //DMA1_CCR1 :=  $25A0;  if DMA enable = $25A1

   DMA1_CCR1.B0 := 1;     //DMA enable
   DMA1_CCR1.B1 := 1;     //Int enable    interrupt must have a handler...
   DMA1_CCR1.B4 := 0;     //Direction
   DMA1_CCR1.B5 := 1;     //CIRCular
   DMA1_CCR1.B6 := 0;     //Periph. inc
   DMA1_CCR1.B7 := 1;     //Mem. inc
   DMA1_CCR1.B8 := 1;     //16bit
   DMA1_CCR1.B10 := 1;    //16bit

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F103 ADC1 + DMA1 It's not working

#9 Post by Vit2 » 20 Apr 2024 09:11

It's not working! Here's another one
ADC1_CR2.B8 := 1; ?
It doesn't make sense to me DMA1_CCR1.B1 := 1; //Int enable interrupt must have a handler...

AntiMember
Posts: 135
Joined: 02 Jan 2020 19:00

Re: STM32F103 ADC1 + DMA1 It's not working

#10 Post by AntiMember » 20 Apr 2024 13:47

ADC1_CR2.B8 := 1; ?
Yes.
It doesn't make sense to me DMA1_CCR1.B1 := 1; //Int enable interrupt must have a handler...
DMA1_CCR1.B1 := 0;
If the buffer size matches the ADC data, wait until the end of the transfer:
while (TCIF1_bit = 0) do;
Otherwise, wait for the end of the ADC conversion:
while (EOC_bit = 0) do;
delay 1mc...
The ADC works for you - they said in the first post.
That's why I didn't look at its settings.
And I'm not a representative of mikroe, if anything.

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: STM32F103 ADC1 + DMA1 It's not working

#11 Post by Vit2 » 21 Apr 2024 18:13

Thank you! I figured it out, it works now!

Post Reply

Return to “mikroPascal PRO for ARM General”