xqueuereceive() data not all correct

kayleejacob1
Posts: 12
Joined: Mon Aug 17, 2020 1:39 pm

xqueuereceive() data not all correct

Postby kayleejacob1 » Tue Aug 18, 2020 1:50 pm

I am using latest IDF with Arduino in Visual studio visual micro.

I am trying to send dat from one task to another and the data is not coming through correct. Only one of the member of a struct are coming through correct. I am using xQueueOverwrite then xQueuePeek to check the data in the task sending and there appears to be issue there then using xQueueRecieve getting the same data of course as Peek.

Code one does not work Output is this
From Peek -peek freq256000.00 not correct

From Receive (Voltage25.67 value Correct) (freq 256000.00 not correct)

In code 2 all I do is uncomment two serial print line showing thdata going into xQueueOverwrite is correct and it works correct
output is correct but the order it prints is weird sense it should be read then peek but also why when I add this print back in does it work.

peek freq60.01
read Voltage60.01
Voltage25.67
60.01
peek freq60.01
read Voltage60.01
Voltage25.67
60.01
peek freq60.01
read Voltage59.98
Voltage25.68
59.98

Code 1

Code: Select all

TaskHandle_t loopi2cread;
QueueHandle_t readi2cdata;
typedef struct powerdata {
    //32BIT
float voltage;
float currentA;
float currentB;
float currentC;
float currentD;
int32_t activeA;
int32_t activeB;
int32_t activeC;
int32_t activeD;
int32_t reactiveA;
int32_t reactiveB;
int32_t reactiveC;
int32_t reactiveD;
uint32_t status2;
//16BIT
float freq;//hz = 0X256E3/(PERIOD15:0)+1
uint16_t pfa; //pf a
uint16_t pfb; //pf B
uint16_t pfc;//pf C
bool DirA;
bool DirB;
bool DirC;

 };
 
  readi2cdata = xQueueCreate(1, sizeof(powerdata));/////////////////error catch later if null through error
   
    xTaskCreatePinnedToCore( loopreadI2C, "i2cread",  2048,  NULL,5,&loopi2cread,0); /* Core where the task should run */

   xTaskCreatePinnedToCore(loopsaveI2C,"i2csave",2048,NULL,4,&loopi2csave,0); /* Core where the task should run */
   
void loopreadI2C(void* parameter) {
    //Serial.print("task read Started");
    powerdata data;
   // vTaskDelay(100 / portTICK_RATE_MS);
    for (;;) {

            ///we can later maybe take average of reading inbetween
             data = power.Get_Data();
            //Serial.print("read Voltage");
          //  Serial.println(data.voltage
              //Serial.println(data.freq);
            xQueueOverwrite(readi2cdata, &data);
        /
            vTaskDelay(1500 / portTICK_RATE_MS);
            xQueuePeek(readi2cdata, &data, 0);
           // xQueueSend(readi2cdata, &data, 0);
             Serial.print("peek freq");
             Serial.println(data.freq);
        
        
    }
}
    
void loopsaveI2C(void* parameter) {
 
    powerdata data;
      
   
    for (;;) {    
            xQueueReceive(readi2cdata, &data, portMAX_DELAY)) 
              
            
         
                    Serial.print("Voltage");
                    Serial.println(data.voltage);
                    Serial.println(data.freq);
                



               

         }

}

Who is online

Users browsing this forum: No registered users and 92 guests