This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GXL: I2C Communication and the bno055

Okay, I will do my best to keep this question succinct and understandable! Thanks in advance for any advice.

I have been working on a project involving the bno055 IMU board from bosch. I managed to successfully talk with the board via UART but am switching to I2C in order to use the BoschSensorTec bno055 Driver Library. And it's additional functionality. This has proved challenging, though. I am not nearly as familiar with I2C as I am with UART but I have been reading up and watching video tutorials to understand its protocol.

The library is a .c file and a .h file, but in order to integrate the library into my project I have to write I2C driver bus read and bus write functions and link them to communication function pointers in the bosch API. What I am trying to make sure of is that the Tivaware I2C functions will function in a way that is compatible with the bno055.  The picture below is from page 92 of the bno055 datasheet.

Let's focus on the simpler "Write" sequence for now, at the top of the picture. If I write this chunk of code, will it correctly do this?

void bno_write(u8 dev_address, u8 reg_address){
	I2CMasterSlaveAddrSet(I2C0_BASE, dev_address, false);
	
	I2CMasterDataPut(I2C0_BASE, reg_address);
	
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
	
	while(I2CMasterBusy(I2C0_BASE));
	if (I2CMasterErr(I2C0_BASE) == true){
		printf("Write Error. \n");
	}
}

I'm not sure what's happening when I call these big I2C functions. If I set the slave address, load in the data to be sent, then call the I2CMasterControl single send command, will it do what the bno055 requires in the picture? Such as wait for acks from the bno055 before continuing from address to register address to data? My biggest problem is that I am unsure of what the I2C functions that I write - BNO055_I2C_bus_read and bus_write in the picture I included - need to be doing.

I apologize if this question is incorrectly phrased. I am still sorting out the truckload of concepts here, and my mind is a bit frazzled from pouring through 6 PDFs (three on the bno055, two on the tiva, and one on i2c communication).

Thank you!

  • Hello Zero PD,

    I would be adding another PDF to the read list. The TM4C129x application note for I2C, especially the section which shows what happens when specific commands are given using I2CMasterControl.

    www.ti.com/.../spma073.pdf

    Regards
    Amit
  • Amit,

    Thank you. I believe that document was the missing piece I couldn't wrap my head around - the description of what the master control commands are doing.

    Let me ask you this. Take a quick look at the top of that picture I included last time, the section I2C Write Access. In it, it says I need to:

    1. Send a Start Bit
    2. Send the Slave Address
    3. Get an Ack back from the Slave
    4. Send the Register Address
    5. Get an Ack Back from the Slave
    6. Send the Data byte
    7. Get an Ack back from the Slave
    8. Send a Stop Bit.

    So to do that, after reading the document you sent me, I should have to write a function that:

    1. Loads the Slave Address
    2. Loads the Register Address into the i2c master data register.
    3. Calls I2C Master Control ( I2C Master CMD Burst Send Start ) to send the slave address, wait for an ack from the slave, then send the register address, get an ack back from the slave, but not send a stop bit.
    4. polls the i2c master busy to wait for the send to finish
    5. Loads the data byte into i2c master data register.
    6. Calls I2C Master Control ( I2C Master CMD Burst Send Finish ) to send the data byte and then a stop bit.

    Here is the code I wrote:

    void i2c_wait(void){
    	while(I2CMasterBusy(I2C0_BASE));
    	if (I2CMasterErr(I2C0_BASE) == true){
    		printf("Write Error. \n");
    	}
    }
    
    s8 bno_write(u8 dev_address, u8 reg_address, u8 DataPacket[10], u8 data){
    	I2CMasterSlaveAddrSet(I2C0_BASE, dev_address, false);
    	I2CMasterDataPut(I2C0_BASE, reg_address);
    	
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    	I2CMasterDataPut(I2C0_BASE, data);
    	i2c_wait();
    	delay_ms(5);
    	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    	i2c_wait();
    	return I2CMasterErr(I2C0_BASE);
    }

    Does my thought process appear correct to you? The only thing that confuses me is the internals of the Master Control functions. Is there blocking code that waits for an Ack back from the slave device? If it doesn't get an ack back, does it set i2c master error boolean to true and continue or abort the operation?

    
    

  • Hello Zero_PD,

    It seems correct except that after i2c_wait gas to come after the I2CMasterControl. The first wait has to before the I2CMasterDataPut(I2C0_BASE, data).

    Regards
    Amit
  • Thanks for all your help, Amit.

    If anyone else is ever trying to use the bno055 with their tiva, I spent a week banging my head against the while but finally integrated Bosch's bno055 C Library into my project. It's a very powerful library and can make your life a lot easier if you want to use adafruit's bno055 breakout board but you are not using an Arduino microcomputer. I wrote a guide to document the process and have attached the pdf. While it's written from the perspective of the TM4C123 Tiva, it should be very useful for anyone trying to integrate the library into their microcomputer project.

    Good luck.

    1738.Guide - How to Integrate BNO055 Library into Tiva Launchpad Project.pdf

  • Hello Zero_PD,

    We appreciate forum contribution, though I have not reviewed the document as of now, but surely your experience into the development and it being documented is a great step for others using the same or planning to do so.

    Regards
    Amit
  • Hi Zero_PD

    Could you please share the piece of code that you used for communication over UART? especially the sequence of setting the BNO055 to one of the modes.

    I am trying to get the ACC data by setting it to the ACC mode, but the data I am getting are all 00!

    Thank you

  • Murtadha - I responded on the Adafruit forum.