# IR - swm Source: [https://docs.qualcomm.com/doc/80-58740-4/topic/ir-swm.html](https://docs.qualcomm.com/doc/80-58740-4/topic/ir-swm.html) This demo mainly introduces IR to send and receive data in software mode. ## Hardware connection The GPIO used in this demo refers to `board_ir_gpio_init`. Connect the infrared transmitting diode and receiving head to the IR pin. The specific connection method is as follows (taking QCC74x\_undef as an example): | IR signal | External module | | --- | --- | | VCC | Infrared receiver VCC | | GND | Infrared receiver GND | | Rx | Infrared receiver OUT | | VCC | Infrared emitting diode anode | | Tx | Infrared emitting diode cathode | ## Software implementation For more detailed code, please refer to examples/peripherals/ir/ir\_swm. board_init();Copy to clipboard - `board_init` turns on the IR clock and select the IR clock source and frequency division. board_ir_gpio_init();Copy to clipboard - Configure related pins as `IR` function uint16_t tx_buffer[] = { 1777, 1777, 3555, 3555, 1777, 1777, 1777, 1777, 1777, 1777, 3555, 1777, 1777, 1777, 1777, 3555, 3555, 1777, 1777, 3555, 1777 }; struct qcc74x_ir_tx_config_s tx_cfg; irtx = qcc74x_device_get_by_name("irtx"); /* TX init */ tx_cfg.tx_mode = IR_TX_SWM; qcc74x_ir_tx_init(irtx, &tx_cfg);Copy to clipboard - Get `irtx` handle - Set tx\_mode to SWM mode and call `qcc74x_ir_tx_init(irtx, &tx_cfg)` to initialize IR Tx uint16_t rx_buffer[30]; uint8_t rx_len; struct qcc74x_ir_rx_config_s rx_cfg; irrx = qcc74x_device_get_by_name("irrx"); /* RX init */ rx_cfg.rx_mode = IR_RX_SWM; rx_cfg.input_inverse = true; rx_cfg.deglitch_enable = false; rx_cfg.end_threshold = 3999; qcc74x_ir_rx_init(irrx, &rx_cfg); /* Enable rx, wait for sending */ qcc74x_ir_rx_enable(irrx, true);Copy to clipboard - Get `irrx` handle - Set rx\_mode to SWM mode and call `qcc74x_ir_rx_init(irrx, &rx_cfg)` to initialize IR Rx - Call `qcc74x_ir_rx_enable(irrx, true)` to enable IR Rx and wait for data to be sent qcc74x_ir_swm_send(irtx, tx_buffer, sizeof(tx_buffer) / sizeof(tx_buffer[0])); rx_len = qcc74x_ir_swm_receive(irrx, rx_buffer, 30);Copy to clipboard - Call `qcc74x_ir_swm_send(irtx, tx_buffer, sizeof(tx_buffer) / sizeof(tx_buffer[0]))` to send the data in tx\_buffer - Call `qcc74x_ir_swm_receive(irrx, rx_buffer, 30)` to store the received data in rx\_buffer ## Experimental phenomena Press the RST button on the development board and the serial port prints the received data. **Parent Topic:** [IR](https://docs.qualcomm.com/doc/80-58740-4/topic/ir.html) Last Published: Feb 10, 2025 [Previous Topic IR - rc5](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/ir-rc5.md) [Next Topic UART](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/uart.md)