Hi,
I have configured DMA to read data over SPI (reads from ADS1278 - 2 bit adc). This works fine most of the times. Once in blue moon a power up results in bad reading over DMA. I used a scope to monitor the traffic and I noticed that the data is still good over SPI. It seems like DMA is not fetching the data correctly from SPI. The values are jumping all over the place though scope reveals that the values from ADC are good. Any idea what could be wrong. My DMA initialization for reading from SPI-1 is as follows.
void Init_SPI1(void)
{
SPI1CTRL2 &= ~SPIEN;
SPI1CTRL3 &= ~RX_INT_EN;
// Configure SPI port 1
SPI1CTRL1 = 0 | CHARLEN_8; // 8 bits/char
SPI1CTRL1 |= SPI_PRESCALE_47;
SPI1CTRL2 |= MASTER; // We are the master
SPI1CTRL2 |= CLKMOD; // We drive the clock
SPI1CTRL2 &= ~POLARITY; // CLK Polarity = 0
SPI1CTRL2 |= PHASE; // Phase = 1
SPI1PC6 = 0 | CLK_FUN; // SCLK pin
SPI1PC6 |= SIMO_FUN; // SIMO pin
SPI1PC6 |= SOMI_FUN; // SOMI pin
SPI1CTRL3 |= DMA_REQ_EN; // DMA request enable
SPI1CTRL2 |= SPIEN; // Activate the SPI
}
void Init_DMA(void)
{
DMAGC = 0; // Channel service size = 1
DMAGD = 0; // Clear STOP and HALT mode
DMACPSCLR = 0; // Disable all control packets
DMAS = 0; // Clear all pending interrupts
DMACCP0 = 0; // Disable channels 0-3
DMACCP1 = 0; // Disable channels 4-7
DMACCP2 = 0; // Disable channels 8-11
DMACCP3 = 0; // Disable channels 12-15
}
void SPI1_DmaExchange (uint8_t *txbuf, uint8_t *rxbuf, uint16_t size)
{
DMAC01 = 0 | INTEN | DSTINC | DSTMOD_2 | SRCMOD_15;
DMASA01 = (uint32_t)&SPI1BUF + 3;
DMADA01 = (uint32_t)rxbuf;
DMATC01 = size;
// Notify the DMA that Control Packet 1 is updated
DMACPS |= CPACK_1;
// Channel 1 Configuration
DMACC0 |= SEN1 | RQEN1;
// Channel 1 Enable with Control Packet 1
DMACCP0 |= CCPACK1_1 | DMEN1;
// DMA setup for SPI1:TX (Packet 2/Channel 2)
// Control Packet 2 Configuration
DMAC02 = 0 | SRCINC | SRCMOD_2 | DSTMOD_15;
DMASA02 = (uint32_t)txbuf;
DMADA02 = (uint32_t)&SPI1DAT0 + 1;
DMATC02 = size;
// Notify the DMA that Control Packet 2 is updated
DMACPS |= CPACK_2;
// Channel 2 Configuration
DMACC0 |= SEN2 | RQEN2;
// Channel 2 Enable with Control Packet 2
DMACCP0 |= CCPACK2_2 | DMEN2;
}
Any help is appreciated.
Pinakin