Hi everyone,
I'm new to Renesas MCUs and currently working with the EK-RA2L1 to control a WS2812B LED strip using the r_spi peripheral. I'm trying to automate the SPI0 transmission with the Data Transfer Controller (DTC). However, I'm running into an issue: although the TXI interrupt for SPI0 triggers correctly, the DTC itself doesn’t seem to activate.
r_spi
Here’s how I configured the SPI peripheral:
And here’s how I configured the DTC transfer:
When the SPI transfer completes, I print a message to confirm it.
void spi_callback(spi_callback_args_t *p_args) { if (SPI_EVENT_TRANSFER_COMPLETE == p_args->event) { APP_PRINT("\r\nSPI Transfer Complete\r\n"); } }
Through J-Link RTT Viewer, I receive the "SPI Transfer Complete" message, confirming that the TXI interrupt is working. However, I only see the initial byte that I manually placed in the SPI buffer on the oscilloscope. This suggests that the DTC is not transferring additional data as expected.
This is the code I’m currently using for configuring SPI and setting up the DTC:
void hal_entry(void) { APP_PRINT("\r\nWS2812B controller with SPI\r\n"); fsp_err_t err = FSP_SUCCESS; uint8_t data4SPIbuffer = 0b11011011; uint8_t data_to_send[2] = {0b01101101, 0b10110110}; err = R_SPI_Open(&g_spi0_ctrl, &g_spi0_cfg); /* Handle error */ if (FSP_SUCCESS != err) { APP_ERR_PRINT("\r\n ** SPI Open API failed ** \r\n"); APP_ERR_TRAP(err); } err = R_DTC_Enable(&g_transfer2_ctrl); /* Handle error */ if (FSP_SUCCESS != err) { APP_ERR_PRINT("\r\n ** DTC Enable API failed ** \r\n"); APP_ERR_TRAP(err); } /* Configure DTC */ g_transfer2_cfg.p_info->p_dest = (void *) R_SPI0->SPDR; g_transfer2_cfg.p_info->p_src = &data_to_send; g_transfer2_cfg.p_info->length = sizeof(data_to_send); err = R_DTC_Reconfigure(&g_transfer0_ctrl, g_transfer0_cfg.p_info); /* Handle error */ if (FSP_SUCCESS != err) { APP_ERR_PRINT("\r\n ** DTC Reconfigure API failed ** \r\n"); APP_ERR_TRAP(err); } err = R_SPI_Write(&g_spi0_ctrl, data4SPIbuffer, 1, SPI_BIT_WIDTH_8_BITS); /* Handle error */ if (FSP_SUCCESS != err) { APP_ERR_PRINT("\r\n SPI Write failed!\r\n"); APP_ERR_TRAP(err); } }
Thank you in advance for any insights or suggestions on getting the DTC to trigger!
Hello,
The FSP software r_spi module has DTC support. FSP automatically enables DTC (when selected) to support the transfer of data from RAM buffers to SPI registers and vice versa to support transmission and reception. The user needs to add the DTC module on FSP configurator:
This is also used on the SPI example on EK-RA2L1:
https://github.com/renesas/ra-fsp-examples/tree/master/example_projects/ek_ra2l1/spi/spi_ek_ra2l1_ep
You do not need to add any user code to configure or enable DTC.
Thank you very much! I thought this would be a lot harder. The DTC works very well now, but there's still a significant delay between bytes (see photo). I see in the datasheet that for the SPI peripheral, there is a minimum delay of 1 RSPCK + 2 PCLKB. This is to allow another master to take over if it's a multi-master network. Is there a way to disable this delay? The WS2812B protocol is a one-wire interface, so it’s very dependent on the timing of the MOSI data.
No, the delay cannot be disabled. There is always a delay between every byte during SPI transfer.
The timings are depending on the delay registers. The minimum delays are the default ones:
t1: SPI Clock Delay Register (SPCKD) -> minimum = 1 RSPCKt2: SPI Slave Select Negation Delay Register (SSLND) -> minimum = 1 RSPCKt3: SPI Next-Access Delay Register (SPND) -> minimum = 1 RSPCK + 2 PCLKB
Okay, thanks for the help!