Page 1 of 1

xEventGroupSetBits don't trigger xEventGroupWaitBits when using UART

Posted: Wed Sep 13, 2017 6:18 pm
by Prasad
I'm using event group to keep wait until one of my processes finishes. My process is sending one AT command over UART and receive the feedback over UART. But problem is it works when i execute xEventGroupSetBits right before read UART bytes using uart_read_bytes, But it won't work if i set bits after uart_read_bytes . Please see below code,

This is the function i use to read the feedback from UART once i sent an AT command request,

Code: Select all

char* get_at_response(uart_port_t uart_num) {

	char* result = NULL;
	while (1) {

		uint8_t* data = (uint8_t*) malloc(BUF_SIZE);

		xEventGroupSetBits(gsm_event_group, GSM_0_DONE_BIT | GSM_1_DONE_BIT);//This works

		int len = uart_read_bytes(uart_num, data, BUF_SIZE,
				20 / portTICK_RATE_MS);

		xEventGroupSetBits(gsm_event_group, GSM_0_DONE_BIT | GSM_1_DONE_BIT);//This does not work

		char payloadChr[len];

		if (len > 1) {

			for (int i = 0; i < len; i++) {
				char c = (char) data[i];
				payloadChr[i] = c;

			}

			result = (char*) malloc(sizeof(payloadChr) + 1);
			strncpy(result, payloadChr, sizeof(payloadChr) + 1);

		}
		break;
	}

	return result;
}
This is what i'm calling from main task,

Code: Select all

void app_main() {

gsm_event_group = xEventGroupCreate();

	xReturned = xTaskCreate(init_task, "init_task", 2048, GSM_0, 3, &xHandle);

	EventBits_t uxBits;

	while (1) {
		ESP_LOGI(TAG, "WAITING...");
		uxBits = xEventGroupWaitBits(gsm_event_group,
		GSM_0_DONE_BIT | GSM_1_DONE_BIT, true, false, portMAX_DELAY);
		if (uxBits & GSM_0_DONE_BIT) {
			vTaskDelete(xHandle);
			xReturned = xTaskCreate(init_task, "init_task", 2048, GSM_1, 3,
					&xHandle);
		}
		if (uxBits & GSM_1_DONE_BIT) {
			vTaskDelete(xHandle);
		}
	}
	}
Can anyone tell me what am i missing here please?