cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_TransmitReceive_DMA into EXTI0 ISR

leogarberoglio
Associate III
Posted on October 23, 2015 at 02:42

I have a SPI ADC conected to a STM32F4 I'm trying to use it with SPI DMA and DataReady signal with interrupt.

This code works fine:

while(1)
{
//PB0 = DRDY from ADC
if ( (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0) == GPIO_PIN_RESET) && (cnt_Sample != fftSize))
{
HAL_SPI_TransmitReceive_DMA(&hspi1, dummyByte, dataByte, 27);
}
//Process data
if (fui8DataRdy)
{
// Reseteo el flag de datos listos
fui8DataRdy=0;
for(i = 0; i<9; i++)
{
datachannel[i] = (dataByte[(3*i)+0]<<16) | (dataByte[(3*i)+1]<<8) | dataByte[(3*i)+2];
// convert 3 byte 2's compliment to 4 byte 2's compliment
if(datachannel[i] & (1<<23)){
datachannel[i] |= 0xFF000000;
}else{
datachannel[i] &= 0x00FFFFFF;
}
}
signal[cnt_Sample] = datachannel[1] * constChannel; //PGA=24
cnt_Sample++;
}
}
void EXTI0_IRQHandler(void)
{
if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0) != RESET)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
HAL_GPIO_WritePin(CS_PORT, CS_PIN, GPIO_PIN_RESET); //CS to LOW
}
}
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
HAL_GPIO_WritePin(CS_PORT, CS_PIN, GPIO_PIN_SET); //CS to HIGH
fui8DataRdy=1;
}
void DMA2_Stream0_IRQHandler(void)
{
HAL_DMA_IRQHandler(&hdma_spi1_rx);
}
void DMA2_Stream2_IRQHandler(void)
{
HAL_DMA_IRQHandler(&hdma_spi1_tx);
}

Interrupts prioritys:

void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__DMA2_CLK_ENABLE();
/* DMA interrupt init */
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
}
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 4, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);

So, that code is runing ok. But as soon as I move

HAL_SPI_TransmitReceive_DMA(&hspi1, dummyByte, dataByte, 27);

to

EXTI0_IRQHandler

the code goto to:

Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler

on startup_stm32f411xe.s, becouse a WWDG_IRQHandler It happend other times on the past with other projects and always was related to IRQ priorities, but this time I try diferent ways and code doesn't work. Waht should I check before move HAL_SPI.... onto EXTI0 IRQHandler? Thank
0 REPLIES 0