ESP8266_NONOS_SDK vs Arduino Framework – Interrupt Differences?

Just for the record, I am a C# developer and tend to focus more on api’s and backends, firmware development / C / C++ is EXTRERMELY new to me!

I have been asked to port our existing ESP8266_NONOS_SDK project over to a newer framework for compatability and ease of use (the nonos_sdk is obsolete). After quite a bit of reading and reviewing I determined that the Arduino framework using PlatformIO as the best option (for me).

For the most part the transition worked out OK, I was able to create a project, add libraries i need, and generally get most of the base functionality working (IE: Connect to wifi and allow for OTA).

Now that i’ve proven the concept i need to move on to porting over our Interrupt’s which handle reading data from the Receiver in our device, and this is where I get stuck.

    LOCAL void ICACHE_FLASH_ATTR gpio_intr_handler(void *dummy)
    {
    static uint32 pulseCount, i;
    static uint8 invCRC;
    uint8 crcCalculated;
    volatile uint32 temp = 2500;
    uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);

    // if the interrupt was by GPIO14
    if (gpio_status & BIT(WROOM_DATA_IN_GPIO))
    {
        // disable interrupt for GPIO14
        gpio_pin_intr_state_set(GPIO_ID_PIN(WROOM_DATA_IN_GPIO), GPIO_PIN_INTR_DISABLE);
        // clear interrupt status for GPIO14
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(WROOM_DATA_IN_GPIO));
    
        // Calculate pulse width
        current_time = get_long_systime(); // system_get_time();
        pulseWidth = current_time - previous_time;
        previous_time = current_time;
        if (pulseWidth > 100)
        {
            pulseTime[pulseCount] = pulseWidth;
            pulseCount++;
        }
         }
    // Omitted as it's just calculations that I cannot share
    
    out:
        if (pulseWidth > MAX_WIDTH || pulseCount > MAX_PULSES)
        {
    
            pulseCount = 0;
            byteIndex = 0;
            bitIndex = 0;
            tag_alarm = 0;
            tag_batt = 0;
            tag_tlm = 0;
            for (i = 0; i < 5; i++)
                tagId[i] = 0;
        }
        // Reactivate interrupts for GPIO14
        gpio_pin_intr_state_set(GPIO_ID_PIN(WROOM_DATA_IN_GPIO), GPIO_PIN_INTR_ANYEDGE);

    }

This is the GPIO interrupt for the “Receiver” on GPIO pin 14, and this is copied from the ESP8266_nonos_sdk project where it works very well, however when I port this over to my arduino project, I get vastly different results.

Below is the updated Interrupt handler in my new arduino based project

    LOCAL void IRAM_ATTR gpio_intr_handler()
    {
    static uint32 pulseCount, i;
    static uint8 invCRC;
    uint8 crcCalculated;
    volatile uint32 temp = 2500;

    uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
    if (gpio_status & BIT(WROOM_DATA_IN_GPIO))
    {
        Serial.println("");
    
        // Disable GPIO14 Interrupt
        Serial.println("Detach Interrupt");
        detachInterrupt(digitalPinToInterrupt(WROOM_DATA_IN_GPIO));
    
        // clear interrupt status for GPIO14
        Serial.println("Clear GPIO Interrupt");
        // GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(WROOM_DATA_IN_GPIO));
        GPIO_OUTPUT_SET(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(WROOM_DATA_IN_GPIO));
    
        current_time = micros(); // system_get_rtc_time();
        pulseWidth = (current_time - previous_time);
        previous_time = current_time;
    
        Serial.print("Current Time: ");
        Serial.print(current_time);
        Serial.print(" Previous Time: ");
        Serial.print(previous_time);
        Serial.print(" Pulse Width: ");
        Serial.print(pulseWidth);
        Serial.print(" Pulse Count: ");
        Serial.println(pulseCount);
    
        if (pulseWidth > 100)
        {
            pulseTime[pulseCount] = pulseWidth;
            pulseCount++;
    
            Serial.print("Updated Pulse Count: ");
            Serial.println(pulseCount);
        }
    
        if (pulseWidth > MAX_WIDTH || pulseCount > MAX_PULSES)
        {
            pulseCount = 0;
            byteIndex = 0;
            bitIndex = 0;
            tag_alarm = 0;
            tag_batt = 0;
            tag_tlm = 0;
            for (i = 0; i < 5; i++)
                tagId[i] = 0;
        }
        attachInterrupt(digitalPinToInterrupt(USER_GPIO_IN), gpio_intr_handler, CHANGE);
     }

    }

Now, in the arduino framework version, I was able to add Serial.print so i could print out the current_time, previous_time and pulseWidth variables, but the data does not make any sense, this screenshot is the data that i’m seeing.

As I said I am extremely new to firmware development and I am using ChatGPT to guide me, and it was seeming like everything was working perfectly, until i got to this interrupt handler, this is the last big piece that I need to figure out.

I have tried repeatedly using different ways of “getting system time” but always end up with the current and previous time’s being identical and the pulseWidth being some crazy high value that does not make sense.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật