Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4819

General • Re: Pico2 40Mhz SPI Signal integrity

$
0
0
Ok, I think the main reason for my display artifacts is the difference on how SPI CS is handled on RP2350 together with DMA.

On ESP32, SPI CS stays low for the whole DMA Transfer (e.g. 16 Bytes). On my RP2350 configuration, the SPI CS goes low for every individual byte.

Is it possible to instruct the SPI/DMA Module to keep SPI CS low for the whole transfer? Or do I need to utilize Software SPI CS to do this?

This is my code. Is the Pico SPI/DMA Module to be used in that way, or do I use it fundamentally wrong?
My concept is the following loop: write data with spim_send() -> calculate new data, wait for DMA with spim_wait_blocking()

Code:

void spim_init(uint8_t SCK, uint8_t SDI, uint8_t CS) {  gpio_set_function(SCK, GPIO_FUNC_SPI);  gpio_set_function(SDI, GPIO_FUNC_SPI);  gpio_set_function(CS, GPIO_FUNC_SPI);  spi_init(spi1, 40 * 1000 * 1000);  spim_internal_buffer = malloc(SPIM_DMA_MEMORY_SIZE);}void spim_wait_blocking() {  dma_channel_wait_for_finish_blocking(dma_tx);    dma_channel_unclaim(dma_tx);}void spim_send(uint8_t *data, uint32_t size) {  if(data != NULL && spim_internal_buffer != NULL && size <= SPIM_DMA_MEMORY_SIZE) {    memcpy(spim_internal_buffer, data, size);  } else {    printf("SPIM memory error \n");    return;  }  // Grab some unused dma channels  dma_tx = dma_claim_unused_channel(true);  printf("Configure TX DMA\n");  dma_channel_config c = dma_channel_get_default_config(dma_tx);  channel_config_set_transfer_data_size(&c, DMA_SIZE_8);  channel_config_set_dreq(&c, spi_get_dreq(spi1, true));  dma_channel_configure(dma_tx, &c,                        &spi_get_hw(spi1)->dr, // write address                        spim_internal_buffer, // read address                        size, // element count (each element is of size transfer_data_size)                        false); // don't start yet  dma_start_channel_mask(1u << dma_tx);  return;}
spi_40m_pico2_dma.png

Statistics: Posted by cocoa — Tue Aug 27, 2024 8:32 pm



Viewing all articles
Browse latest Browse all 4819

Trending Articles