Reading temperature from MCP9808 via I2C with CC1110

Discussion in 'Embedded Systems and Microcontrollers' started by Fábio Verde, Mar 18, 2016.

  1. Fábio Verde

    Thread Starter New Member

    Mar 18, 2016
    4
    0
    hi,


    I'm working on a project and i need to connect the CC1110 with MCP9808 (temperature sensor).

    The problem is that MCP9808 uses I2C connection and the CC1110 chip has no such interface.

    I did a little research and it seems the problem can be solve by using bit banging method but i cant find any really good example or document explaining how to do it.

    So i ask to the TI community if someone knows how to do it or if there is another method that i can use in order to complete this task. Any help is precious.

    Thanks.
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    497
    Datasheets, where?
     
  3. Fábio Verde

    Thread Starter New Member

    Mar 18, 2016
    4
    0
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    497
  5. Fábio Verde

    Thread Starter New Member

    Mar 18, 2016
    4
    0
    Thanks for the quick response.
    I have some questions about the code you said and i'm sorry if what i ask is trivial but i dont understant:

    1 - why ( for example) in function I2CRestart() we put SDA = 1 and in next line SDA = 0. it's not the same of put just SDA = 0?

    2 - I think i have to declare the SDA i/o pin of 8051 as output for sending signal to the sensor and in a certain moment switch that pin to input (for collecting data from sensor) right? I ask this because in the code you said the only thing it shows is :
    • #define SDA P0_0
    • #define SCL P0_1
    and nothing about if the SDA pin is an input or output. Therefore how the 8051 with that code is able to collect the data from temperature sensor?

    Sorry if the question is kind confusing.

    Thanks
     
  6. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    497
    1 - why ( for example) in function I2CRestart() we put SDA = 1 and in next line SDA = 0. it's not the same of put just SDA = 0?
    You would need to read about I2C protocol to understand why the author did that.




    2 - I think i have to declare the SDA i/o pin of 8051 as output for sending signal to the sensor and in a certain moment switch that pin to input (for collecting data from sensor) right?

    Author uses following setup to write to slave device:
    Code (Text):
    1.  
    2. /*****************************************
    3. * Write to slave device with
    4. * slave address e.g. say 0x20
    5. *****************************************/
    6. /* Init i2c ports first */
    7. I2CInit();
    8. /* Send start condition */
    9. I2CStart();
    10. /* Send slave address */
    11. ack = I2CSend(0x20);
    12. * ack == 1 => NAK
    13. * ack == 0 => ACK
    14. */
    15. ack = I2CSend(0x07);
    16. /* Send another data */
    17. ack = I2CSend(0x10);
    18. /* Send stop condition */
    19. I2CStop();
    20.  
    Author uses following setup to read from slave device:
    Code (Text):
    1.  
    2. /*****************************************
    3.  * Read from slave device with
    4.  * slave address e.g. say 0x20
    5.  *****************************************/
    6.    /* Init i2c ports first - Should be done once in main */
    7.    I2CInit();
    8.    /* Send start condition */
    9.    I2CStart();
    10.    /*
    11.     * Send slave address with Read bit set
    12.     * So address is 0x20 | 1 = 0x21
    13.     */
    14.    I2CSend(0x21);
    15.    data = I2CRead();
    16.    /* Send ack */
    17.    I2CAck();
    18.    /* Read last byte */
    19.    data = I2CRead();
    20.    /*
    21.     * Send nak for last byte to indicate
    22.     * End of transmission
    23.     */
    24.    I2CNak();
    25.    /* Send stop condition */
    26.    I2CStop();
    27.  
     
    Last edited: Mar 19, 2016
  7. Fábio Verde

    Thread Starter New Member

    Mar 18, 2016
    4
    0
    Hi shteii01,
    I manage to do it, thanks a lot.
     
  8. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,386
    497
    I am glad to hear that you have succeeded.
    To be fair that is not my code, but when I saw that micro uses 8051 core, I figured that one of 8051 websites would have I2C code.
     
Loading...