Other Parts Discussed in Thread: MSP430FR5994
I am trying to incorporate use of DMA with the MSP-EXP430FR5994-BQ79600EVM SPI. Though the BQ79600 operates at 2MHz clock, I am seeing the need to use SPI Rx interrupts for successful auto addressing. The hope is the use of DMA instead of the Rx interrupt is a less stressful setup for the MSP430. The byte I have been using the content of this thread to get started:
Here are my initial questions:
- Can I set the DMA channel 3 to trigger only on UCB1RXIFG? Will UCB1TXIFG use the DMA or only SPI receive is possible with DMA because of the trigger selection? I have pasted SPI_Init, SPI transmit, and SPI receive functions below. Is the correct value for DMA3SZ 1? Or does it have to be same as blocksize?
- Is the correct value for DMA3SZ 1? Or does it have to be same as blocksize?
- Is the correct value for DMA3SZ 1? Or does it have to be same as blocksize?
- I don’t understand the purpose or how to use dma_value.
- If anything else in DMA_Init is amiss, do let me know.
Thanks
void DMA_Init(){
(uintptr_t) &DMA3SA = (uintptr_t) &UCB1RXBUF;
(uintptr_t) &DMA3DA = (uintptr_t) &dma_value;
DMA3CTL &= ~DMAEN;
DMACTL1 |= DMA3TSEL__UCB1RXIFG;
DMA3CTL |= DMAARMDIS;
DMA3CTL &= ~DMA3CTL;
DMA3SZ = 1;
DMA3CTL |= DMADT_4|DMADSTINCR_3|DMASRCINCR_0|DMASRCBYTE__BYTE|DMADSTBYTE__BYTE|DMA_TRIGGER_RISINGEDGE|DMAEN;
}
void SPI_Init()
{
//BQ79600 SPI1_B1
UCB1CTLW0 = UCSWRST; // **Put state machine in reset**
UCB1CTLW0 |= UCCKPH | UCCKPL_0 | UCMSB | UCSYNC
| UCMST | UCSSEL__SMCLK; // 3-pin, 8-bit MAB SPI master SMCLK=1M
UCB1BRW = 0x00; //UCB1CLK=SMCLK=1M
UCB1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
}
void spiTransmitData(uint32_t blocksize)
{
TransmitIndex=0;
P4OUT = ~BIT4;
while(blocksize != 0U)
{
UCB1TXBUF=spiFrame[TransmitIndex];
while((UCB1STAT&UCBUSY));
dummy=UCB1RXBUF;
TransmitIndex++;
blocksize--;
}
P4OUT = BIT4;
return;
}
void spiTransmitAndReceiveData(uint32_t blocksize,uint16_t * destbuff)
{
ReceiveIndex = 0;
P4OUT &= ~BIT4;
while(blocksize != 0U)
{
UCB1TXBUF=dummy;
while((UCB1STAT&UCBUSY));
destbuff[ReceiveIndex]=UCB1RXBUF;
ReceiveIndex++;
blocksize--;
}
P4OUT |= BIT4;
return;
}