This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I have big problems to implement the UCB0 with SPI via DMA. The program runs with UCB0 and SPI without any problem. So I want to implement the DMA.
I don't get any result of the DMA. Maybee someone had the same problem and can help me.
Here is my sourcecode:
void sendFrame(uint8_t *pBuffer, uint16_t size)
{
IFG2 &= ~(UCB0RXIFG | UCB0TXIFG);
DMA1SA = __DMA_ACCESS_REG__ pBuffer;
DMA1DA = __DMA_ACCESS_REG__ &UCB0TXBUF;
DMA1SZ = size;
DMA1CTL = DMADT_0 | DMASBDB | DMASRCINCR1 | DMASRCINCR0;
DMACTL0 |= DMA1TSEL_12;
DMA1CTL |= DMAEN;
UCB0TXBUF = 0xFE;
while((IFG2 & UCB0TXIFG)==0);
}
void readFrame(uint8_t *pBuffer, uint16_t size)
{
IFG2 &= ~(UCB0RXIFG | UCB0TXIFG);
DMA1SA = __DMA_ACCESS_REG__ &UCB0RXBUF;
DMA1DA = __DMA_ACCESS_REG__ pBuffer;
DMA1SZ = size;
DMA1CTL = DMADT_0 | DMASBDB | DMADSTINCR1 | DMADSTINCR0;
DMA1CTL |= DMAEN;
DMA2SA = __DMA_ACCESS_REG__ BLANK;
DMA2DA = __DMA_ACCESS_REG__ &UCB0TXBUF;
DMA2SZ = size - 1;
DMA2CTL = DMADT_0 | DMASBDB;
DMACTL0 |= (DMA1TSEL_12 + DMA2TSEL_12);
DMA2CTL |= DMAEN;
DMA2CTL |= DMAREQ;
UCB0TXBUF = 0xFF;
while((IFG2 & UCB0RXIFG)==0);
}
I think the problem is the way you initialize the transfer.
You write to TXBUF to initialize the sending.
However, if the USCI is initialized, TXIFG is already set. Writing to TXBUF doesn't clear it as TXBUF is immediately moved to the output and TXBUF is empty again. It is possible that TXIFG never appears clear. And the DMA requires a transition from 0 to 1 on TXIFG to trigger.
You'll need to manually clear TXIFG and then write to txbuf. This will set txifg once the byte starts to transfer, and trigger the DMA. (manually clearing and then setting txifg will have the same effect, yet does not trigger an USCI transfer - however, the DMA will do it then).
You should take a close look at the timings. You trigger both, read and write, by the TXIFG bit. Ensure that RX is really complete when TXIFG is set, and that the RX is always done first (since serving TX will clear the TXIFG bit and I'm not sure whether the RX DMA is still served then).
**Attention** This is a public forum