Hi guys,
I'm trying to use DMA to update a register with the contents of the GPIOD_PDIR.
I'm wanting to use PIR to fix my sampling rate
So far I have this:
However readBuffer is remaining at 0x00. Any ideas?
I'm trying to use DMA to update a register with the contents of the GPIOD_PDIR.
I'm wanting to use PIR to fix my sampling rate
So far I have this:
Code:
DMAChannel dmaChannel0;
volatile uint32_t readBuffer;
void setup() {
// Set port D as inputs
pinMode(2, INPUT); // #0
pinMode(14, INPUT); // #1
pinMode(7, INPUT); // #2
pinMode(8, INPUT); // #3
pinMode(6, INPUT); // #4
pinMode(20, INPUT); // #5
pinMode(21, INPUT); // #6
pinMode(5, INPUT); // #7
/// SETUP DMA
dmaChannel0.channel = 0; // Ensure this is DMA channel 0 (Must be same as PIT)
// Source
dmaChannel0.TCD->SADDR = &GPIOD_PDIR;
dmaChannel0.TCD->SLAST = 0;
dmaChannel0.TCD->ATTR_SRC = 2; // 32 bit
dmaChannel0.TCD->SOFF = 0;
// Destination
dmaChannel0.TCD->DADDR = &readBuffer;
dmaChannel0.TCD->DLASTSGA = 0;
dmaChannel0.TCD->ATTR_SRC = 2; // 32 bit
dmaChannel0.TCD->DOFF = 0;
// Universal
dmaChannel0.TCD->NBYTES = 4;
dmaChannel0.TCD->BITER = 4;
dmaChannel0.TCD->CITER = 4;
DMAMUX0_CHCFG0 = (DMAMUX_SOURCE_ALWAYS0 & 0x3F) | DMAMUX_ENABLE | DMAMUX_TRIG;
dmaChannel0.enable();
/// SETUP PIT
// Enable the clock gating to pass F_BUS to PIT
SIM_SCGC6 |= SIM_SCGC6_PIT;
// Turn on PIT
PIT_MCR = 0x00;
// Set the period of the timer. Unit is (1 / 50MHz) = 20ns
// (period / (1/F_BUS)) - 1
PIT_LDVAL0 = 15; // 16MHz (3)
// Start the timer
PIT_TCTRL0 |= PIT_TCTRL_TEN;
}
void loop() {
delay(1000);
Serial.println("------------------------------------------------------------------------");
Serial.println(digitalReadFast(2));
//for (int i = 0; i < bufSize; i++)
{
Serial.print(readBuffer);
Serial.print(", ");
}
Serial.println("\n------------------------------------------------------------------------");
}
However readBuffer is remaining at 0x00. Any ideas?