cancel
Showing results for 
Search instead for 
Did you mean: 

How to launch IRTIM on STM32F030

valik mahrov
Associate II
Posted on April 01, 2018 at 12:36

Hello everyone, I had a question about how to run IRTIM on STM32F030. If there is an answer please tell me how to solve it?

11 REPLIES 11
Posted on April 02, 2018 at 15:22

What exactly is not clear in chapter 18  Infrared interface (IRTIM) of RM0360? There's even a code example in the appendix.

JW

valik mahrov
Associate II
Posted on April 02, 2018 at 15:40

But they run PB9 and not PA13 (IR_OUT).

valik mahrov
Associate II
Posted on April 02, 2018 at 16:30

Could you please reset the sample code using PA13 (IR_OUT).Thanks!

valik mahrov
Associate II
Posted on April 02, 2018 at 17:54

Thank!!!

valik mahrov
Associate II
Posted on April 02, 2018 at 18:16

Another minute of your attention. How to start PWM - TIM16 and TIM17 correctly? I set up IRTIM in CubeMX and set TIM16 to 'Output compare no byout' and TIM17 to 'PWM Generation no output' but it did not work.

Here is part of my code:

static void MX_TIM16_Init(void)

{

TIM_OC_InitTypeDef sConfigOC;

TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;

htim16.Instance = TIM16;

htim16.Init.Prescaler = 9;

htim16.Init.CounterMode = TIM_COUNTERMODE_UP;

htim16.Init.Period = 240;

htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim16.Init.RepetitionCounter = 0;

htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim16) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_OC_Init(&htim16) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sConfigOC.OCMode = TIM_OCMODE_TIMING;

sConfigOC.Pulse = 0;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

if (HAL_TIM_OC_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;

sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;

sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;

sBreakDeadTimeConfig.DeadTime = 0;

sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;

sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;

sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;

if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

/* TIM17 init function */

static void MX_TIM17_Init(void)

{

TIM_OC_InitTypeDef sConfigOC;

TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;

htim17.Instance = TIM17;

htim17.Init.Prescaler = 0;

htim17.Init.CounterMode = TIM_COUNTERMODE_UP;

htim17.Init.Period = 1263;

htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim17.Init.RepetitionCounter = 0;

htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim17) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_PWM_Init(&htim17) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 40;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

if (HAL_TIM_PWM_ConfigChannel(&htim17, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;

sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;

sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;

sBreakDeadTimeConfig.DeadTime = 0;

sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;

sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;

sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;

if (HAL_TIMEx_ConfigBreakDeadTime(&htim17, &sBreakDeadTimeConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

/** Configure pins as

* Analog

* Input

* Output

* EVENT_OUT

* EXTI

PA13 ------> IR_OUT

*/

static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOF_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_4, GPIO_PIN_RESET);

/*Configure GPIO pins : PA0 PA4 */

GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_4;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pin : PA13 */

GPIO_InitStruct.Pin = GPIO_PIN_13;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.Alternate = GPIO_AF1_IR;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

valik mahrov
Associate II
Posted on April 02, 2018 at 18:18

Modulation on the PA13 leg does not start.

Posted on April 02, 2018 at 16:19

Ok, but isn't that just a matter of pin configuration and AF mux setting, ie PA13 (AF1) vs PB9 (AF0), as either can be routed to IR_OUT

http://www.st.com/resource/en/datasheet/stm32f030f4.pdf

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
valik mahrov
Associate II
Posted on April 02, 2018 at 19:40

Yes. I use st-link v2. And that it off and delete?

Posted on April 02, 2018 at 17:45

 ,

 ,

Change the GPIO configuration, along the these lines

 , GPIO_InitStruct.Mode , , , , , = GPIO_MODE_AF_PP,

 ,

 , GPIO_InitStruct.Pull , , , , , = GPIO_NOPULL,

 ,

 , GPIO_InitStruct.Speed , , , , = GPIO_SPEED_FREQ_HIGH,

♯ if 1

 ,

 , __HAL_RCC_GPIOA_CLK_ENABLE(), // PA13 AF1

 ,

 , GPIO_InitStruct.Pin , , , , , , = GPIO_PIN_13,

 ,

 , GPIO_InitStruct.Alternate = GPIO_AF1_IR,

 , HAL_GPIO_Init(GPIOA, &,GPIO_InitStruct),

 ,

♯ else

 ,

 , __HAL_RCC_GPIOB_CLK_ENABLE(), // PB9 AF0

 ,

 , GPIO_InitStruct.Pin , , , , , , = GPIO_PIN_9,

 ,

 , GPIO_InitStruct.Alternate = GPIO_AF0_IR,

 , HAL_GPIO_Init(GPIOB, &,GPIO_InitStruct),

 ,

♯ endif
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..