Supported ICs

IC

RTL8721Dx

RTL8726E

RTL8720E

RTL8730E

Supported

Y

N

N

Y

Introduction

The Infrared (IR) module provides hardware-modulated transmission and automatic capture reception capabilities. This chapter details operational specifications.

This chapter introduces how to use IR.

IR Sending

Tx Polling Mode

To use IR sending function, the following steps are mandatory.

  1. Configure IR pin multiplexing according to the pinmux table.

    For example, in order to use PB4 as IR Tx pin, call the following function. It is the same for other IR pins.

    Pinmux_Config(_PB_4, PINMUX_FUNCTION_IR_TX);
    
  2. Call IR_Cmd() to disable IR.

  3. Set parameters, and modify some parameters if needed.

    IR_StructInit(IR_InitTypeDef *IR_InitStruct);
    
  4. Initialize the hardware using the parameters in Step 3.

    IR_Init(IR_InitTypeDef *IR_InitStruct);
    
  5. Write Tx data to FIFO by using IR_SendBuf() or IR_SendData().

  6. Call cIR_Cmd() to enable IR to start transmission.

  7. Write more data to FIFO if needed.

Note

  • In Step 2 to Step 6, It is suggested that disabling IR at first, and then enabling IR after writing data to FIFO.

  • In Step 5, pay attention to convert the data into the appropriate format that Tx FIFO register can recognize before writing data to FIFO.

Special Notes

Tx FIFO Offset Issue

If you want to judge whether Tx data in FIFO has been sent completely or not, you’d better check Tx FIFO empty flag rather than TX_FIFO_OFFSET.

Tx Last Packet Cannot Let FSM Enter Idle Issue

If the last packet written to Tx FIFO cannot let Tx state machine enter idle, it is suggested write some data packets to Tx FIFO before enabling IR Tx.

Refer to Step 2 to Step 6 in Section Tx Polling Mode.

IR Receiving

Rx Interrupt Mode

To use IR receiving function, the following steps are mandatory.

  1. Configure the IR pin according to the pinmux table.

    For example, in order to use PB5 as IR Rx pin, call the following function. It is the same for other IR pins.

    Pinmux_Config(_PB_5, PINMUX_FUNCTION_IR_RX);
    
  2. Set parameters, such as sampling frequency, Rx FIFO threshold level, Rx counter threshold type, Rx counter threshold level, and Rx trigger mode if needed.

    IR_StructInit(IR_InitTypeDef *IR_InitStruct);
    
  3. Initialize the hardware using the parameters in Step 2.

    IR_Init(IR_InitTypeDef *IR_InitStruct);
    
  4. Configure the interrupt if needed and register the interrupt callback function.

    IR_INTConfig(IR_DEV, IR_RX_INT_ALL_EN, ENABLE);
    InterruptRegister((IRQ_FUN) IR_irq_handler, IR_IRQ, (u32)NULL, 10);
    InterruptEn(IR_IRQ, 10);
    
  5. Call IR_Cmd() to enable IR.

  6. Call IR_ClearRxFIFO() to clear Rx FIFO.

  7. When Rx FIFO threshold interrupt triggers, read data from Rx FIFO with IR_ReceiveBuf() and IR_ReceiveData(), and make further processing in interrupt handle function.

Note

  • In Step 7, to decode the receiving data correctly, you should understand the data format in Rx FIFO register.

  • Waveform inverse issue: in Rx ending, if the waveform is inverse, you should define INVERSE_DATA in Ir_nec_protocol.h and set IR_InitStruct.IR_RxCntThrType = IR_RX_COUNT_HIGH_LEVEL.

Rx Learning

The process of Rx learning is similar to common Rx.

The difference is that in interrupt handle function, Rx learning should store each pulse of the Rx waveform, while common Rx only needs to store the carrier or un-carrier duration.

../../_images/difference_of_waveform_between_rx_learning_and_common_rx.svg

Difference of waveform between Rx learning and common Rx

Note

  • It is advised that putting the interrupt handle function code in RAM, and close other peripheral interrupts to avoid the interfere.

  • If the carrier frequency of learning waveform is larger than 400kHz, the hardware may cannot respond to the interrupt in time, which will result in decoding carrier frequency failed.