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.

LAUNCHXL-CC2650: I want to change sensor data from console output to display output such as terminal.

Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: CC2650, SYSBIOS

Hello,

Currently, a program was created to connect the sensor to the CC2650 and output data to the console.
However, when I tried to change this program to display output, nothing was printed.
Does anyone know of a solution to this?

Please tell me…

Lina

I'm sorry, I couldn't insert it in the code editor, so I'll paste it as it is.

Error code

/////////////////////////////////////

/*
* ======== bme280_simple.c ========
*/

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplayExt.h>

/* Board Header files */
#include "Board.h"

// For usleep()
#include <ti/sysbios/posix/unistd.h>

#include <stdio.h>

#define TASKSTACKSIZE 2048

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

Task_Struct task0Struct1;
Char task0Stack1[TASKSTACKSIZE];

/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;

/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config ledPinTable[] = {
Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE };

////////////////////////////////////////////////////////////////////////////////
/* I2C buffers and parameters */
uint8_t i2cTxBuffer[32];
uint8_t i2cRxBuffer[32];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;

unsigned long int temp_raw, pres_raw, hum_raw;
signed long int t_fine;
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
uint16_t dig_P1;
int16_t dig_P2;
int16_t dig_P3;
int16_t dig_P4;
int16_t dig_P5;
int16_t dig_P6;
int16_t dig_P7;
int16_t dig_P8;
int16_t dig_P9;
int8_t dig_H1;
int16_t dig_H2;
int8_t dig_H3;
int16_t dig_H4;
int16_t dig_H5;
int8_t dig_H6;

char str[64];

////////////////////////////////////////
void i2c_writeRegister(uint8_t reg_address, uint8_t data) {
i2cTxBuffer[0] = reg_address;
i2cTxBuffer[1] = data;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = i2cRxBuffer;
i2cTransaction.readCount = 0;
I2C_transfer(i2c, &i2cTransaction);
}

////////////////////////////////////////
void i2c_readData() {
i2cTxBuffer[0] = 0xF7;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer;
i2cTransaction.readCount = 8;
I2C_transfer(i2c, &i2cTransaction);

pres_raw = (i2cRxBuffer[0] << 12) | (i2cRxBuffer[1] << 4) | (i2cRxBuffer[2] >> 4);
temp_raw = (i2cRxBuffer[3] << 12) | (i2cRxBuffer[4] << 4) | (i2cRxBuffer[5] >> 4);
hum_raw = (i2cRxBuffer[6] << 8) | i2cRxBuffer[7];
}

////////////////////////////////////////
void readTrimmingParameter() {

/* Initialize display and try to open both UART and LCD types of display. */
Display_Params params;
Display_Params_init(&params);
params.lineClearMode = DISPLAY_CLEAR_BOTH;
Display_Handle hDisplaySerial = Display_open(Display_Type_UART, &params);

/* Check if the selected Display type was found and successfully opened */
if (hDisplaySerial) {Display_print0(hDisplaySerial, 0, 0, "Hello Serial!");}

i2cTxBuffer[0] = 0x88;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer;
i2cTransaction.readCount = 24;
I2C_transfer(i2c, &i2cTransaction);

i2cTxBuffer[0] = 0xA1;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer + 24;
i2cTransaction.readCount = 1;
I2C_transfer(i2c, &i2cTransaction);

i2cTxBuffer[0] = 0xE1;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer + 24 + 1;
i2cTransaction.readCount = 7;
I2C_transfer(i2c, &i2cTransaction);

dig_T1 = (i2cRxBuffer[1] << 8) | i2cRxBuffer[0];
dig_T2 = (i2cRxBuffer[3] << 8) | i2cRxBuffer[2];
dig_T3 = (i2cRxBuffer[5] << 8) | i2cRxBuffer[4];
dig_P1 = (i2cRxBuffer[7] << 8) | i2cRxBuffer[6];
dig_P2 = (i2cRxBuffer[9] << 8) | i2cRxBuffer[8];
dig_P3 = (i2cRxBuffer[11] << 8) | i2cRxBuffer[10];
dig_P4 = (i2cRxBuffer[13] << 8) | i2cRxBuffer[12];
dig_P5 = (i2cRxBuffer[15] << 8) | i2cRxBuffer[14];
dig_P6 = (i2cRxBuffer[17] << 8) | i2cRxBuffer[16];
dig_P7 = (i2cRxBuffer[19] << 8) | i2cRxBuffer[18];
dig_P8 = (i2cRxBuffer[21] << 8) | i2cRxBuffer[20];
dig_P9 = (i2cRxBuffer[23] << 8) | i2cRxBuffer[22];
dig_H1 = (i2cRxBuffer[24]);
dig_H2 = (i2cRxBuffer[26] << 8) | i2cRxBuffer[25];
dig_H3 = (i2cRxBuffer[27]);
dig_H4 = (i2cRxBuffer[28] << 4) | (0x0F & i2cRxBuffer[29]);
dig_H5 = (i2cRxBuffer[30] << 4) | ((i2cRxBuffer[29] >> 4) & 0x0F);
dig_H6 = (i2cRxBuffer[31]);

Display_print0(hDisplaySerial, 0, 0, "Hello Serial!");
//Display_printf(hDisplaySerial, 0, 0,"Hellow\n");
//Display_printf(hDisplaySerial,0,0,"Hellow:%d\n",3.1415);
//Display_print3(hDisplaySerial, 0, 0, "dig_T1: %.2f dig_T2: %.2f dig_T3: %.2f\n",dig_T1, dig_T2, dig_T3);


sprintf(str, "dig_T1: %.2f dig_T2: %.2f dig_T3: %.2f\n", dig_T1, dig_T2, dig_T3);
System_printf("%s", str);

#if 0 // Dump calibration data
int i, ret_cnt = 0;
for (i=0;i<32;i++) {
ret_cnt += sprintf(str+ret_cnt, "%02x ", i2cRxBuffer[i]);
}
System_printf("%s\n", str);
System_flush();
#endif
}

////////////////////////////////////////
signed long int compensate_T(signed long int adc_T) {

signed long int var1, var2, T;
var1 = ((((adc_T >> 3) - ((signed long int) dig_T1 << 1))) * ((signed long int) dig_T2)) >> 11;
var2 = (((((adc_T >> 4) - ((signed long int) dig_T1)) * ((adc_T >> 4) - ((signed long int) dig_T1))) >> 12)
* ((signed long int) dig_T3)) >> 14;

t_fine = var1 + var2;
T = (t_fine * 5 + 128) >> 8;
return T;
}

////////////////////////////////////////
unsigned long int compensate_P(signed long int adc_P) {
signed long int var1, var2;
unsigned long int P;
var1 = (((signed long int) t_fine) >> 1) - (signed long int) 64000;
var2 = (((var1 >> 2) * (var1 >> 2)) >> 11) * ((signed long int) dig_P6);
var2 = var2 + ((var1 * ((signed long int) dig_P5)) << 1);
var2 = (var2 >> 2) + (((signed long int) dig_P4) << 16);
var1 = (((dig_P3 * (((var1 >> 2) * (var1 >> 2)) >> 13)) >> 3) + ((((signed long int) dig_P2) * var1) >> 1)) >> 18;
var1 = ((((32768 + var1)) * ((signed long int) dig_P1)) >> 15);
if (var1 == 0) {
return 0;
}
P = (((unsigned long int) (((signed long int) 1048576) - adc_P) - (var2 >> 12))) * 3125;
if (P < 0x80000000) {
P = (P << 1) / ((unsigned long int) var1);
} else {
P = (P / (unsigned long int) var1) * 2;
}
var1 = (((signed long int) dig_P9) * ((signed long int) (((P >> 3) * (P >> 3)) >> 13))) >> 12;
var2 = (((signed long int) (P >> 2)) * ((signed long int) dig_P8)) >> 13;
P = (unsigned long int) ((signed long int) P + ((var1 + var2 + dig_P7) >> 4));
return P;
}

////////////////////////////////////////
unsigned long int compensate_H(signed long int adc_H) {
signed long int v_x1;

v_x1 = (t_fine - ((signed long int) 76800));
v_x1 = (((((adc_H << 14) - (((signed long int) dig_H4) << 20) - (((signed long int) dig_H5) * v_x1))
+ ((signed long int) 16384)) >> 15)
* (((((((v_x1 * ((signed long int) dig_H6)) >> 10)
* (((v_x1 * ((signed long int) dig_H3)) >> 11) + ((signed long int) 32768))) >> 10)
+ ((signed long int) 2097152)) * ((signed long int) dig_H2) + 8192) >> 14));
v_x1 = (v_x1 - (((((v_x1 >> 15) * (v_x1 >> 15)) >> 7) * ((signed long int) dig_H1)) >> 4));
v_x1 = (v_x1 < 0 ? 0 : v_x1);
v_x1 = (v_x1 > 419430400 ? 419430400 : v_x1);
return (unsigned long int) (v_x1 >> 12);
}

////////////////////////////////////////
Void bme280_simple(UArg arg0, UArg arg1) {

/* Initialize display and try to open both UART and LCD types of display. */
Display_Params params;
Display_Params_init(&params);
params.lineClearMode = DISPLAY_CLEAR_BOTH;
Display_Handle hDisplaySerial = Display_open(Display_Type_UART, &params);

/* Check if the selected Display type was found and successfully opened */
if (hDisplaySerial) {Display_print0(hDisplaySerial, 0, 0, "Hello Serial!");}

// Operation mode parameters
uint8_t osrs_t = 0b001; // Temperature oversampling x 1
uint8_t osrs_p = 0b001; // Pressure oversampling x 1
uint8_t osrs_h = 0b001; // Humidity oversampling x 1
uint8_t mode = 0b11; // Normal mode
uint8_t t_sb = 0b100; // Tstandby 500ms
uint8_t filter = 0b000; // Filter off
uint8_t spi3w_en = 0; // 3-wire SPI Disable

uint8_t ctrl_meas_reg = (osrs_t << 5) | (osrs_p << 2) | mode;
uint8_t config_reg = (t_sb << 5) | (filter << 2) | spi3w_en;
uint8_t ctrl_hum_reg = osrs_h;

// Open I2C
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C, &i2cParams);
if (i2c == NULL) {
System_abort("Error I2C initializing.");
}

// Setup
i2c_writeRegister(0xF2, ctrl_hum_reg);
i2c_writeRegister(0xF4, ctrl_meas_reg);
i2c_writeRegister(0xF5, config_reg);

// Trimming parameter readout
readTrimmingParameter();

while (1) {
Task_sleep((UInt) arg0);

PIN_setOutputValue(ledPinHandle, Board_RLED, 1);
PIN_setOutputValue(ledPinHandle, Board_GLED, 0);

double temp_act = 0.0, press_act = 0.0, hum_act = 0.0;
signed long int temp_cal;
unsigned long int press_cal, hum_cal;

i2c_readData();

temp_cal = compensate_T(temp_raw);
press_cal = compensate_P(pres_raw);
hum_cal = compensate_H(hum_raw);
temp_act = (double) temp_cal / 100.0;
press_act = (double) press_cal / 100.0;
hum_act = (double) hum_cal / 1024.0;

Display_print0(hDisplaySerial, 0, 0, "Hello Serial!");
//Display_printf(hDisplaySerial, 0, 0,"Hellow\n");
//Display_print3(hDisplaySerial, 0, 0, "Temp: %.2fC Press: %.2fhPa Hum: %.2f%%\n", temp_act, press_act, hum_act);


sprintf(str, "Temp: %.2fC Press: %.2fhPa Hum: %.2f%%\n", temp_act, press_act, hum_act);
System_printf("%s", str);
System_flush();

PIN_setOutputValue(ledPinHandle, Board_RLED, 0);
PIN_setOutputValue(ledPinHandle, Board_GLED, 1);

}
}


/* ======== taskFxn ======== */
Void taskFxn(UArg arg0, UArg arg1)
{
unsigned int ledPinValue;

/* Initialize display and try to open both UART and LCD types of display. */
Display_Params params;
Display_Params_init(&params);
params.lineClearMode = DISPLAY_CLEAR_BOTH;
Display_Handle hDisplaySerial = Display_open(Display_Type_UART, &params);

/* Check if the selected Display type was found and successfully opened */
if (hDisplaySerial) {Display_print0(hDisplaySerial, 0, 0, "Hello Serial!");}

/* Loop forever, alternating LED state and Display output. */
while (1) {

if (hDisplaySerial) {
/* Print to UART */
Display_print1(hDisplaySerial, 0, 0, "LED: %s",(!ledPinValue)?"On!":"Off!");
}


}
}
////////////////////////////////////////
int main(void) {

Board_initGeneral();
Board_initI2C();
Board_initSPI();
// Board_initUART();
// Board_initWatchdog();

// Create a task
Task_Params taskParams;
Task_Params_init(&taskParams);
taskParams.arg0 = 1000000 / Clock_tickPeriod;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr) bme280_simple, &taskParams, NULL);

// Open LED pins
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if (ledPinHandle) {
PIN_setOutputValue(ledPinHandle, Board_RLED, 0);
PIN_setOutputValue(ledPinHandle, Board_GLED, 0);
} else {
System_abort("Error initializing board LED pins\n");
}

System_printf("\n\n");
System_printf("SmartBAN SensorBoard - bme280_simple.\n");
System_flush();

/* Start BIOS */
BIOS_start();

return (0);
}

//////////////////////////////////////////////////////////////

  • Hello Lina,

    Please clarify from where you have sourced this code and exactly what lines were modified.  Also, please state why Display_open is used multiple times?  It should only be used once if Display_close is never called.  I also don't understand the end goal since "display output such as terminal" is the same as "console output" is some application instances.  I would appreciate if you could re-word your objective in a more clear manner.

    Regards,
    Ryan