Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TIMER Interrupt and SPI DMA Conflict in STM32F7

Status
Not open for further replies.

uranyumx

Advanced Member level 4
Joined
Mar 5, 2011
Messages
102
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,091
Hello,

On my custom designed PCB, I use a STM32F7 processor. I control a SPST switch with TIM ISR. I establish a serial interface with SPI2 for a DAC control. Also I have an external ADC which is controlled with SPI4 DMA mode. Now I call the SPST and DAC control commands with TIM ISR. For the ADC, I call the SPI DMA function in main.c file. The problem is that I can measure DAC command results with oscilloscope and observe the results in debug session (which means SPI DMA also works), but the SPST does not operate. Do you have any idea how I can solve the problem?

Thank you,

Code:
void TIM3_IRQHandler(void)
{
  /* USER CODE BEGIN TIM3_IRQn 0 */

  /* USER CODE END TIM3_IRQn 0 */
  HAL_TIM_IRQHandler(&htim3);
  /* USER CODE BEGIN TIM3_IRQn 1 */
	
                // SPST Switch Control
		switch (count)
				{
					case 0:
							break;
					case 50:
							HAL_GPIO_WritePin(PHASE_1ST_GPIO_Port, PHASE_1ST_Pin, GPIO_PIN_SET);
							break;
					case 70:
							HAL_GPIO_WritePin(PHASE_2ND_GPIO_Port, PHASE_2ND_Pin, GPIO_PIN_SET);
							break;
					case 80:
							HAL_GPIO_WritePin(PHASE_1ST_GPIO_Port, PHASE_1ST_Pin, GPIO_PIN_RESET);
							break;
					case 100:
							HAL_GPIO_WritePin(PHASE_2ND_GPIO_Port, PHASE_2ND_Pin, GPIO_PIN_RESET);
							count=-1;
				}
				count++;
                          
			        // DAC Control	
				float testdata_out_1 = (0.4); // Desired DAC Output value. The formula is testdata_out_1=5V*(D/255) 
				uint8_t Data_1;
				Data_1 = (uint8_t)(testdata_out_1*255);
				HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_RESET);		
				DACA_Buf = DAC_A_Write<<12 | Data_1<<4;
				HAL_SPI_Transmit(&hspi2,(uint8_t*)&DACA_Buf,2,100);
				HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_SET);
					
				float testdata_out_2 = (0.4); // Desired DAC Output value. The formula is testdata_out_1=5V*(D/255) 
				uint8_t Data_2;
				Data_2 = (uint8_t)(testdata_out_2*255);
				HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_RESET);
				DACB_Buf = DAC_B_Write<<12 | Data_2<<4;
				HAL_SPI_Transmit(&hspi2,(uint8_t*)&DACB_Buf,2,100);
				HAL_GPIO_WritePin(DAC_CS_GPIO_Port, DAC_CS_Pin, GPIO_PIN_SET);




Main. c file

Code:
while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
		
		spidata[0]=0x00;       // Set everything up  before you start the exchange
		spidata[1]=0x00;
		HAL_SPI_TransmitReceive_DMA(&hspi4,spidata,ADC_Buf,2);
		HAL_Delay(500);
  }
  /* USER CODE END 3 */
}

void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
		Sample = (((uint16_t) ADC_Buf[1]) << 8 | ADC_Buf[0]) & 0x0FFF; 
		volt = (float)(Sample * (3.3 / 4096.0)); //
		testdata_in[i++]=volt;
		i %= 60;

}







Timer Settings:

Code:
static void MX_TIM3_Init(void)
{

  /* USER CODE BEGIN TIM3_Init 0 */

  /* USER CODE END TIM3_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM3_Init 1 */

  /* USER CODE END TIM3_Init 1 */
  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 10-1;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 80-1;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM3_Init 2 */

  /* USER CODE END TIM3_Init 2 */

}

- - - Updated - - -

I solve the problem with adjusting the timer period and prescaler values. Now the problem is that I couldn't read the correct values of the input signals.

I have attached the input signal and the debug session results.]

input biphasic_1 0.png
debug session_1.PNG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top