c - 定时器触发 GPDMA 传输到 SRAM
问题描述
我想从外部 AD 转换器传输数据。我得到存储在数组中的并行 11 位。我想设置一个定时器触发的 GPDMA 传输,每 50ns 触发一个 DMA 流并传输数据。传输完成后,RAM 地址应递增。
我使用的 MCU 是 LPC4088 快速入门板。CPU 和外设时钟,以 120Mhz 运行
我研究了LPC4088的UM,已经写了一些简单的基本代码。
#include "LPC407x_8x_177x_8x.h"
#define PERIPHSRAM1 0x20004000
char adcData[11] = {1,1,1,1,1,1,1,1,1,1,1};
volatile uint32_t DMATCCOUNT = 0;
volatile uint32_t DMAERRCOUNT = 0;
int main(){
uint8_t size = sizeof(adcData);
LPC_SC->PCONP |= (1 << 22); //Power & Clock Timer2
LPC_TIM2->CTCR = (0 << 0); //Timer Mode
LPC_TIM2->PR = 0;
LPC_TIM2->TCR = (1 << 1); //Reset timer
LPC_TIM2->TC = 0;
LPC_TIM2->MR0 = 5; //Match register to get 10MHz
LPC_TIM2->MCR = (1 << 1) //Reset Timer
|(1 << 0); //Interrupt if MR0 matches
LPC_TIM2->EMR = 0x31; //toggle pin to check wave output
LPC_TIM2->TCR = (1 << 1); //reset timer again
LPC_SC->PCONP |= (1 << 29); //Power & Clock DMA
LPC_GPDMACH0->CConfig = 0; //disable CH0
LPC_GPDMA->Config |= (1 << 0); //enable DMA Controller
LPC_SC->DMAREQSEL = 0x010; //Set T2 MAT0 as DMA request
LPC_GPDMA->IntErrClr |= 0x0FF;
LPC_GPDMA->IntTCClear |= 0x0FF;
LPC_GPDMACH0->CDestAddr = PERIPHSRAM1;
LPC_GPDMACH0->CSrcAddr = (uint32_t) &adcData;
LPC_GPDMACH0->CControl = size
|(0x00 << 12) //Source Burst size: 1
|(0x00 << 15) //Destination Burst size: 1
|(0x02 << 18) //Source width: 32 bit
|(0x02 << 21) //Destination width:32 bit
|(0x01 << 26) //Source increment: enabled
|(0x01 << 27) //Destination increment: enabled
|(0x01 << 31); //TermCount interrupt enabled
LPC_GPDMACH0->CControl |= (4 << 1) //Source peripheral: Timer2 MR0
|(0 << 11); //Memory to memory trasnfer
NVIC_SetVector(DMA_IRQn, (uint32_t) DMA_IRQHandler);
NVIC_EnableIRQ(DMA_IRQn);
LPC_GPDMACH0->CConfig |= 1; //Enable channel
LPC_TIM2->IR |= 0x0FF; //CLear all timer interrupts
LPC_TIM2->TCR = 0x01; //start Timer
while(!DMATCCOUNT); //Wait till transfer Complete
while(1){
}
}
void DMA_IRQHandler(void){
uint32_t temp;
DMATCCOUNT++;
temp = LPC_GPDMA->IntTCStat;
if(temp){
DMATCCOUNT++;
LPC_GPDMA->IntTCClear |= temp;
}
temp = LPC_GPDMA->IntErrStat;
if(temp){
DMAERRCOUNT++;
LPC_GPDMA->IntErrClr |= temp;
}
return;
}
I expected data on address 0x20004000, but there is nothing.
Hope any of you guys could help me.
解决方案
推荐阅读
- rust - One::one() 与 1 有什么区别
- c# - 如何在代码隐藏中多次将 XAML 资源(带有 ItemsControls 的网格)添加到 FlowDocument
- javascript - React 更改父数组属性
- django - 在 Django 项目停止之前做一些任务
- javascript - 如何从来自 api 的对象创建有效文件?
- r - 重命名列条目,当它是按组的最大值时,会给出不一致的结果
- php - IMAP 检查邮件来自哪个邮件客户端
- php - 在 php 表单中添加输入文本字段并将数据存储在文件中也显示动态表中的文本
- javascript - 如何使用 cy.intercept 存根两个同名请求但返回两个不同的主体?
- c++ - 同步访问两个矩阵