Reading temperature from MCP9808 via I2C with CC1110

Thread Starter

Fábio Verde

Joined Mar 18, 2016
4
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.
 

Thread Starter

Fábio Verde

Joined Mar 18, 2016
4
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
 

shteii01

Joined Feb 19, 2010
4,647
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:
/*****************************************
* Write to slave device with
* slave address e.g. say 0x20
*****************************************/
/* Init i2c ports first */
I2CInit();
/* Send start condition */
I2CStart();
/* Send slave address */
ack = I2CSend(0x20);
* ack == 1 => NAK
* ack == 0 => ACK
*/
ack = I2CSend(0x07);
/* Send another data */
ack = I2CSend(0x10);
/* Send stop condition */
I2CStop();
Author uses following setup to read from slave device:
Code:
/*****************************************
 * Read from slave device with
 * slave address e.g. say 0x20
 *****************************************/
   /* Init i2c ports first - Should be done once in main */
   I2CInit();
   /* Send start condition */
   I2CStart();
   /*
    * Send slave address with Read bit set
    * So address is 0x20 | 1 = 0x21
    */
   I2CSend(0x21);
   data = I2CRead();
   /* Send ack */
   I2CAck();
   /* Read last byte */
   data = I2CRead();
   /*
    * Send nak for last byte to indicate
    * End of transmission
    */
   I2CNak();
   /* Send stop condition */
   I2CStop();
 
Last edited:
Top