Thanks for the answer.
I tried to add Mutex to my code but my pico started to freeze after the code starts running.
void tof(void *param) {
(void)param;
Wire.setSDA(4);
Wire.setSCL(5);
Wire.begin();
Serial1.begin(115200);
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
vTaskDelay(50 / portTICK_PERIOD_MS);
Serial1.println(F("Both in reset mode...(pins are low)"));
Serial1.println(F("Starting..."));
setID();
while (1) {
if (xSemaphoreCreateRecursiveMutex() != NULL) {
if (xSemaphoreTake(mutex, 0) == pdTRUE) {
oku();
vTaskDelay(100 / portTICK_PERIOD_MS);
}
xSemaphoreGive(mutex);
} else {
}
}
}
void mputask(void *param) {
(void)param;
while (1) {
if (xSemaphoreCreateRecursiveMutex() != NULL) {
if (xSemaphoreTake(mutex, 0) == pdTRUE) {
vTaskDelay(500 / portTICK_PERIOD_MS);
// if programming failed, don't try to do anything
if (!dmpReady) return;
if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial1.print("MPU1\t");
Serial1.print(ypr[0] * 180 / M_PI);
Serial1.print("\t");
Serial1.print(ypr[1] * 180 / M_PI);
Serial1.print("\t");
Serial1.println(ypr[2] * 180 / M_PI);
#endif
}
/////////////////////////////////////////////////////////////////////////// 2. MPU veri alımı ////////////////////////////////////////////////////////////////////////////
Serial1.print("\r");
if (!dmp2Ready) return;
if (mpu2.dmpGetCurrentFIFOPacket(fifoBuffer2)) { // Get the Latest packet
#ifdef OUTPUT_READABLE_YAWPITCHROLL
mpu2.dmpGetQuaternion(&q2, fifoBuffer2);
mpu2.dmpGetGravity(&gravity2, &q2);
mpu2.dmpGetYawPitchRoll(ypr2, &q2, &gravity2);
Serial1.print("MPU2\t");
Serial1.print(ypr2[0] * 180 / M_PI);
Serial1.print("\t");
Serial1.print(ypr2[1] * 180 / M_PI);
Serial1.print("\t");
Serial1.println(ypr2[2] * 180 / M_PI);
#endif
}
}
xSemaphoreGive(mutex);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}