Hey, all-
Been struggling with using DMA to write to an SD card with SPI. It's my first try at using DMA so please excuse any silly mistakes.
The facts:
1) MSP430F1611
2) Using SLAA281b appnote code
3) ***Can read/write fine without DMA***
4) Modified appnote code to use USART0 rather than the "default" USART1
5) Can't read or write.
6) Tried many modifications of this to troubleshoot the poroblem and I'm stumped.
7) I don't have an oscope to probe the SPI connection.
8) mmcInit() from SLAA281b appears to work
9) I note that comments say "UART send" is the trigger but the original code used USART1 receive. Tried both ways...
Let's start with writing for now. Here's my modified code from the appnote:
#define withDMA
//Send a frame of bytes via SPI
unsigned char spiSendFrame(unsigned char* pBuffer, unsigned int size)
{
#ifndef withDMA
unsigned long i = 0;
// clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
for (i = 0; i < size; i++){
while (halSPITXREADY ==0); // wait while not ready for TX
halSPI_SEND(pBuffer[i]); // write
while (halSPIRXREADY ==0); // wait for RX buffer (full)
pBuffer[i] = halSPIRXBUF;
}
#else
/* Get the block */
/* DMA trigger is UART send */
DMACTL0 &= ~(DMA0TSEL_15);
DMACTL0 |= (DMA0TSEL_3); //USART0 Rx trigger
/* Source DMA address: the data buffer. */
DMA0SA = (unsigned short)pBuffer;
/* Destination DMA address: the UART send register. */
DMA0DA = U0TXBUF_;
/* The size of the block to be transferred */
DMA0SZ = size;
/* Configure the DMA transfer*/
DMA0CTL =
DMADT_0 | /* Single transfer mode */
DMASBDB | /* Byte mode */
DMAEN | /* Enable DMA */
DMASRCINCR1 | DMASRCINCR0; /* Increment the source address */
DMA0CTL |= DMAREQ;
#endif
return(0);
}
Thanks for any help or suggestions!
Cheers, MH