LPC17xx ADC werte mit DMA in ein Feld kopieren

Gast #3271616
Lesenswert?

Hallo Leute,

ich versuche den DMA Kontroller dazu zu bewegen die ADC Werte  des 
Channel 0 in ein Feld zu schreiben.
Leider versteh ich das UM anscheinend nicht richtig. :( Das Beispiel von 
NXP ‚ADCDMA‘ hab ich mir  angeschaut, es bringt mich auch nicht wirklich 
weiter.

Mein Vorgehen.
ADC so konfigurieren, dass es im Burst Mode immer ein Interrupt auslöst 
wenn es fertig ist.
Daraufhin soll das DMA den neuen Wert in das Feld zu schreiben und die 
Zieladresse um 1 zu erhöhen.
Nach 32 Durchläufen soll es stoppen. Das funktioniert!
Aber die ADC Werte werden anscheinend nicht richtig gelesen.
Wo ist mein Fehler?

Gruß
Alex
1
#ifdef __USE_CMSIS
2
#include "LPC17xx.h"
3
#endif
4

5
#include <cr_section_macros.h>
6
#include <NXP/crp.h>
7

8
volatile int arrADC[40];
9

10
// Variable to store CRP value in. Will be placed automatically
11
// by the linker when "Enable Code Read Protect" selected.
12
// See crp.h header for more information
13
__CRP extern const unsigned int CRP_WORD = CRP_NO_CRP ;
14

15
void adcInit(){
16
   /* Enable CLOCK into ADC controller */
17
  LPC_SC->PCONP |= (1 << 12);
18

19
  /* all the related pins are set to ADC inputs, AD0.0~7 */
20
  LPC_PINCON->PINSEL1 &= ~0x003FC000;  /* P0.23~26, A0.0~3, function 01 */
21
  LPC_PINCON->PINSEL1 |= (1<<14); //p0.23 adc
22
  /* No pull-up no pull-down (function 10) on these ADC pins. */
23
  LPC_PINCON->PINMODE1 &= ~0x003FC000;
24
  LPC_PINCON->PINMODE1 |= (1<<15);
25

26
  LPC_ADC->ADINTEN = 1;
27

28
  LPC_ADC->ADCR = ( 0x01 << 0 ) | ( 15 << 8 ) | ( 1 << 16 ) | ( 1 << 21 );
29

30
  /* ADC Interrupt is needed, but NVIC is not necessary for ADC DMA. */
31
  NVIC_DisableIRQ(ADC_IRQn);
32

33
}
34

35
void dmaInit(){
36
  LPC_SC->PCONP |= (1<<29);
37
//DMA Controller enable
38
  LPC_GPDMA->DMACConfig = 1;
39

40
  LPC_GPDMA->DMACIntTCClear = 0xff;
41

42
  LPC_GPDMA->DMACIntErrClr = 0xff;
43
}
44

45
void dmaChanInit(){
46
  LPC_GPDMACH0->DMACCConfig = 0;
47
  LPC_GPDMACH0->DMACCControl = 0;
48

49
  LPC_GPDMACH0->DMACCSrcAddr = 0x40034010; //AD0DR0
50
  LPC_GPDMACH0->DMACCDestAddr =  (int ) arrADC;
51
  LPC_GPDMACH0->DMACCLLI = 0x40034010; //AD0DR0
52

53
  LPC_GPDMACH0->DMACCControl = (0x20 << 0)| (0x2 << 12)|(0x2 << 12)|(0x2 << 18)|(0x2 << 21)|(1<<27);
54
  LPC_GPDMACH0->DMACCConfig = (1<<0)|(0x4 << 1)|(0x00 <<6)|(0x2 << 11);
55
}
56

57

58
int main(void) {
59
  adcInit();
60
  dmaInit();
61
  dmaChanInit();
62

63
  int x = 1000;
64
  
65
  while (x)
66
    x--;
67

68
  while(1);
69
  
70
  return 0 ;
71
}
Gast #3271651
Lesenswert?

>  LPC_GPDMACH0->DMACCControl = (0x20 << 0)| (0x2 << 12)|(0x2 << 12)|(0x2 << 
18)|(0x2 << 21)|(1<<27);
>  LPC_GPDMACH0->DMACCConfig = (1<<0)|(0x4 << 1)|(0x00 <<6)|(0x2 << 11);

Tu' Dir einen Gefallen und verwende die Symbole, die sicher in 
irgendeinem Header definiert sind. So ist der Code unlesbar.
#3275405
Lesenswert?

Alex schrieb:
> "> LPC_GPDMACH0->DMACCLLI = 0x40034010; //AD0DR0
>
> Das ist mit Sicherheit falsch."
>
> Und kireg man die Erklärung/Begründung wieso das falsch sein soll?


Wenn man das Manual (UM10360.pdf) gelesen hätte, dann wüsste man das das 
LLI Register immer auf nix (0) oder eine DMA-LLI Struktur zeigen muß. 
Letztere besteht aus 3 Pointern und einem Control Feld, alles 32 Bit. 
Übrigens: LLI = Linked List Item.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren