Skip to main content
Visitor II
October 31, 2023
Question

Unable to read registers from ISM330IS

  • October 31, 2023
  • 1 reply
  • 1036 views

Hello,

 

I am trying to get a ISM330IS IMU working. I have ordered a development kit from Mouser / ST Micro with the following board number https://www.mouser.in/ProductDetail/STMicroelectronics/STEVAL-MKI230KA?qs=amGC7iS6iy%252B%252BWAEBNHSnWw%3D%3D (photos are also attached).

 

sa32953_0-1698726755935.png

 

I have done the wiring referring to the User Manual Section 5.1. (photo is also attached). I am using a I2C to USB converter (photo is attached below) to read the data in a linux based Ubuntu 22.04 PC via library i2c-dev.

Link to User Manual I am following: https://www.st.com/resource/en/datasheet/ism330is.pdf

 

sa32953_1-1698726776353.png

 

sa32953_2-1698726776150.png

 

 

I am able to connect to the I2C bus and connect to Slave Address as per User Manual Section 5.1.1.1.

 

I am facing a problem: 

  1. When I am trying to read the IMU data through any register (for Temperature sensor or WHO_AM_I from user manual page 30), all the values are coming out to be zero constantly. I am unsure what the reason for this is. (I am not getting any kind of runtime errors).

 

Does someone have an idea why this could happen? Perhaps I am missing something to start the communication via I2C. Or something needs to be triggered before I start reading these registers on the sensor hub?

 

Here’s the code I am using:

 

 

void connect_i2c(std::shared_ptr<rclcpp::Node> imu_node){

		const char* i2cDevice = "/dev/i2c-1"; // I2C bus number
		
		i2cFile = open(i2cDevice, O_RDWR);

		// Open the I2C device file for reading
		if (i2cFile < 0) {
			perror("Failed to open the I2C device.");
		}
		else{
			std::cout << "I2C open successful" << "\n";
		}

 const uint8_t i2cAddress = 0b1101010; // I2C device's address

 if (ioctl(i2cFile, I2C_SLAVE, i2cAddress) < 0) {
			perror("Failed to set I2C address.");
		}	
		else{
			std::cout << "Slave open successful" << "\n";
		}

		// Write a command or data to initiate communication 
 //(replace 0x01 with your specific command)
		unsigned char command = 0x00;
		if (write(i2cFile, &command, 1) != 1) {
			std::cerr << "Failed to write data to the ISM330IS sensor" << std::endl;	
		}

 // This will run iteratively
		run_i2c(imu_node);
}


void run_i2c(std::shared_ptr<rclcpp::Node> imu_node){
		sleep(2);
		rclcpp::Rate loop_rate(5);
		while (rclcpp::ok())
		{
 int registerToRead = 0x0F; // Replace with the register address you want to read


			if (write(i2cFile, &registerToRead, 1) != 1) {
				perror("Error writing register address");
				//return 1;
			}

			uint8_t data;
			if (read(i2cFile, &data, 1) != 1) {
				perror("Error reading data");
				//std::cerr << "Error reading data" << std::endl;
				//return 1;
			}

			std::cout << "Data from register 0x" << std::hex << registerToRead << ": 0x" << static_cast<int>(data) << std::endl;

			
 loop_rate.sleep();
			rclcpp::spin_some(imu_node);
		}

 

 

 

 

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    November 3, 2023

    Hi @sa32953 ,

    Welcome to ST Community!

    From your photos it seems that you are connecting GND of the STEVAL to SCL of your board. Can you check this?