element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Problem getting data from ST-WINBX1 sensors
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: embeddedguy
  • Date Created: 26 Aug 2025 9:16 AM Date Created
  • Views 520 views
  • Likes 4 likes
  • Comments 7 comments
  • RoadTest
  • stm32
  • stwinbx1
Related
Recommended

Problem getting data from ST-WINBX1 sensors

embeddedguy
embeddedguy
26 Aug 2025

Hello Element14 Community members,

I have been working on element14 roadtest for ST-WINBX1 and wanted to know about the problem that I am facing to get the sensor data.

I am using Zephyr OS. I am getting the data for one accelerometer but after that I could not get the data out of sensor. I do not know what could have gone wrong but the chances of sensors being damage are rare.

Here is a sample code that is not working as expected. For the first sensor, I am getting the correct data. But for the next one and many others, I get no data.?

 

  if (sensor_sample_fetch(acc)) {
            printk("sensor_sample fetch failed\n");
        }

        sensor_channel_get(acc, SENSOR_CHAN_ACCEL_X, &accx);
        sensor_channel_get(acc, SENSOR_CHAN_ACCEL_Y, &accy);
        sensor_channel_get(acc, SENSOR_CHAN_ACCEL_Z, &accz);

        printk("Acceleromer X: %f Acceleromer Y: %f Acceleromer Z: %f\n", sensor_value_to_double(&accx), sensor_value_to_double(&accy), sensor_value_to_double(&accz));

        k_sleep(K_MSEC(50));

        if (sensor_sample_fetch(acchp)) {
            printk("sensor_sample fetch failed\n");
        }

        sensor_channel_get(acchp, SENSOR_CHAN_ACCEL_XYZ, &hpaccx);
        sensor_channel_get(acchp, SENSOR_CHAN_ACCEL_XYZ, &hpaccy);
        sensor_channel_get(acchp, SENSOR_CHAN_ACCEL_XYZ, &hpaccz);

        printk("Acceleromer X: %f Acceleromer Y: %f Acceleromer Z: %f\n", sensor_value_to_double(&hpaccx), sensor_value_to_double(&hpaccy), sensor_value_to_double(&hpaccz));

More Information

Here is the more information regarding the issue.

I am first getting the device using compatible, as used by Zephyr to get a device struct using compatible property. 

static const struct device *acc = DEVICE_DT_GET_ANY(st_iis2dlpc);
static const struct device *acchp = DEVICE_DT_GET_ANY(st_ism330dhcx);
static const struct device *absprs = DEVICE_DT_GET_ANY(st_ilps22qs);
static const struct device *tmps = DEVICE_DT_GET_ANY(st_stts22h);
static const struct device *magt = DEVICE_DT_GET_ANY(st_iis2mdc);
Once I have the device struct, I check for weather the device is ready to be used using device_is_ready(device) function. I do not get error on any of these lines.
if(!device_is_ready(acc)) {
        printk("Accelerometer is not ready");
        return 0;
    }
    k_sleep(K_MSEC(50));

    if(!device_is_ready(acchp)) {
        printk("High-p Accelerometer is not ready\n");
        return 0;
    }
    k_sleep(K_MSEC(50));
After these I have variables to store received sensor values from the channels that they define. Each sensor defines set of channels, and we have to be carefully to select them.
struct sensor_value accx, accy, accz;
struct sensor_value hpaccx, hpaccy, hpaccz;
struct sensor_value abspress;
Once this is done the above code should print the values. But for the second sensor that is device *acchp I do not get data. Same is for many other sensors.

More Information

So, if you look at the following diagram, most of the sensors I am using, are connected on SPI2 and I2C2 bus. 

After build I can check which bus is enabled or disabled in the final build and they are all enabled correctly. Even if they are not, I would get error to initialize the sensor, the device_is_ready() will let me know.

If say sensor/s is damaged, then also it will not init. I have verified from the code that the channels that I am using are correct channels. i.e. SENSOR_CHAN_AMBIENT_TEMP, etc.

Even the Bluetooth is working that is connected on SPI bus. Most other modules are working. Sensors are being initialized, and their address is printed. But the values are not. 

Each sensor has real and fractional part. So I tried to print only real part if that could be an issue but seems that is also not a problem.

Sometimes we have to enable the CS line for SPI sensor, but that is handled by the driver itself in this case. 

image

Here is the board.dts file

&spi2 {
	pinctrl-0 = <&spi2_sck_pi1 &spi2_miso_pd3 &spi2_mosi_pi3>;
	pinctrl-names = "default";
	status = "okay";

	cs-gpios = <&gpioh 6 GPIO_ACTIVE_LOW>,
		   <&gpioh 15 GPIO_ACTIVE_LOW>,
		   <&gpioi 7 GPIO_ACTIVE_LOW>;
		  

	iis2dlpc: iis2dlpc@0 {
		compatible = "st,iis2dlpc";
		spi-max-frequency = <DT_FREQ_M(10)>;
		reg = <0>;
		drdy-gpios = <&gpiof 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		drdy-int = <1>;
	};

	ism330dhcx: ism330dhcx@1 {
		compatible = "st,ism330dhcx";
		spi-max-frequency = <DT_FREQ_M(10)>;
		reg = <1>;
		drdy-gpios = <&gpiob 8 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		int-pin = <1>;
	};

	iis2iclx: iis2iclx@2 {
		compatible = "st,iis2iclx";
		spi-max-frequency = <DT_FREQ_M(10)>;
		reg = <2>;
		drdy-gpios = <&gpiof 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		int-pin = <2>;
	};
};

&spi3 {
	pinctrl-0 = <&spi3_sck_pg9 &spi3_miso_pb4 &spi3_mosi_pb5>;
	pinctrl-names = "default";
	status = "okay";
	cs-gpios = <&gpioe 1 GPIO_ACTIVE_LOW>;

	hci_spi: bluenrg-2@0 {
		compatible = "st,hci-spi-v2";
		reg = <0>;
		reset-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>;
		irq-gpios = <&gpiof 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
		spi-cpha; /* CPHA=1 */
		spi-hold-cs;
		spi-max-frequency = <DT_FREQ_M(1)>;
		reset-assert-duration-ms = <6>;
	};
};

&i2c2 {
	pinctrl-0 = <&i2c2_scl_ph4 &i2c2_sda_pf0>;
	pinctrl-names = "default";
	status = "okay";
	clock-frequency = <I2C_BITRATE_FAST>;

	stts22h@3f {
		compatible = "st,stts22h";
		reg = <0x3f>;
		int-gpios = <&gpiof 5 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	iis2mdc@1e {
		compatible = "st,iis2mdc";
		reg = <0x1e>;
		drdy-gpios = <&gpiof 9 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	ilps22qs@5c {
		compatible = "st,ilps22qs";
		reg = <0x5c>;
		status = "okay";
	};
};

  • Sign in to reply
  • embeddedguy
    embeddedguy 1 month ago in reply to BigG

    Hi, Thanks for your efforts.

    Anyways, I have set the sensor configs to right settings. If I do not, it will have built time error. Zephyr is changing fast. Previously, if I remember correctly I have to manually add all the sensors that I am using like

    CONFIG_SENSORNAME_XYZ = y

    Now it just works with CONFIG_SENSOR=y

    I also believe that if incase sensor_sample_fetch() is failed it will through error to me.

    CONFIG_GPIO=y
    CONFIG_I2C=y
    CONFIG_SENSOR=y
    
    CONFIG_DISK_ACCESS=y
    CONFIG_LOG=y
    CONFIG_FILE_SYSTEM=y
    CONFIG_FAT_FILESYSTEM_ELM=y
    CONFIG_PRINTK=y
    CONFIG_MAIN_STACK_SIZE=2048
    
    CONFIG_SPI=y
    CONFIG_DISK_DRIVER_SDMMC=y
    
    CONFIG_SHELL=y
    
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    CONFIG_BT=y
    
    CONFIG_BT_DEVICE_NAME="Element14-RoadTest"
    CONFIG_ADC=y
    CONFIG_RTC=y

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • BigG
    BigG 1 month ago in reply to embeddedguy

    Ok. The board is listed in Zephyr: https://docs.zephyrproject.org/latest/boards/st/steval_stwinbx1/doc/index.html

    Also all sensors have yaml files, which makes it easier.

    E.g. https://docs.zephyrproject.org/latest/build/dts/api/bindings/sensor/st%2Cism330dhcx-spi.html#dtbinding-st-ism330dhcx-spi

    https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/st/steval_stwinbx1/steval_stwinbx1.dts?plain=1#L169

    Anyway, if sensor_sample_fetch() is not retrieving data, then have you set CONFIG_SENSOR=y in prj.conf?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • embeddedguy
    embeddedguy 1 month ago in reply to BigG

    No, not yet. I have not tried it today, but I will try it again.
    But it won't work maybe because the board is not tested with Zephyr. Or there is some other version of sensor the driver is. This is my assumption. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • BigG
    BigG 1 month ago in reply to embeddedguy

    I see you added further info. So is sensor_sample_fetch() retrieving data or not?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • BigG
    BigG 1 month ago in reply to embeddedguy

    It might help with your problem solving by creating a separate example just for the acchp sensor. It might also be worth checking the driver code for the standard function sensor_sample_fetch() to see what data is actually captured. Are you confident that the i2c driver for that sensor is working correctly, for example.

    If all ok, then I'm convinced it's data structure related. There is a sample available in the sensors folder (lsm303dlhc), which uses the follow code to capture the data. Note the struct sensor_value is an array (val[3]).

    static int32_t read_sensor(const struct device *sensor,
    			   enum sensor_channel channel)
    {
    	struct sensor_value val[3];
    	int32_t ret = 0;
    
    	ret = sensor_sample_fetch(sensor);
    	if (ret < 0 && ret != -EBADMSG) {
    		printf("Sensor sample update error\n");
    		goto end;
    	}
    
    	ret = sensor_channel_get(sensor, channel, val);
    	if (ret < 0) {
    		printf("Cannot read sensor channels\n");
    		goto end;
    	}
    
    	printf("( x y z ) = ( %f  %f  %f )\n", sensor_value_to_double(&val[0]),
    					       sensor_value_to_double(&val[1]),
    					       sensor_value_to_double(&val[2]));
    
    end:
    	return ret;
    }
    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube