How do you stop SPI DMA circular transfers in a G474RE
I am using a NUCLEO64-G474RE as an SPI master with DMA (Rx and Tx in circular mode) to interface an ADC CHIP. I am receiving data reliably but wish to stop and start the SPI/DMA .
I have used CubeMx to generate the initilisation code and HAL_SPI_TransmitReceive_DMA( ) to start sampling. However I cannot stop the reception.
I have read the relevant sections of RM0440. The only reference to stopping the SPI/DMA is on page 1745 where it states
- Disable DMA streams for TX and Rx in the DMA registers, if the streams are used.
- Disable the SPI by following the SPI disable proceedure as follows (this is on Page 1743)
Wait until FTLVL[1:0] = 00 (NO MORE DATA TO TRANSMIT)
Wait until BSY=0 (THE LAST DATA FRAME IS PROCESSED)
Disable the SPI (SPE =0);
Read data until FRLVL[1:0] = 00 (read all the received data) - Disable DMA Tx and Rx buffers by clearing the TXDMAEN and RXDMAEN bits in the SPI_CR2 register, if DMA Tx and/or DMA Rx are used.
I could find no reference to the term "streams" in the DMA section of the data sheet, what are they?
My effort is below, what am I doing wrong? Many thanks in advance.
/* stop the SPI-DMA process */
HAL_SPI_DMAStop(&hspi3); // Disable DMA streams if used what and how???
__nop();
while (((SPI3->SR)&(3<<11))) {}; // Wait until FTLVL[1:0] = 00 (no more data to transmit)
while (((SPI3->SR)&(1<<7))) {}; // Wait until BSY = 0 (the last data frame is processed)
SPI3->CR1 &= ~(1<<7); // Disable the SPI (SPE = 0)
do{
dummy = SPI3->DR; // Keep doing dummy reads of the SPI3 data register
dummy = SPI3->SR; // (this line allows the FRLVL bits to be observed)
} while(((SPI3->SR)&(3<<9))); // until FRLVL[1:0] = 0 i.e. all data received
SPI3->CR2 &= ~(11); // Disable DMA Rx and Tx buffers TXDMAEN = RXDMAEN = 0
