stephendpmurphy / icm20948

📡 C Driver for the ICM-20948 9-Axis Telemetry sensor
MIT License
24 stars 7 forks source link

bank selection doesn't work properly #12

Open adambujak opened 3 years ago

adambujak commented 3 years ago

I think you need to shift it to the left by 4 because right now you are setting bits 0 and 1 as far as I can tell

stephendpmurphy commented 3 years ago

Hmmm, honestly haven't touched or used this since I wrote it. I thought I had tested accessing other banks but maybe not.. If you find this issue is true, please feel free to submit a PR to fix it. Otherwise, I will fix it once I get around to it 👍

zafbangash commented 5 months ago

I used this code recently, and can confirm while being very well structured, the bank selection is incorrect. for example:

dev.usr_bank.reg_bank_sel = ICM20948_USER_BANK_0;  // (whichever user bank it is, 0, 1, 2)  
// Write to the reg bank select to select bank 0
ret = _spi_write(ICM20948_ADDR_REG_BANK_SEL,  (uint8_t *)&dev.usr_bank.reg_bank_sel, 0x01);

can / should be replaced with

dev.usr_bank.bank0.bytes.REG_BANK_SEL.bits.USER_BANK = ICM20948_USER_BANK_0;    //(again, X being the bank) //// Write to the reg bank select to select bank 0
ret = _spi_write(ICM20948_ADDR_REG_BANK_SEL,& dev.usr_bank.bank0.bytes.REG_BANK_SEL.byte, 0x01);
stephendpmurphy commented 5 months ago

@zafbangash thanks for confirming this. Happy to review any PR back into the repo to get this fixed!