GPIO Stops Toggling When Timer and SPI DMA Are Active on NUCLEO-H753ZI
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:
- The CS pin is controlled by Timer 12 PWM output, as we need to read data from the accelerometer at 8 kHz sampling rate.
- The SPI communication seems to be working correctly because I can successfully read the accelerometer’s WHO_AM_I register.
- However, I noticed that the GPIO toggling inside the while loop stops working when both Timer 12 and SPI DMA are active.
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!
