Hi,
I am having trouble with DMA transfer on SPI2. Currently in my code SCI-3 is configured for DMA. I am trying to configure SPI-2 with DMA as well. In the ref. manual for SM470R1B1M ( ) on page 20 - table 5 shows list of modules. It lists SCI3/SPI2. From the note under the table I infer that we cannot use DMA for SCI3 and SPI2 at the same time. It is only either one of the options. Is my understanding correct?
If it is not correct then I have implemented the DMA for SPI-2 as follows. Please let me know if I am missing anything or if something is wrong with this code:
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 Init_SPI2(void)
{
// Enter SPI reset mode
SPI2CTRL2 &= ~SPIEN; // Place SPI in reset
SPI2CTRL3 &= ~RX_INT_EN; // Disable SPI receive interrupts
// Configure SPI port 2
SPI2CTRL1 = 0 | CHARLEN_8; // 8 bits/char
SPI2CTRL1 |= SPI_PRESCALE_7;
SPI2CTRL2 |= MASTER; // We are the master
SPI2CTRL2 |= CLKMOD; // We drive the clock
SPI2CTRL2 &= ~POLARITY; // CLK Polarity = 0
SPI2CTRL2 |= PHASE; // CLK Phase = 1
SPI2PC6 = 0 | CLK_FUN; // SCLK pin
SPI2PC6 |= SIMO_FUN; // SIMO pin
SPI2PC6 |= SOMI_FUN; // SOMI pin
// SPI2CTRL3 |= RX_INT_EN; // SPI interrupt enable
SPI2CTRL3 |= DMA_REQ_EN; // DMA request enable
// Exit SPI reset mode
SPI2CTRL2 |= SPIEN; // Activate the SPI
}
void spi2RxDma(uint8_t *pDest, uint32_t count)
{
// Set up DMA:
// DMA setup for SPI1:RX (Packet 1/Channel 10)
// Control Packet 1 Configuration
DMAC01 = 0 | INTEN | DSTINC | DSTMOD_2 | SRCMOD_15;
DMASA01 = (uint32_t)&SPI2BUF;
DMADA01 = (uint32_t)pDest;
DMATC01 = count;
// Channel 10 Configuration
DMACC1 |= SEN10 | RQEN10; // IL10 // = for DMA1 interrupt line
// Notify the DMA that Control Packet 1 is updated
DMACPS |= CPACK_1;
// Channel 10 Enable with Control Packet 1
DMACCP2 |= CCPACK10_1 | DMEN10;
}
void spi2TxDma(uint8_t *pSrc, uint32_t count)
{
// DMA setup for SPI1:TX (Packet 2/Channel 11)
// Control Packet 2 Configuration
DMAC02 = 0 | SRCINC | SRCMOD_2 | DSTMOD_15;
DMASA02 = (uint32_t)pSrc;
DMADA02 = (uint32_t)&SPI2DAT0;
DMATC02 = count;
// Channel 11 Configuration
DMACC1 |= SEN11 | RQEN11;
// Notify the DMA that Control Packet 2 is updated
DMACPS |= CPACK_2;
// Channel 11 Enable with Control Packet 2
DMACCP2 |= CCPACK11_2 | DMEN11;
}
Any help is greatly appreciated.
Pinakin