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.

TM4C123GH6PM: Using HMC5883L in a classroom

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: TMP102

Can anybody offer some sample code to interface TM4C123 to the HMC5883L?

A class and I tried and could not get code to work.

Went looking for help and only found two others asking for help.

Thanks.

Kurt at CSUCI

  • Hi,

      No, we don't have example to interface with this specific 3rd party vendor sensor HMC5883L. You can refer to TivaWare I2C examples at C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\i2c and C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl-boostxl-senshub\humidity_sht21_simple. 

    This app note is also very useful with examples. https://www.ti.com/lit/pdf/spma073

  • Thank you for the reply.

    Unfortunately this did not help.

    -The "spma073 app report" you sent is for the TM4C129 and we are using the TM4C123G.

    -The "peripherals\i2c" folder does not contain any examples of send/receive to a simple compass.

    -The "boards\ek-tm4c123gxl-boostxl-senshub\humidity_sht21_simple" folder does not contain any examples of send/receive to a simple compass.

    What we are using is the Tivaware included drivers. Specifically I2C0.c. The header for this is below:

    // I2C0.c
    // Runs on LM4F120/TM4C123
    // Provide a function that initializes, sends, and receives the I2C0 module
    // interfaced with an HMC6352 compass or TMP102 thermometer.
    // Daniel Valvano
    // July 2, 2014

    /* This example accompanies the book
    "Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers",
    ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2013
    Section 8.6.4 Programs 8.5, 8.6 and 8.7 */

    We are communicating with the HMC5883L but the data we get back appears random.

    We have verified we are addressing the correct part because we get no data back if the address of the part is changed.

    I found two users who observed similar problems of random data in the last few years but they got no replies.

    Many Arduino users report great results and no problems with the HMC5883L.

    Can you suggest any user's group who might be using this already?

    Thanks,

    Kurt

  • There are so many I2C semiconductor devices out there and you expect we have every example such as for HMC5883L ? I have already given you all the examples we have. These examples demonstrate how to carry out a generic read and write I2C transactions. The app note is for TM4C129 and TM4C123 because they share the  same TivaWare driverlib.  You need to read your compass datasheet and understand what write and read sequences are needed to access the sensor. You can then adapt one of the examples to it. 

    We are communicating with the HMC5883L but the data we get back appears random.

    If the master is putting out the correct slave address byte and command and if the device does not return correct data then it is something to investigate on the slave side. Do you have a logic analyzer capture of the bus to check if it is conforming to the timing and sequence as specified in HMC5883L datasheet?