Hi, Fasih,
I have tried to use the code to test the PIT/ADC/eDMA, it appears it works fine. I develop the code under CW for mcu ver11.x, MC56F83000-EVK. But it is not fully tested.
BR
XiangJun Rong
#define N 100
#define CHANNEL_NUMBER_EACH_TRIGGER 4
void eDMA_ADC_MultipleChannel(void);
void ADCPit0TriggereMultipleChannelDMA(void);
uint16_t sample[N];
void main(void)
{
INTC->VBA = (uint16_t)(&vba_vector_addr);
__EI(0); // enable interrupts of all priorities
LED0_Init();
configADCPins();
ADCPit0TriggereMultipleChannelDMA();
eDMA_ADC_MultipleChannel();
// memTomem_eDMA();
while(1) {}
}
//ADC will sample CH0/CH1/CH2/CH3, total 4 channel
void ADCPit0TriggereMultipleChannelDMA(void)
{
//PIT0 init
SIM->PCE2|=1<<3;
//PIT0 prescaler is 32768, the PIT0 cycl;e time is (100 000 000/32768)=3051
PIT0->CTRL=0x0F<<3;
PIT0->MOD=5;
//PIT0->CTRL|=0x01;
//set up crossbar so that the PIT0 can trigger ADC
//XBAR_OUT12 ADCA_TRIG ADCA (Cyclic ADC) Trigger
//PIT0_SYNC_OUT PIT0 Sync Output XBAR_IN44
XBARA->SEL6=44;
//ADC init
//enable ADC gated clock
SIM->PCE2|=1<<7;
//init ADC module
//using hardware to start ADC, enable ADC end of scan interrupt
//Triggered sequential mode
ADC->CTRL1=0x9004;
//ADC clock is 100MHz/6=16.67MHz
ADC->CTRL2=0x02;
//ADC will sample CH0/CH1/CH2/CH3, total 4 channel
ADC->CLIST1=0x3210;
//sinfgle channel is sampled
ADC->SDIS=0xFFF0;
//configure ADC PWR reg
ADC->PWR2=0x200;
ADC->PWR=0x304;
//Poll id the ADC is powered up, the delay time is 0x30 clock cycles
while(ADC->PWR&0x400) {}
//set up voltage reference
ADC->CAL=0x00;
i=0;
//start PIT0
PIT0->CTRL|=0x01;
__asm(NOP);
}
void eDMA_ADC_MultipleChannel(void)
{
uint32_t temp;
//set up eDMA channel0 interrupt
INTC->IPR3|=0xC0;
DMA->INT|=0x01;
//enable EDMA channel 0 interrupt
//enable always channel
SIM->CTRL&=~(0x1C0);
SIM->CTRL|=0x1C0;
//reset DMAMUX
SIM->PSWR3|=0x200;
__asm(NOP);
__asm(NOP);
SIM->PSWR3&=~(0x200);
//48 ADCA_ES ADCA End of Scan
DMAMUX->CHCFG[0]=48;
//initalize the eDMA module
//enable minor loop and debug mode
DMA->CR|=0x82;
//word address &ADC->RSLT[0]=0xE500+E=0xE50E, byte address is 0x1CA1C
DMA->TCD[0].SADDR=(uint32_t)&ADC->RSLT[0]<<1;
//source offset 2 bytes
DMA->TCD[0].SOFF=0x02;
//two bytes for each transfer
DMA->TCD[0].ATTR=0x0101;
//minor loop count number
temp=(-2*CHANNEL_NUMBER_EACH_TRIGGER)<<10;
temp&=0x3FFFFC00;
temp|=0x80000000;
temp|=2*CHANNEL_NUMBER_EACH_TRIGGER;
DMA->TCD[0].NBYTES_MLOFFYES=temp;
__asm(nop); //break point, check the DMA->TCD[0].NBYTES_MLOFFYES reg
DMA->TCD[0].SLAST=0x00;
DMA->TCD[0].DADDR=(uint32_t)&sample[0]<<1;
DMA->TCD[0].DOFF=0x02;
//major counter
DMA->TCD[0].CITER_ELINKNO=N/4;
DMA->TCD[0].DLASTSGA=0x00;
DMA->TCD[0].BITER_ELINKNO=N/4;
//enable DMA trigger
DMAMUX->CHCFG[0]|=0x80;
//DMA->ERQ|=0x01;
//enable eDMA channel 0 interrupt
DMA->TCD[0].CSR|=0x02;
DMA->ERQ=0x01;
//start DMA for software trigger
//DMA->TCD[0].CSR|=0x01;
// while(!(DMA->TCD[0].CSR&0x80)) {}
__asm(nop);
}
//GPIOA0/A1/A2/A3 become ANA0/ANA1/ANA2/ANA3
void configADCPins(void)
{
//enable GPIOA gated clock
SIM->PCE0|=0x40;
GPIOA->PER|=0x0F;
}
#pragma interrupt on
void eDMA_0_ISR(void)
{
//clear DONE flag of eDMA channel 0
// DMA->TCD[0].BITER_ELINKNO=N/4;
// DMA->TCD[0].CITER_ELINKNO=N/4;
DMA->CDNE=0x40;
//clear DONE bit
DMA->TCD[0].CSR|=0x80;
PIT0->CTRL&=~(0x01);
__asm(NOP);
}
#pragma interrupt off
in the MC56F83xxx_Vectors.c
extern void eDMA_0_ISR(void);
volatile asm void _vect(void) {
JMP >_EntryPoint /* Interrupt no. 0 (Used)*/
JMP >_EntryPoint /* Interrupt no. 1 (Used)*/
JSR >ivINT_ILLEGAL_OP /* Interrupt no. 2*/
JSR >ivINT_SWI3 /* Interrupt no. 3*/
JSR >ivINT_OVERFLOW /* Interrupt no. 4*/
JSR >ivINT_MISALIGNED /* Interrupt no. 5*/
JSR >ivINT_STPCNT /* Interrupt no. 6*/
JSR >ivINT_BKPT /* Interrupt no. 7*/
JSR >ivINT_TRBUF /* Interrupt no. 8*/
....
JSR >eDMA_0_ISR //ivINT_DMA0 /* Interrupt no. 36*/
...
}