Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    bno055 PSoC read and write functions

    bno055 PSoC read and write functions

    frasics
    New Poster

    Hello, I am an engineering student at the University of the Fraser Valley and was directed to get into contact with you about accessing the BNO055 data. We are using the Adafruit breakout board with the bno055, and are using a Cypress microcontroller to try and access the data. We are having trouble understanding how to program the read and write functions, and have been trying for over a month with no success. I have read through the bno055.c and bno055_support.c files many times, as well as the datasheet, but we are still stuck. Any help you can provide would be greatly appreciated. Thank you, Fraser Forbes

    3 REPLIES 3

    Vincent
    Community Moderator
    Community Moderator

    1. which interface you are configured for BNO055? UART or I2C or HID over I2C?   it can be done by PS0 and PS1 pin status during power on the sensor.

    2. if you select I2C interface for BNO055, then normal I2C read / write function should be good enough to build up the communication between host and BNO055 chip.

    Thank you for your help and sorry for the late reply!

    We are using I2C. Our problem has been making the read and write fuctions since they seem to have have very specific protocols that I don't believe we are noticing.

    Here are the read/write functions from the support file that I am trying get functioning:

    s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
    {
    cnt = 1;
    s32 BNO055_iERROR = 0; // this is the "status" we usually use in our R/W functions
    u8 array[I2C_BUFFER_LEN];
    u8 stringpos =0;
    array[0] = reg_addr;
    for (stringpos = 0; stringpos<cnt; stringpos++)
    {
    array[stringpos+BNO055_I2C_BUS_WRITE_ARRAY_INDEX] = *(reg_data+stringpos);
    }
    BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
    BNO055_iERROR = I2C_MasterWriteByte(array[1]);
    BNO055_iERROR = I2C_MasterWriteByte(*reg_data);
    BNO055_iERROR = I2C_MasterSendStop();
    return (s8)BNO055_iERROR;

    }

    s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
    {
    dev_addr = dev_addr;
    s32 BNO055_iERROR = BNO055_INIT_VALUE; // the s32 error var is = 0 (bno055_init_value=0)
    u8 array[I2C_BUFFER_LEN]; // buffer_len = 8
    u8 stringpos = 0;
    array[0] = reg_addr; //set 0 of array to reg_addr

    BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
    BNO055_iERROR = I2C_MasterWriteByte(array[1]);
    BNO055_iERROR = I2C_MasterSendStop();

    for (stringpos = 0; stringpos < cnt; stringpos++) // counts through the entire reg_addr
    {
    BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_READ_XFER_MODE);
    array[stringpos] = I2C_MasterReadByte(I2C_ACK_DATA);// saves each byte to a different array pos
    *(reg_data + stringpos)=array[stringpos];
    }
    array[stringpos+1] = I2C_MasterReadByte(I2C_NAK_DATA);
    *(reg_data + stringpos)= array[stringpos];
    u8 comp =0;
    for(comp = 0;comp<cnt; comp++)
    {
    BNO055_iERROR =
    }
    BNO055_iERROR = I2C_MasterSendStop();

    return (s8) BNO055_iERROR;
    }

    void BNO055_delay_msek(u32 msek)
    {
    CyDelay(msek);
    }

    kgoveas
    Community Moderator
    Community Moderator

    Hi frasics,

    Could you try the following snippets for read and write?

    s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
    {
    	s32 BNO055_iERROR = 0; // this is the "status" we usually use in our R/W functions
    	u8 idx;
    	
    	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
    	// Check for BNO055_iERROR before proceeding
    	BNO055_iERROR = I2C_MasterWriteByte(reg_addr);
    	for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
    	{
    		BNO055_iERROR = I2C_MasterWriteByte(reg_data[idx]);
    	}
    	// Check for BNO055_iERROR before proceeding
    	BNO055_iERROR = I2C_MasterSendStop();
    	
    	return (s8)BNO055_iERROR;
    }
    
    s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
    {
    	s32 BNO055_iERROR = 0; // this is the "status" we usually use in our R/W functions
    	u8 idx;
    	
    	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_WRITE_XFER_MODE);
    	// Check for BNO055_iERROR before proceeding
    	BNO055_iERROR = I2C_MasterWriteByte(reg_addr);
    	// Check for BNO055_iERROR before proceeding
    	BNO055_iERROR = I2C_MasterSendStop();
    	
    	BNO055_iERROR = I2C_MasterSendStart(dev_addr, I2C_READ_XFER_MODE);
    	for (idx = 0; (idx < cnt) && (BNO055_iERROR == 0); idx++)
    	{
    		reg_data[idx] = I2C_MasterReadByte(I2C_ACK_DATA);
    	}
    	// Check for BNO055_iERROR before proceeding
    	BNO055_iERROR = I2C_MasterSendStop();
    
    	return (s8)BNO055_iERROR;
    }
    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