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.

CCS/EK-TM4C123GXL: TM4C123 I2C Library to Arduino Wire Library for MPU6050

Part Number:

Tool/software: Code Composer Studio

I study to read MPU6050 gyro data but the main problem is that I could not achieve. Let me to explain why this problem happen.

I found MPU6050 example for Arduino MPU6050BasicExample.

I have started to change basic Arduino example. Then I applied all codes to my project except of these "writeByte", "readByte", "readBytes" functions.

I have tried to change these code according to Arduino as follow;

These are Arduino codes;

 void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
    Wire.beginTransmission(address);  // Initialize the Tx buffer
    Wire.write(subAddress);           // Put slave register address in Tx buffer
    Wire.write(data);                 // Put data in Tx buffer
    Wire.endTransmission();           // Send the Tx buffer
}

  uint8_t readByte(uint8_t address, uint8_t subAddress)
{
    uint8_t data; // `data` will store the register data     
    Wire.beginTransmission(address);         // Initialize the Tx buffer
    Wire.write(subAddress);                  // Put slave register address in Tx buffer
    Wire.endTransmission(false);             // Send the Tx buffer, but send a restart to keep connection alive
    Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address 
    data = Wire.read();                      // Fill Rx buffer with result
    return data;                             // Return data read from slave register
}

  void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
{  
    Wire.beginTransmission(address);   // Initialize the Tx buffer
    Wire.write(subAddress);            // Put slave register address in Tx buffer
    Wire.endTransmission(false);       // Send the Tx buffer, but send a restart to keep connection alive
    uint8_t i = 0;
        Wire.requestFrom(address, count);  // Read bytes from slave register address 
    while (Wire.available()) {
        dest[i++] = Wire.read(); }         // Put read results in the Rx buffer
}  


These are my codes I have tried to change;

void writeByte(uint16_t address, uint16_t subAddress, uint8_t data)
{
    writeI2C0(address, subAddress, data);
}

 uint8_t readByte(uint16_t address, uint16_t subAddress)
{

   uint8_t data;
   return readI2C0(address, subAddress);

}

 void readBytes(uint16_t address, uint16_t subAddress, uint8_t count, uint8_t * dest)
{

   writeByte(address, subAddress, count);

   uint8_t i = 0;

   while (I2CMasterBusy(I2C0_BASE)) {
       dest[i++] = readByte(address, subAddress); }// Put read results in the Rx buffer
}

In my opinion, if I port Arduino codes to Tiva-c codes, I will achieve to read gyro data.

  • yilmaz edis said:

    Part Number: EK-TM4C123GXL

    Tool/software: Code Composer Studio

    I study to read MPU6050 gyro data but the main problem is that I could not achieve. Let me to explain why this problem happen.

    I found MPU6050 example for Arduino MPU6050BasicExample.

    I have started to change basic Arduino example. Then I applied all codes to my project except of these "writeByte", "readByte", "readBytes" functions.

    I have tried to change these code according to Arduino as follow;

    These are Arduino codes;

     void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
    {
        Wire.beginTransmission(address);  // Initialize the Tx buffer
        Wire.write(subAddress);           // Put slave register address in Tx buffer
        Wire.write(data);                 // Put data in Tx buffer
        Wire.endTransmission();           // Send the Tx buffer
    }
    
      uint8_t readByte(uint8_t address, uint8_t subAddress)
    {
        uint8_t data; // `data` will store the register data     
        Wire.beginTransmission(address);         // Initialize the Tx buffer
        Wire.write(subAddress);                  // Put slave register address in Tx buffer
        Wire.endTransmission(false);             // Send the Tx buffer, but send a restart to keep connection alive
        Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address 
        data = Wire.read();                      // Fill Rx buffer with result
        return data;                             // Return data read from slave register
    }
    
      void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
    {  
        Wire.beginTransmission(address);   // Initialize the Tx buffer
        Wire.write(subAddress);            // Put slave register address in Tx buffer
        Wire.endTransmission(false);       // Send the Tx buffer, but send a restart to keep connection alive
        uint8_t i = 0;
            Wire.requestFrom(address, count);  // Read bytes from slave register address 
        while (Wire.available()) {
            dest[i++] = Wire.read(); }         // Put read results in the Rx buffer
    }  


    These are my codes I have tried to change;

    void writeByte(uint16_t address, uint16_t subAddress, uint8_t data)
    {
        writeI2C0(address, subAddress, data);
    }
    
     uint8_t readByte(uint16_t address, uint16_t subAddress)
    {
    
       uint8_t data;
       return readI2C0(address, subAddress);
    
    }
    
     void readBytes(uint16_t address, uint16_t subAddress, uint8_t count, uint8_t * dest)
    {
    
       writeByte(address, subAddress, count);
    
       uint8_t i = 0;
    
       while (I2CMasterBusy(I2C0_BASE)) {
           dest[i++] = readByte(address, subAddress); }// Put read results in the Rx buffer
    }

    In my opinion, if I port Arduino codes to Tiva-c codes, I will achieve to read gyro data.

  • What you suggest is of course doable, but requires you to totally understand the Arduino code and identify the processor dependencies. Helping you do that is beyond my scope of assistance. You might find help in the Arduino forum or from some community members. I suggest that it would be easier to download TivaWare and start with the programming example in section 15.3 of the Sensor Library User's Guide which will be in:

    C:\ti\TivaWare_C_Series-2.1.4.178\docs\SW-TM4C-SENSORLIB-UG-2.1.4.178.pdf

  • Yes you are right. My desire is beyond scope of assistance. I have tried that you suggest me but I couldn't succeed.

    I ask a question to stackoverflow 

    https://stackoverflow.com/questions/52916781/tm4c123-and-mpu6050-i2c-connection

    . I have tried to port mpu9160 to mpu6050 too. But I haven't succeed again. What should I do.

  • Ok, here is a very simple Code Composer Studio project that shows writing and reading from the MPU6050 registers. My hardware used I2C3. Import this project to your workspace with FILE->Import "Code Composer Studio" "CCS Projects", Next, "Select archive file".

    /cfs-file/__key/communityserver-discussions-components-files/908/MPU6050.zip

  • **** Build of configuration Debug for project MPU6050_Bob_Crosby ****

    "C:\\ti\\ccsv7\\utils\\bin\\gmake" -k all
    'Building target: MPU6050_Bob_Crosby.out'
    'Invoking: ARM Linker'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.4.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 --abi=eabi -me -O2 --advice:power=all -g --gcc --define=ccs="ccs" --define=PART_TM4C123GH6PM --define=TARGET_IS_TM4C123_RB1 --diag_warning=225 --diag_wrap=off --display_error_number --gen_func_subsections=on --ual -z -m"MPU6050_Bob_Crosby.map" --stack_size=256 --heap_size=0 -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.4.LTS/lib" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.4.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="MPU6050_Bob_Crosby_linkInfo.xml" --rom_model -o "MPU6050_Bob_Crosby.out" "./main.obj" "./startup_ccs.obj" "./tm4c123gh6pm_startup_ccs.obj" "../project0_ccs.cmd" "../tm4c123gh6pm.cmd" -llibc.a -l"C:/ti/TivaWare_C_Series-2.1.4.178/driverlib/ccs/Debug/driverlib.lib" -l"C:/ti/TivaWare_C_Series-2.1.4.178/sensorlib/ccs/Debug/sensorlib.lib"
    <Linking>
    "../tm4c123gh6pm.cmd", line 13: error #10263: FLASH memory range has already been specified
    "../tm4c123gh6pm.cmd", line 13: error #10264: FLASH memory range overlaps existing memory range FLASH
    "../tm4c123gh6pm.cmd", line 14: error #10263: SRAM memory range has already been specified
    "../tm4c123gh6pm.cmd", line 14: error #10264: SRAM memory range overlaps existing memory range SRAM
    "../tm4c123gh6pm.cmd", line 45: warning #10190-D: absolute symbol "__STACK_TOP" being redefined
    "../tm4c123gh6pm.cmd", line 45: warning #10190-D: absolute symbol "__STACK_TOP" being redefined
    error #10056: symbol "ResetISR" redefined: first defined in "./startup_ccs.obj"; redefined in "./tm4c123gh6pm_startup_ccs.obj"
    error #10056: symbol "g_pfnVectors" redefined: first defined in "./startup_ccs.obj"; redefined in "./tm4c123gh6pm_startup_ccs.obj"
    remark #10371-D: (ULP 1.1) Detected no uses of low power mode state changing instructions
    "../tm4c123gh6pm.cmd", line 45: warning #10190-D: absolute symbol "__STACK_TOP" being redefined

    >> Compilation failure
    makefile:145: recipe for target 'MPU6050_Bob_Crosby.out' failed
    error #10010: errors encountered during linking; "MPU6050_Bob_Crosby.out" not built
    gmake: *** [MPU6050_Bob_Crosby.out] Error 1
    gmake: Target 'all' not remade because of errors.

    I got these errors as above. I have started solve these. I think I created project wrongly but I don't know now. As you see, I am very new about embedded develop but I want to improve my skills to help people. By the way, when I saw your last post that include this project I was so happy. Thank you for your interest.

  • Ah sorry I have Imported your project wrongly. Now I built successfully. My microcontroller is not with me now. I'll try this CSS project tomorrow. I'm very happy right now. Thank you so much. :D:D