GithubHelp home page GithubHelp logo

mokhwasomssi / stm32_hal_icm20948 Goto Github PK

View Code? Open in Web Editor NEW
46.0 3.0 16.0 14.24 MB

ICM-20948 library with STM32 HAL driver

C 99.44% Assembly 0.47% Makefile 0.09%
stm32 spi sensor imu stm32f4 icm20948 mpu9250 stm32hal

stm32_hal_icm20948's Issues

Accel LPF Assignement

Hello. Thank you for writing this driver. I'm currently adapting it to be useful for a different IMU but STM32 friendly.

void icm20948_accel_low_pass_filter(uint8_t config)
{
	uint8_t new_val = read_single_icm20948_reg(ub_2, B2_ACCEL_CONFIG);
	new_val |= config << 3;

	write_single_icm20948_reg(ub_2, B2_GYRO_CONFIG_1, new_val);
}

I wanted to point out that the registers here do not line up. I think this is a simple typo, and it likely will not have much of an effect, but it would likely be a good idea to fix this before it affects someone's project.

icm20948 i2c

Hello again ,
I make read write function separately reading all register giving me just right value except b0_control reg of bank 0 and B0_EXT_SLV_SENS_DATA_00 , B0_EXT_SLV_SENS_DATA_00 giving me zero value again and again , I am just verifying whoiam of magnetometer . I am adding all codes here please give a small review on that .

static void magnetometer()
{
select_bank(0);
read_data(0,B0_USER_CTRL);
write_data(0,B0_USER_CTRL,0x22,2);
read_data(0,B0_USER_CTRL);
write_data(0,B0_USER_CTRL,0x22,2);
read_data(3,B3_I2C_MST_CTRL);
write_data(3,B3_I2C_MST_CTRL,0x07,2);
read_data(3,B3_I2C_MST_CTRL);
write_data(3,B3_I2C_SLV0_ADDR,0x8C,2);
read_data(3,B3_I2C_SLV0_ADDR);
write_data(3,B3_I2C_SLV0_REG,0x01,2);
read_data(3,B3_I2C_SLV0_REG);
write_data(3,B3_I2C_MST_CTRL,0x81,2);
read_data(3,B3_I2C_MST_CTRL);
nrf_delay_ms(10);
select_bank(0);
read_data(0,B0_EXT_SLV_SENS_DATA_00);
}
void write_data(uint8_t ub , uint8_t regaddress , uint8_t regdata , uint8_t size)
{
writeregaddress=regaddress;
writeregdata=regdata;
len = size;
writeub=ub;
nrf_delay_ms(10);
select_bank(writeub);
nrf_delay_ms(10);
uint8_t writedata[2] = {writeregaddress , writeregdata};
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr ,writedata,len, true);
APP_ERROR_CHECK(err_code);
}

void read_data(uint8_t ub , uint8_t regaddress)
{
writeub=ub;
readregaddress=regaddress;
nrf_delay_ms(10);
select_bank(writeub);
nrf_delay_ms(10);
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr ,&readregaddress,1, true);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(10);
read_sensor_data();
}

void select_bank(uint8_t bankselectvalue)
{
funbankselect=bankselectvalue;
shifted_value=funbankselect<<4;
bank[0]=bankselect;
bank[1]=shifted_value;
err_code = nrf_drv_twi_tx(&m_twi, ICM20948addr,bank,2, false);
APP_ERROR_CHECK(err_code);
}

void read_sensor_data()
{
m_xfer_done = false;
//NRF_LOG_INFO("1");
//NRF_LOG_FLUSH();

/* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
ret_code_t err_code = nrf_drv_twi_rx(&m_twi,ICM20948addr ,& m_sample, 1);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("%x",m_sample);
NRF_LOG_FLUSH();
}

int main()
{
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("\r\nTWI sensor example started.");
NRF_LOG_FLUSH();
twi_init();
NRF_LOG_INFO("1");
NRF_LOG_FLUSH();
//ICM();
magnetometer();
NRF_LOG_INFO("end icm");

NRF_LOG_FLUSH();
}
and these are logs

app:
TWI sensor example started.
app: 1
app: 0
app: Register value = 32
app: 20
app: Register value = 32
app: 20
app: Register value = 129
app: 81
app: Register value = 7
app: 7
app: Register value = 140
app: 8C
app: Register value = 1
app: 1
app: Register value = 129
app: 81
app: Register value = 0
app: end icm

please reply , Thanks in advance.

Friendly Register Assignments

Hi again. I can't help but notice that the way you assign values to registers is not friendly or... safe?

void icm20948_clock_source(uint8_t source)
{
	uint8_t new_val = read_single_icm20948_reg(ub_0, B0_PWR_MGMT_1);
	new_val |= source;

	write_single_icm20948_reg(ub_0, B0_PWR_MGMT_1, new_val);
}

In this snippet, you |= two values, but if I used a number like 0x41 instead of 0x01 here, I could theoretically put the chip into sleep instead of correctly setting the clock source.

Now, in the event that I wanted to set the clock source as 0x07, which I think is valid, and then later change it back to 0x01, I could not with your code.

Consider redoing your assignments to something that clears the bits for the field in the register before OR-ing them.

new_val = (new_val & 0xF8) | (source & 0x07);

would be a much safer way of preventing accidental changes to registers/configs, I think. Nearly every register config function should probably be updated like this.

I want to retrieve data in nrf52840 .

I have been doing efforts to do the same thing on NRF52840 with I2C , I have configured every register right but not get the desired data , It is giving me same value again and again and value is not changing at any time , Can you please help to me in that . Thanks in advance .This is code and its showing logs like that . [
code icm20948.txt
logs.txt
](url)

the bug in icm20948.c

Hi, I've found the bug in icm20948.c file.

void icm20948_accel_low_pass_filter(uint8_t config)
{
uint8_t new_val = read_single_icm20948_reg(ub_2, B2_ACCEL_CONFIG);
new_val |= config << 3;

// Bug !!! write_single_icm20948_reg(ub_2, B2_GYRO_CONFIG_1, new_val);
write_single_icm20948_reg(ub_2, B2_ACCEL_CONFIG, new_val);

}

Best Regards
James

Incorrect accelerometer data

When calling the function void icm20948_accel_read_g (axises * data); I am getting readings in g that do not have negative values. And the readings can be as high as 2.5g.

I also noticed that when receiving data from the gyroscope, some indication is remembered and in the future it is added to the gyroscope data

I am using STM32 Discovery board with STM32F407vgt chip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.