cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER

DYann.1
Senior

Hello,

I found an example on the internet of a project but I don't understand the usefulness of using a Timer 7. Could you tell me why ? Thanks in advance.

 

__IO uint32_t usTick;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* Prevent unused argument(s) compilation warning */
  if(htim==&htim7){
	usTick++;	
	}
  /* NOTE : This function Should not be modified, when the callback is needed,
            the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
   */
}

void delay_us(__IO uint32_t Delay){
uint32_t t=usTick;
uint32_t wait = Delay;
while( usTick - t < wait);

}
int main(void)
{

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM7_Init();
	/*if (HAL_TIM_Base_Start(&htim7) != HAL_OK) {
		      _Error_Handler(__FILE__, __LINE__);
    }*/
	if (HAL_TIM_Base_Start_IT(&htim7) != HAL_OK) {
		      _Error_Handler(__FILE__, __LINE__);
    }

  MX_I2C1_Init();
	  MX_I2S2_Init();

	HAL_Delay(100);

	audio.init();


	bool ptt=HAL_GPIO_ReadPin(GPIOE,PTT_SWITCH);
	bool pttstate=ptt;
	uint16_t index = 0;
	uint16_t buf = 0;
	audio.set_volume(0);
  /* Infinite loop */
  	while (1)//	read power switch
	{
		ptt=HAL_GPIO_ReadPin(GPIO_PINS,PTT_SWITCH);
		if(ptt!=pttstate){
			if(ptt==0){

				audio.start_receive();
				for(buf=0;buf<32;buf++){
					for(index=0;index < AUDIO_BUF_SIZE;index++){
						HAL_I2SEx_TransmitReceive(&hi2s2, &i2s_zero,&i2s_buf[buf][index], 1,0xFF);
					}
				}

				audio.start_play();
				for(buf=0;buf<32;buf++){
					for(index=0;index < AUDIO_BUF_SIZE;index++){
						HAL_I2SEx_TransmitReceive(&hi2s2, &i2s_buf[buf][index],&i2s_zero, 1,0xFF);
					}
				}
			}
			
			pttstate=ptt;
		}
  	}

}

 

 

40 REPLIES 40

Hi,

Thank you for your helps, I'm guessing but I understand your testing method for the SAI better. Have a nice day.