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.

interfacing TMP102 with CC2530

Other Parts Discussed in Thread: CC2530, TMP102, Z-STACK

Hi everyone,

I'm currently working on CC2530 development kit and attempt to using I2C bus to interface external temperature sensor TMP102 with CC2530 chip. Instead of using the internal temperature sensor inside CC2530 chip, I would like to use TMP102 to measure the temperature.

I already downloaded the i2c hal drivers (hal_i2c.c, hal_i2c.h) available in RemoTi Stack for cc2530 and define my own OCM_CLK_PORT, OCM_CLK_PIN, OCM_DATA_PORT, and OCM_DATA_PIN for SCL and SDA. However, I still have several questions:

(1) in the method "void HalI2CInit( void )", there are several lines that have been commented out:

//    // Set port pins as inputs
//    IO_DIR_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_IN );
//    IO_DIR_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_IN );
//
//    // Set for general I/O operation
//    IO_FUNC_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_GIO );
//    IO_FUNC_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_GIO );
//
//    // Set I/O mode for pull-up/pull-down
//    IO_IMODE_PORT_PIN( OCM_CLK_PORT, OCM_CLK_PIN, IO_PUD );
//    IO_IMODE_PORT_PIN( OCM_DATA_PORT, OCM_DATA_PIN, IO_PUD );
//
//    // Set pins to pull-up
//    IO_PUD_PORT( OCM_CLK_PORT, IO_PUP );
//    IO_PUD_PORT( OCM_DATA_PORT, IO_PUP );

Do I have to bring them back to original code?

(2) Are there any other methods or variables that I need to revise?

Thank you for the help! ^-^

  • As I know, you only have to revise pin and ports for SDL and SDA in hal_i2c. Do you see clock and data signal on SDL and SDA when you use I2C driver?
  • Thank you for your quick reply, YiKai Chen

    I always got several errors after I included and compiled "hal_i2c.c" in my application files. I have spent several hours attempting to figure out what goes wrong in my code. Could you please give me some advice on how to debug those errors indicating that "expected a declaration"? I also attached a picture.

    (I did not change anything in my hal_i2c.c file except defining my own OCM_CLK_PORT, OCM_CLK_PIN, OCM_DATA_PORT, and OCM_DATA_PIN for SCL and SDA)

    Thank you for your help!

  • Do you put hal_i2c.c and hal_i2c.h under HAL->TARGET->CC2530EB->Drivers?

  • Could you attach the list of additional include directories.
    Project options (Alt+F7) -> C/C++ Compiler -> Preprocessor (tab)
  • Hi YK Chen,
    Thank you for your help. I already put those files in this location, but the errors still appear.
  • Hi Igor Sherer,
    This is the list of additional include directories:
    $PROJ_DIR$
    $PROJ_DIR$\..\Source
    $PROJ_DIR$\..\..\Source
    $PROJ_DIR$\..\..\..\ZMain\TI2530DB
    $PROJ_DIR$\..\..\..\..\..\Components\hal\include
    $PROJ_DIR$\..\..\..\..\..\Components\hal\target\CC2530EB
    $PROJ_DIR$\..\..\..\..\..\Components\mac\include
    $PROJ_DIR$\..\..\..\..\..\Components\mac\high_level
    $PROJ_DIR$\..\..\..\..\..\Components\mac\low_level\srf04
    $PROJ_DIR$\..\..\..\..\..\Components\mac\low_level\srf04\single_chip
    $PROJ_DIR$\..\..\..\..\..\Components\mt
    $PROJ_DIR$\..\..\..\..\..\Components\osal\include
    $PROJ_DIR$\..\..\..\..\..\Components\services\saddr
    $PROJ_DIR$\..\..\..\..\..\Components\services\sdata
    $PROJ_DIR$\..\..\..\..\..\Components\stack\af
    $PROJ_DIR$\..\..\..\..\..\Components\stack\nwk
    $PROJ_DIR$\..\..\..\..\..\Components\stack\sapi
    $PROJ_DIR$\..\..\..\..\..\Components\stack\sec
    $PROJ_DIR$\..\..\..\..\..\Components\stack\sys
    $PROJ_DIR$\..\..\..\..\..\Components\stack\zcl
    $PROJ_DIR$\..\..\..\..\..\Components\stack\zdo
    $PROJ_DIR$\..\..\..\..\..\Components\zmac
    $PROJ_DIR$\..\..\..\..\..\Components\zmac\f8w
  • In your case the hal_i2c.h should be placed under include, not in drivers.
  • Hi Igor Sherer,
    Thank you for your help. I also tried to place the file under include, but the errors still appear.
  • Ok, where did you copy these files on your PC?
  • Hi Igor Sherer and YK Chen,
    Thank you for your help. I already solved the problem. It turns out that the predefined file path for "ZDObject.c" is not correct so that the definition and declaration of variables "port" and "pin" are not existed under this condition.
    But still, thank you for your assistance.
  • You are welcome and it's good to know your problem is solved.
  • Hi YK Chen,

    I already implemented the i2c drivers for TMP102 temperature sensor, but I'm not very clear how to verify whether the driver is actually working. Do I just use oscilloscope to measure the signal of SDA and SCL after I run the code on CC2530? For example, just use the probe to measure the voltage change of the SDA data port and SCL port (in my case, they are P0_1 and P0_7) and watch the voltage change. Will that work?

    Also, I notice that there is an output pin of TMP102 for alert signal. In my case, the alert pin of TMP102 will be connected to P1_0. Do I also have to configure P1_0 for alert signal?

    Thank you for your time and help?

  • Yes, you should check if you can see SDA and SCL signal on P0.1 and P0.7 on scope.
  • By the way, you can config P1.0 as GPI to read TMP102 alert signal.
  • Thank you YK Chen,

    But I'm still not very clear about how to configure P1.0 as a port for alert signal. Do you know which file in Z-stack I need to focus on in order to configure P1.0 for alert signal? Also, do you have any sample code for this?

    Thank you very much for your time and help!

    And Happy New Year!

  • Hal_key.c shows you how to config a pin as GPI and trigger interrupt. You can refer to SW6 implementation in hal_key.c.
  • Hi YK Chen,

    Thank you for your help! Right now, I already configured DATA and CLK port in hal_i2c.c file. However, I'm still trying to figure out how to read temperatures from TMP102 sensor using methods from this i2c driver. I noticed that there is one method in the application file called readTempVolt(), which reads temperature from internal temperature sensor inside CC2530. Do I need to modify this method using method from i2c driver? Could you please provide me with some insights?

    Thank you very much for your help!

  • As you say, readTempVolt read ADC value to get temperature from internal temperature sensor so it's not the same to use TMP102. You have to use TMP102 I2C command to read temperature from TMP102.