Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI323 SPI For stm32

    BMI323 SPI For stm32

    Noro
    New Poster

    Hello forum can you tell me how to intagrate API for stm32 spi please Thank You

    9 REPLIES 9

    Spoiler
    I need a simple implementation because I use a microcontroller. The API is very huge and there are a lot of functions that I don’t need and I don’t want to understand this, so I wrote these functions that don’t work properly, I get -32000 always on I did everything according to the datasheet, I tried to search on arduno uno using i2c everything works but not here

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Noro,

    Sensor API was written according data sheet description, support to be easily migrated to different host MCU.
    It is recommended that you use the sensor API to run it well first, then cut the code size.

    Spoiler
    I understand but you use RTOS and I don't it doesn't work for me I need a simple solution like reading and writing to the register via SPI I did this on arduino using I2C but it doesn't work on stm32, I use HAL

     

    //Write data in 16 bits
    void writeRegister16(uint16_t reg, uint16_t value) {
    Wire.beginTransmission(INC_ADDRESS);
    Wire.write(reg);
    //Low
    Wire.write((uint16_t)value & 0xff);
    //High
    Wire.write((uint16_t)value >> 8);
    Wire.endTransmission();
    }

    //Read data in 16 bits
    uint16_t readRegister16(uint8_t reg) {
    Wire.beginTransmission(INC_ADDRESS);
    Wire.write(reg);
    Wire.endTransmission(false);
    int n = Wire.requestFrom(INC_ADDRESS, 4);
    uint16_t data[20];
    int i =0;
    while(Wire.available()){
    data[i] = Wire.read();
    i++;
    }
    return (data[3] | data[2] << 8);
    }

    //Read all axis
    void readAllAccel() {
    Wire.beginTransmission(INC_ADDRESS);
    Wire.write(0x03);
    Wire.endTransmission();
    Wire.requestFrom(INC_ADDRESS, 20);
    uint16_t data[20];
    int i =0;
    while(Wire.available()){
    data[i] = Wire.read();
    i++;
    }

    //Offset = 2 because the 2 first bytes are dummy (useless)
    int offset = 2;
    x = ((data[offset + 1] << 8 | (uint16_t)data[offset + 0])); //0x03
    y = ((data[offset + 3] << 8 | (uint16_t)data[offset + 2])); //0x04
    z = ((data[offset + 5] << 8 | (uint16_t)data[offset + 4])); //0x05
    gyr_x = (data[offset + 7] << 8 | (uint16_t)data[offset + 6]); //0x06
    gyr_y = (data[offset + 9] << 8 | (uint16_t)data[offset + 8]); //0x07
    gyr_z = (data[offset + 11] << 8 | (uint16_t)data[offset + 10]); //0x08
    temperature = (data[offset + 13] << 8 | (uint16_t)data[offset + 12]); //0x09
    }

    code for arduino working 

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Noro,

    If you looked at the code for the previous attachment, the only hardware-related functions are the SPI write and read functions.
    Once the SPI read, write function is normal, the code will run.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist