My new DMA SPI INIT function looks like that:
!!!!
FIFO_SIZE - number of transfer is a static harcoded value
!!!!!
In main() , I called this function dma_init() for DMA initialization and in my readSamples() function, I read actual data from IIS via DMA:
It works for me only if I called once readSamples() function , but I don t want that, I want to called it into a loop using a while(1) instruction with a 5 ms sleep of waiting. If I did that, If I read samples data in a loop with 5 ms sleep, it works just for the first iteration and after 5 ms doesn't start....TX channel doesn't send that dummy value
How can I make it to works right in a continuous loop?
Do I have to close the channels with dma_channel_abort(channel) ?
Code:
#ifdef USE_DMA_IISuint8_t fifo_buffer[MAX_SAMPLES];//DMA SPI INITvoid dma_init() { // Configure DMA channel for RX dma_channel_config c2 = dma_channel_get_default_config(DMA_CHANNEL_RX); channel_config_set_transfer_data_size(&c2, DMA_SIZE_8); channel_config_set_read_increment(&c2, false); channel_config_set_write_increment(&c2, true); channel_config_set_dreq(&c2, spi_get_dreq(SPI_PORT, false)); dma_channel_configure( DMA_CHANNEL_RX, &c2, fifo_buffer, // Destiantion &spi_get_hw(SPI_PORT)->dr, // Source FIFO_SIZE, / Number of transfers false // Don't start yet ); // Configure DMA channel for TX with dummy data static uint16_t dummy_data[FIFO_SIZE] = {0}; dummy_data[0] = IIS3D_FIFO_DATA_OUT_BASE | 0x80; // TX byte for IIS FIFO read dma_channel_config c1 = dma_channel_get_default_config(DMA_CHANNEL_TX); channel_config_set_transfer_data_size(&c1, DMA_SIZE_8); channel_config_set_read_increment(&c1, true); channel_config_set_write_increment(&c1, false); channel_config_set_dreq(&c1, spi_get_dreq(SPI_PORT, true)); dma_channel_configure(DMA_CHANNEL_TX, &c1, &spi_get_hw(SPI_PORT)->dr, // Destination dummy_data, // Source FIFO_SIZE, // Number of transfers (same as RX) false // Don't start yet );}#endif
FIFO_SIZE - number of transfer is a static harcoded value
!!!!!
In main() , I called this function dma_init() for DMA initialization and in my readSamples() function, I read actual data from IIS via DMA:
Code:
readSamples(){ gpio_put(PIN_CS, 0); dma_channel_start(DMA_CHANNEL_TX); // Start dummy TX dma_channel_start(DMA_CHANNEL_RX); // Start RX dma_channel_wait_for_finish_blocking(DMA_CHANNEL_RX); gpio_put(PIN_CS, 1) };
Code:
dma_channel_start(DMA_CHANNEL_TX)
How can I make it to works right in a continuous loop?
Do I have to close the channels with dma_channel_abort(channel) ?
Statistics: Posted by redans123 — Fri Aug 02, 2024 11:01 am