2023-10-30 02:45 AM
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;
}
}
}
2023-10-30 02:48 AM
It's probably to do a clocking in µs ?
2023-10-30 05:09 AM
Yes, exactly this.
2023-10-30 05:25 AM
Yes but only use in the HAL_TIM_PeriodElapsedCallback and nothing else (the usTick) and apparently the timer works by itself and we don't use it manually to recover the data. I don't see the use of the Timer yet the author says : 'This function Should not be modified, when the callback is needed, the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file'
But there is no callback so why the Timer is necessary ? Thank you for your helps.
2023-10-30 06:19 AM
If the random code you found needs to interrupt at 1 MHz, I would say maybe find a different code to go from.
2023-10-30 06:25 AM
>This function Should not be modified
This looks like just copy/paste from some place in the template code; the HAL_TIM_PeriodElapsedCallback is defined there with "weak" attribute. In your code it is exactly the "implementation in user file". This function *is* the callback from timer interrupt handler.
/* Example why bad comments are worse than no comments */
2023-10-30 06:28 AM
In this case, I don't need to implement a Timer I guess since there is no callback.
2023-10-30 09:14 AM - edited 2023-10-30 09:29 AM
Hi,
I tried to adapt the code to my microprocessor but I don't know which one to choose? In your opinion ?
After me the SAI (equivalent to I2S) work with 3 possible modes: IRQ, DMA and IT. Probably, I'll start with IRQ to make it as simple as possible.
I do this but I get a warning. Do you know how to call the SAI function to retrieve the values ?
2023-10-30 11:58 AM
Source of the ST library is available. Please read the documentation in the library files (.h and c) , it is helpful. The compiler warnings are very helpful - please read them and try to understand the reason.
2023-10-31 01:01 AM
Hi,
Just to need the type and now It's correct.
uint8_t txData[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
start_receive ();
for(buf=0;buf<32;buf++){
for(index=0;index < AUDIO_BUF_SIZE;index++){
HAL_SAI_Transmit(&hsai_BlockB1,txData,1, 0xFF);
}
}
But in the example found on the internet the person uses the TransmitRrecieve command.
HAL_I2SEx_TransmitReceive(&hi2s2, &i2s_zero,&i2s_buf[buf][index], 1,0xFF);
Where to find in the documentation to find the right command to retrieve the values ?