ubxlib icon indicating copy to clipboard operation
ubxlib copied to clipboard

uGnssPosGet sometimes fails with U_ERROR_COMMON_NOT_INITIALISED

Open KjartanOli opened this issue 9 months ago • 16 comments

I'm using ESP-IDF 5.2 with a TTGO LORA32 board connected to a ublox ZED-F9P via I2C. I call the following init function at the start of app_main to initialise the GNSS module and then proceed to simply call uGnssPosGet in a loop. Sometimes it simply works, others it returns -2 (U_ERROR_COMMON_NOT_INITIALISED). When it fails pressing the reset button on the TTLooking at the code of uGnssPosGet it appears to me to only return U_ERROR_COMMON_NOT_INITIALISED when gUGnssPrivateMutex == NULL GO usually makes it work again. This is is the part that really confuses me: if something is wrong with my code, why does rebooting the device make it work, if nothing is wrong with my code why does it only work some of the time?

auto init() -> std::int32_t
	{
		const uDeviceCfg_t gDeviceCfg = {
			.deviceType = U_DEVICE_TYPE_GNSS,
			.deviceCfg = {
				.cfgGnss = {
					.moduleType = U_GNSS_MODULE_TYPE_M9,
					.pinEnablePower = -1,
				}
			},
			.transportType = U_DEVICE_TRANSPORT_TYPE_I2C,
			.transportCfg = {
				.cfgI2c = {
					.i2c = 0,
					.pinSda = 21,
					.pinScl = 22,
					.alreadyOpen = false
				}
			}
		};
		auto status = uPortInit();
		ESP_LOGI(TAG.data(), "Port initialised: %ld", status);
		status = uPortI2cInit(); // You only need this if an I2C interface is used
		ESP_LOGI(TAG.data(), "I2C Port initialised: %ld", status);
		status = uDeviceInit();
		ESP_LOGI(TAG.data(), "Device initialised: %ld", status);
		status = uDeviceOpen(&gDeviceCfg, &gnssHandle);
		ESP_LOGI(TAG.data(), "Device opened: %ld", status);
		status = uPortI2cOpen(0, 21, 22, true);
		ESP_LOGI(TAG.data(), "Port opened: %ld", status);
		return status;
	}

Just in case its related: uPortI2cOpen seems to return -5, but that seems to happen regardless of whether uGnssPosGet is working or failing.

KjartanOli avatar May 22 '24 15:05 KjartanOli