2025-03-17 6:46 PM - edited 2025-03-17 6:49 PM
Hello everyone,
I am working with the NUCLEO-H753ZI and communicating with an IIM42652 accelerometer using SPI with DMA enabled. Below is the relevant part of my code:
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
MX_TIM12_Init();
/* Start Timer 12 PWM */
HAL_TIM_PWM_Start_IT(&htim12, TIM_CHANNEL_2);
// Prepare SPI communication
txbuffer_dma[0] = REG_WHO_AM_I | 0x80;
txbuffer_dma[1] = 0x00;
memset(rxbuffer_dma, 0, sizeof(rxbuffer_dma));
// Start SPI communication with DMA
HAL_SPI_TransmitReceive_DMA(&hspi1, txbuffer_dma, rxbuffer_dma, 4);
/* Main Loop */
while (1)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET);
}
}
After running this code, I checked the signals using a logic analyzer and observed the following:
Since DMA is supposed to store the received data directly into memory without CPU intervention, I expected the CPU to be free to execute other tasks (such as GPIO toggling). However, this does not seem to be the case.
Has anyone encountered a similar issue or found a solution for this behavior? Any insights would be greatly appreciated!
Solved! Go to Solution.
2025-03-17 7:42 PM - edited 2025-03-17 7:43 PM
When the system is handling interrupts, it is not making progress in the main thread. This is a single thread processor. Interrupts such as transfer complete will interrupt and pause the main thread until they are done.
The DMA is handled without the CPU, but the interrupts caused by it are not. You can disable the interrupts if you don't need them.
2025-03-17 7:42 PM - edited 2025-03-17 7:43 PM
When the system is handling interrupts, it is not making progress in the main thread. This is a single thread processor. Interrupts such as transfer complete will interrupt and pause the main thread until they are done.
The DMA is handled without the CPU, but the interrupts caused by it are not. You can disable the interrupts if you don't need them.
2025-03-17 8:55 PM
Thank you for your response. I understand that interrupts pause the main thread while they are being handled.