Tuesday, March 22, 2016

Running 6lbr on CC2538DK with ENC28J60 and make CC2650STK send sensor data to IBM MQTT quickstart service.

The following steps show how to run 6lbr on CC2538DK with ENC28J60 and make CC2650STK send sensor data to IBM MQTT quickstart service.

For CC2538DK and ENC28J60,

1. Connect CC2538DK with ENC28J60.

  • SCLK : CC2538 Port A2 (mapped to RF1.16 on P407 of SmartRF06EB)
  • MOSI : CC2538 Port A4 (mapped to RF1.18 on P407 of SmartRF06EB)
  • MISO : CC2538 Port A5 (mapped to RF1.20 on P407 of SmartRF06EB)
  • CS : CC2538 Port B5 (mapped to RF1.17 on P407 of SmartRF06EB)


2. Git 6lbr develop version from Github
 
 git clone https://github.com/cetic/6lbr
 git checkout develop

3. Build 6lbr for CC2538DK with ENC28J60

make TARGET=cc2538dk all

4. Use Flash Programmer 2 to download cetic_6lbr_router.bin (under \6lbr\examples\6lbr\bin_cc2538dk) to CC2538DK.


For CC2650STK,

1. Git Contiki from Github (refer to http://sunmaysky.blogspot.tw/search/label/Cygwin)

2. Add the following lines in project-conf.h of cc26xx-web-demo example to use nullRDC

#undef NETSTACK_CONF_RDC
#define NETSTACK_CONF_RDC     nullrdc_driver

3. Build cc26xx-web-demo.bin for CC2650STK

make BOARD=sensortag/cc2650 cc26xx-web-demo.bin

4. Use Flash Programmer 2 to download cc26xx-web-demo.bin to CC2650STK


Enable NAT64 to make CC2650STK can report sensor data to IBM MQTT quickstart service.

1. Connect Ethernet cable to CC2538DK-ENC28J60 and power on to run 6lbr.

2. Use Firefox to open web page at [bbbb::100] and switch to Configuration page. Change channel to 25 and select all options under IP64: to on. Press Submit button to write configurations and restart 6lbr.



3. Turn on CC2650STK to make it join 6lbr. Click on the web link in sensor page.



4.In sensor web page, click "IBM Quickstart"


5. Sensor data from CC2650STK would show on IBM MQTT quickstart service.




Wednesday, March 9, 2016

CC253x/CC254x IO Pin mapping to SmartRF05EB

CC253x/CC254x IO Pin mapping to SmartRF05EB are listed in the followings:



Wednesday, March 2, 2016

Basic example to use OPT3001 on CC2650 LaunchPad

1. Connect OPT3001EVM SCL to CC2650 IOID_6 and SDA to IOID_5.



2. Replace the following code to taskFxn in i2ctmp006.c (in CC26xx I2C TMP006 example) will make CC2650 LaunchPad to read OPT3001EVM Lux data.

Void taskFxn(UArg arg0, UArg arg1)
{
    unsigned int    i;
    uint16_t        lux;
    uint8_t         txBuffer[4];
    uint8_t         rxBuffer[4];
    I2C_Handle      i2c;
    I2C_Params      i2cParams;
    I2C_Transaction i2cTransaction;

    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;
    i2c = I2C_open(Board_I2C_TMP, &i2cParams);
    if (i2c == NULL) {
        System_abort("Error Initializing I2C\n");
    }
    else {
        System_printf("I2C Initialized!\n");
    }

    Task_sleep(1000000 / Clock_tickPeriod);

    //Read OPT3001 device ID
    txBuffer[0] = 0x7F;
    txBuffer[1] = 0x10;
    txBuffer[2] = 0x00;
    i2cTransaction.slaveAddress = 0x44;//OPT3001 ADDR;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;

    if (I2C_transfer(i2c, &i2cTransaction)){
        System_printf("Device ID: %x%x\n", rxBuffer[0], rxBuffer[1]);
    } else {
        System_printf("Device ID fail!\n");
    }
    if (I2C_transfer(i2c, &i2cTransaction)){
        System_printf("Device ID: %x%x\n", rxBuffer[0], rxBuffer[1]);
    } else {
        System_printf("Device ID fail!\n");
    }


    //Read OPT3001 ADDR Manufacture ID
    txBuffer[0] = 0x7E;
    i2cTransaction.slaveAddress = 0x44;//OPT3001 ADDR;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 2;
    if (I2C_transfer(i2c, &i2cTransaction)) {
        System_printf("Manufacture ID: %x%x\n", rxBuffer[0], rxBuffer[1]);
    } else {
        System_printf("Manufacture ID fail!\n");
    }


    /* Take 20 samples and print them out onto the console */
    for (i = 0; i < 20; i++) {
        //Config OPT3001
        txBuffer[0] = 0x01;
        txBuffer[1] = 0xC4;
        txBuffer[2] = 0x10;
        i2cTransaction.slaveAddress = 0x44;//OPT3001 ADDR;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 3;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 0;

        if (I2C_transfer(i2c, &i2cTransaction)){
            System_printf("Config write!\n");
            //System_printf("Conf: 0x%x 0x%x (C)\n", rxBuffer[0], rxBuffer[1]);
        } else {
            System_printf("Config write fail!\n");
        }

        //Read OPT3001 Config
        txBuffer[0] = 0x01;
        i2cTransaction.slaveAddress = 0x44;//OPT3001 ADDR;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 2;
        if (I2C_transfer(i2c, &i2cTransaction)){
            System_printf("Config read!\n");
            System_printf("Conf %u:  0x%x 0x%x\n", i, rxBuffer[0], rxBuffer[1]);
        } else {
            System_printf("Config read fail!\n");
        }

        //Task_sleep(1000000 / Clock_tickPeriod);

        txBuffer[0] = 0x00;
        i2cTransaction.slaveAddress = 0x44;//OPT3001 ADDR;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 2;
        if (I2C_transfer(i2c, &i2cTransaction)) {
            uint16_t e, m;
            float val;

            /* Extract degrees C from the received data */
            lux = rxBuffer[0];
            lux = (lux<<8 8="" br=""> | rxBuffer[1];

            m = lux & 0x0FFF;
            e = (lux & 0xF000) >> 12;
            val= (float)m * (0.01 * exp2(e));
            //System_printf("Lux %u: 0x%x 0x%x \n", i, rxBuffer[0], rxBuffer[1]);
            System_printf("Lux %u: %d \n", i, (int)val);
        }
        else {
            System_printf("I2C Bus fault\n");
        }

        System_flush();
        Task_sleep(1000000 / Clock_tickPeriod);
    }

    /* Deinitialized I2C */
    I2C_close(i2c);
    System_printf("I2C closed!\n");

    System_flush();
}