cancel
Showing results for 
Search instead for 
Did you mean: 

200kHz ADC Communication

UL
Associate III

Hello, 

 

I have been using the STM32F4 chip for a while but I ran into an issue when trying to communicate with an ADC to sample at 200kHz. So I have started to work with the STM32U5 chip. My goal is to use the SPI RDY feature or the GPDMA triggered from an external interrupt in order to handle the spi communication and fill a buffer. Unfortunately I have been struggling to find good resources on how to use these features or examples that I can try to follow through. I am able to do spi communication that are called from the main process but I can't get a message to trigger from an external interrupt. 

 

Any advice on how I can learn about these features would be greatly appreciated,

 

I have also included the code as I have it thus far.

 

Thanks!

12 REPLIES 12

Yes that was my original solution when I was using the STM32F4 MCU and I could only go as high as 15kHz before the messaging was taking too long. 

UL
Associate III

In Order to make the transfer I have done the following:

Starting point LL Node:

pNodeConfig.Init.Request = GPDMA1_REQUEST_USART1_TX;

pNodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;

pNodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;

pNodeConfig.Init.DestInc = DMA_DINC_FIXED;

pNodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;

pNodeConfig.SrcAddress = data;

pNodeConfig.DstAddress = (uint32_t)&(USART1->TDR);

pNodeConfig.DataSize = 64*2;

 

After Change LL Node:

pNodeConfig.Init.Request = GPDMA1_REQUEST_SPI1_TX;

pNodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;

pNodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;

pNodeConfig.Init.DestInc = DMA_DINC_FIXED;

pNodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_BYTE;

pNodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_BYTE;

pNodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;

pNodeConfig.SrcAddress = data;

pNodeConfig.DstAddress = (uint32_t)&(SPI1->TXDR);

pNodeConfig.DataSize = 64*2;

 

 

main.c Uart Setup:

 

MX_YourQueueName_Config();

HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel15, &YourQueueName);

ATOMIC_SET_BIT(huart1.Instance->CR3, USART_CR3_DMAT);

__HAL_UART_ENABLE(&huart1);

HAL_ADC_Start(&hadc1);

HAL_DMAEx_List_Start(&handle_GPDMA1_Channel15);

HAL_TIM_Base_Start(&htim15);

 

 

main.c SPi Setup:

MX_YourQueueName_Config();

HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel15, &YourQueueName);

SET_BIT(hspi1.Instance->CFG1, SPI_CFG1_RXDMAEN | SPI_CFG1_TXDMAEN);

SPI_2LINES_TX(&hspi1);

__HAL_SPI_ENABLE(&hspi1);

HAL_SPI_Transmit_DMA(&hspi1, data, 4);

HAL_ADC_Start(&hadc1);

HAL_DMAEx_List_Start(&handle_GPDMA1_Channel15);

HAL_TIM_Base_Start(&htim15);

 

 

SPI Config:

 

hspi1.Instance = SPI1;

hspi1.Init.Mode = SPI_MODE_MASTER;

hspi1.Init.Direction = SPI_DIRECTION_2LINES;

hspi1.Init.DataSize = SPI_DATASIZE_16BIT;

hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

hspi1.Init.NSS = SPI_NSS_SOFT;

hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

hspi1.Init.CRCPolynomial = 0x7;

hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;

hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;

hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;

hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;

hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;

hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;

hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;

hspi1.Init.ReadyMasterManagement = SPI_RDY_MASTER_MANAGEMENT_INTERNALLY;

hspi1.Init.ReadyPolarity = SPI_RDY_POLARITY_HIGH;

if (HAL_SPI_Init(&hspi1) != HAL_OK)

{

Error_Handler();

}

HAL_SPI_AutonomousMode_Cfg_Struct.TriggerState = SPI_AUTO_MODE_DISABLE;

HAL_SPI_AutonomousMode_Cfg_Struct.TriggerSelection = SPI_GRP1_GPDMA_CH0_TCF_TRG;

HAL_SPI_AutonomousMode_Cfg_Struct.TriggerPolarity = SPI_TRIG_POLARITY_RISING;

if (HAL_SPIEx_SetConfigAutonomousMode(&hspi1, &HAL_SPI_AutonomousMode_Cfg_Struct) != HAL_OK)

{

Error_Handler();

}

UL
Associate III

Hi OSAKE,

 

I found that continuous transmutation is only available on the USART communication. For SPI I needed to use the autonomous mode as you had mentioned. Since I am using the Development Kit I am currently using a timer to mimic the external interrupt. I have attached the solution below.

 

I did find that the I needed two nodes in the linked list and the ADC read had to have atleast one value or the the spi clock signal would not be generated. 

 

thanks!