cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 IrDA not work at all

Jong Hoo Yoon
Associate
Posted on June 28, 2017 at 13:39

Hi, every one.

I am trying to get data from IrDA SIR mode on STM32F092.

I setup that USART Port 2 is sending IrDA packet and USART Port 1 is receiving ( it similar to loop-back, wired USART2 TX and USART RX )

I can see the irda wave form on USART Port 2 TX Line, but I can't receive any data on USART Port 1.

I hope get any clue what am I missing

Thanks in advance.

Here is our code

IRDA_HandleTypeDef hirda_1;

IRDA_HandleTypeDef hirda_2;

void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)

{

   GPIO_InitTypeDef GPIO_InitStruct;

   if(hirda->Instance==USART1)

   {

      __HAL_RCC_USART1_CLK_ENABLE();

   GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;

   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

   GPIO_InitStruct.Pull = GPIO_NOPULL;

   GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

   GPIO_InitStruct.Alternate = GPIO_AF1_USART1;

   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

   }

   if(hirda->Instance==USART2)

   {

      __HAL_RCC_USART2_CLK_ENABLE();

      GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;

      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

      GPIO_InitStruct.Pull = GPIO_NOPULL;

      GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

      GPIO_InitStruct.Alternate = GPIO_AF1_USART2;

      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

   }

   }

void init_irda(int port )

{

if ( port == COM_SIR ) {

hirda_1.Instance = USART1;

hirda_1.Init.BaudRate = 115200;

hirda_1.Init.PowerMode = IRDA_POWERMODE_NORMAL;

hirda_1.Init.Parity = IRDA_PARITY_NONE;

hirda_1.Init.Prescaler = 1;

hirda_1.Init.Mode = IRDA_MODE_TX_RX;

hirda_1.Init.WordLength = IRDA_WORDLENGTH_8B;

if ( HAL_IRDA_Init(&hirda_1) != HAL_OK ) {

Printf('HAL IRDA INIT ERROR ---------\r\n');

}

} else if ( port == COM_BT ) {

   hirda_2.Instance = USART2;

   hirda_2.Init.BaudRate = 115200;

   hirda_2.Init.PowerMode = IRDA_POWERMODE_NORMAL;

   hirda_2.Init.Parity = IRDA_PARITY_NONE;

   hirda_2.Init.Prescaler = 1;

   hirda_2.Init.Mode = IRDA_MODE_TX_RX;

   hirda_2.Init.WordLength = IRDA_WORDLENGTH_8B;

   if ( HAL_IRDA_Init(&hirda_2) != HAL_OK ) {

   Printf('HAL IRDA INIT ERROR ---------\r\n');

   }

}

}

void irda_test()

{

   uint8_t Cmd[] = {0x80};

   uint8_t ret[10];

while(1) {

    int retval;

   memset(ret,0x0,5);

   Printf('Data Transmit\r\n');

   HAL_IRDA_Transmit(&hirda_2,(uint8_t *) Cmd,1,0xFFFF);

   retval = HAL_IRDA_Receive(&hirda_1,ret,1,1000);

   if ( retval != HAL_OK ) {

      Printf('HAL RECEIVE ERROR : %08x\r\n',retval);

   } else {

      Printf('Data Received : %02x\r\n',ret[0]);

   }

   JOSTimeDly(100);

   }

}

at Main.c 

{

<...>

init_irda(COM_SIR);

init_irda(COM_BT);

irda_test();

}

#irda #stm32f0
1 REPLY 1
Posted on June 28, 2017 at 16:26

https://community.st.com/0D50X00009XkXcMSAV

Can we please try not to have duplicative posts on materially the same theme

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