How to use "portENTER_CRITICAL(&my_mutex)" with ESP32 ?

daemondong
Posts: 11
Joined: Fri Dec 24, 2021 7:20 am

How to use "portENTER_CRITICAL(&my_mutex)" with ESP32 ?

Postby daemondong » Fri Feb 25, 2022 3:33 pm

I'm working on MPU6050 with ESP32. It worked well as the below code. But when I added a gif playing task the code couldn't get the MPU6050 data sometime (half work and half bad). I raised the Priority of MPU6050 it didn't work. So I added the portENTER_CRITICAL(&my_mutex); and portExit_CRITICAL(&my_mutex); to make sure the MPU 6050 work alone but it caused WDT reset on CPU0. I tried disableCore0WDT(); and enableCore0WDT();. But it didn't work the WDT reset still occur always. Could anyone tell me how to figure this issue out ? Thank you very much.

Code: Select all

        //disableCore0WDT();
        //portENTER_CRITICAL(&my_mutex);
	    mpuIntStatus = mpu.getIntStatus();
		// get current FIFO count
		fifoCount = mpu.getFIFOCount();

	    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
	        // reset so we can continue cleanly
	        mpu.resetFIFO();

	    // otherwise, check for DMP data ready interrupt frequently)
	    } else if (mpuIntStatus & 0x02) {
	        // wait for correct available data length, should be a VERY short wait
	        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

	        // read a packet from FIFO

	        mpu.getFIFOBytes(fifoBuffer, packetSize);
	 		mpu.dmpGetQuaternion(&q, fifoBuffer);
			mpu.dmpGetGravity(&gravity, &q);
			mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        }
        //portENTER_CRITICAL(&my_mutex);
        //enableCore0WDT();


Who is online

Users browsing this forum: No registered users and 270 guests