Array elements not assigned in loop
Posted: Fri May 21, 2021 4:42 am
Greetings,
I am beginner with ESP32 and using VSCode with PlatformIO plugin and Arduino framework.
Below is a code snippet:
If the above code is executed I get only elements filled with character 'a' only in MasterStatusTx.Byte and not in the MasterStatusRx.Byte. The output of LOOP VARIABLE line is printed on terminal with incrementing values of 'i'.
Also if the CONDITION A is changed to 'if(1)' then the elements of MasterStatusRx.Byte are filled as expected.
I am unable to what i am missing on. Any help appreciated.
Thanks
Amar
I am beginner with ESP32 and using VSCode with PlatformIO plugin and Arduino framework.
Below is a code snippet:
- struct MasterStatusDef
- {
- uint8_t members[40];
- };
- union
- {
- struct MasterStatusDef Value;
- uint8_t Byte[sizeof(struct MasterStatusDef)];
- }MasterStatusRx, MasterStatusTx;
- void setup()
- {
- xTaskCreatePinnedToCore(ProcessTask, "Process", 2048, NULL, 1, NULL, 0);
- ESP_LOGE(TAG,"initdone");
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
- void ProcessTask(void* pvParameters)
- {
- uint8_t i;
- for(;;)
- {
- bzero(MasterStatusRx.Byte, sizeof(MasterStatusRx.Byte));
- bzero(MasterStatusTx.Byte, sizeof(MasterStatusTx.Byte));
- for(i = 0; i < 5; i++)
- {
- MasterStatusTx.Byte[i] = 'a';
- if(i > 1) // **CONDITION A**
- {
- MasterStatusRx.Byte[i] = 'a';
- ESP_LOGE(TAG, "%d", i); // LOOP VARIABLE
- }
- }
- ESP_LOGE(TAG, "%s", MasterStatusRx.Byte);
- ESP_LOGE(TAG, "%s", MasterStatusTx.Byte);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
- }
Also if the CONDITION A is changed to 'if(1)' then the elements of MasterStatusRx.Byte are filled as expected.
I am unable to what i am missing on. Any help appreciated.
Thanks
Amar