I am using RXB6 RF receiver with esp32 and the code is ESP-IDF. But I am not receiving any output from the receiver. Nothing is getting printed on the serial monitor. I have attached the code below. Please go through and help me.
What codes should I transmit from the RF transmitter or which rf remote should I use? Or is there any code to receive all the rf codes?
#include "esp32_rf_receiver.h"
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <freertos/queue.h>
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "esp_intr_alloc.h"
#include "sdkconfig.h"
#include "esp_log.h"
#include "include/output.h"
#include "esp_timer.h"
#define ADVANCED_OUTPUT 0
#define TAG "RF433"
static xQueueHandle s_esp_RF433_queue = NULL;
static const Protocol proto[] = {
{ 350, { 1, 31 }, { 1, 3 }, { 3, 1 }, false }, // protocol 1
{ 650, { 1, 10 }, { 1, 2 }, { 2, 1 }, false }, // protocol 2
{ 100, { 30, 71 }, { 4, 11 }, { 9, 6 }, false }, // protocol 3
{ 380, { 1, 6 }, { 1, 3 }, { 3, 1 }, false }, // protocol 4
{ 500, { 6, 14 }, { 1, 2 }, { 2, 1 }, false }, // protocol 5
{ 450, { 23, 1 }, { 1, 2 }, { 2, 1 }, true } // protocol 6 (HT6P20B)
};
enum {
numProto = sizeof(proto) / sizeof(proto[0])
};
volatile unsigned long nReceivedValue = 0;
volatile unsigned int nReceivedBitlength = 0;
volatile unsigned int nReceivedDelay = 0;
volatile unsigned int nReceivedProtocol = 0;
int nReceiveTolerance = 60;
const unsigned nSeparationLimit = 4300;
unsigned int timings[RCSWITCH_MAX_CHANGES];
static inline unsigned int diff(int A, int B) {
return abs(A - B);
}
bool receiveProtocol(const int p, unsigned int changeCount) {
const Protocol pro = proto[p-1];
unsigned long code = 0;
//Assuming the longer pulse length is the pulse captured in timings[0]
const unsigned int syncLengthInPulses = ((pro.syncFactor.low) > (pro.syncFactor.high)) ? (pro.syncFactor.low) : (pro.syncFactor.high);
const unsigned int delay = timings[0] / syncLengthInPulses;
const unsigned int delayTolerance = delay * nReceiveTolerance / 100;
const unsigned int firstDataTiming = (pro.invertedSignal) ? (2) : (1);
for (unsigned int i = firstDataTiming; i < changeCount - 1; i += 2) {
code <<= 1;
if (diff(timings, delay * pro.zero.high) < delayTolerance &&
diff(timings[i + 1], delay * pro.zero.low) < delayTolerance) {
// zero
} else if (diff(timings, delay * pro.one.high) < delayTolerance &&
diff(timings[i + 1], delay * pro.one.low) < delayTolerance) {
// one
code |= 1;
} else {
// Failed
return false;
}
}
if (changeCount > 7) { // ignore very short transmissions: no device sends them, so this must be noise
nReceivedValue = code;
nReceivedBitlength = (changeCount - 1) / 2;
nReceivedDelay = delay;
nReceivedProtocol = p;
return true;
}
return false;
}
// -- Wrappers over variables which should be modified only internally
bool available() {
return nReceivedValue != 0;
}
void resetAvailable() {
nReceivedValue = 0;
}
unsigned long getReceivedValue() {
return nReceivedValue;
}
unsigned int getReceivedBitlength() {
return nReceivedBitlength;
}
unsigned int getReceivedDelay() {
return nReceivedDelay;
}
unsigned int getReceivedProtocol() {
return nReceivedProtocol;
}
unsigned int* getReceivedRawdata() {
return timings;
}
// ---
void data_interrupt_handler(void* arg)
{
static unsigned int changeCount = 0;
static unsigned long lastTime = 0;
static unsigned int repeatCount = 0;
const long time = esp_timer_get_time();
const unsigned int duration = time - lastTime;
if (duration > nSeparationLimit) {
if (diff(duration, timings[0]) < 200) {
repeatCount++;
if (repeatCount == 2) {
for(uint8_t i = 1; i <= numProto; i++) {
if (receiveProtocol(i, changeCount)) {
uint8_t protocol_num = (uint8_t)i;
xQueueSendFromISR(s_esp_RF433_queue, &protocol_num, NULL);
break;
}
}
repeatCount = 0;
}
}
changeCount = 0;
}
// detect overflow
if (changeCount >= RCSWITCH_MAX_CHANGES) {
changeCount = 0;
repeatCount = 0;
}
timings[changeCount++] = duration;
lastTime = time;
}
void receiver_rf433(void* pvParameter)
{
uint8_t prot_num = 0;
while(1)
{
if (xQueueReceive(s_esp_RF433_queue, &prot_num, portMAX_DELAY) == pdFALSE) {
ESP_LOGE(TAG, "RF433 interrurpt fail");
}
else {
ESP_LOGW(TAG, "Received %lu / %dbit Protocol: %d.\n", getReceivedValue(), getReceivedBitlength(), prot_num);
resetAvailable();
}
}
}
void app_main()
{
if (s_esp_RF433_queue == NULL) {
s_esp_RF433_queue = xQueueCreate(1, sizeof(uint8_t));
if (s_esp_RF433_queue != NULL) {
// Configure the data input
gpio_config_t data_pin_config = {
.intr_type = GPIO_INTR_ANYEDGE,
.mode = GPIO_MODE_INPUT,
.pin_bit_mask = GPIO_SEL_22, // GPIO_NUM_22 (SEL) DATA PIN!
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE
};
gpio_config(&data_pin_config);
// Attach the interrupt handler
gpio_install_isr_service(ESP_INTR_FLAG_EDGE);
gpio_isr_handler_add(GPIO_NUM_22, data_interrupt_handler, NULL); // GPIO_NUM_22 DATA PIN!
xTaskCreate(&receiver_rf433, "receiver_rf433", 2048, NULL, 3, NULL);
}
}
}
3400RF with ESP-IDF
-
- Posts: 5
- Joined: Mon Jun 27, 2022 10:44 am
Return to “General Discussion”
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Baidu [Spider] and 99 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.