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:我要将控制台输出中的传感器数据更改为显示输出、例如终端。

Guru**** 675400 points
Other Parts Discussed in Thread: CC2650
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1215854/launchxl-cc2650-i-want-to-change-sensor-data-from-console-output-to-display-output-such-as-terminal

器件型号:LAUNCHXL-CC2650
"Thread:CC2650SysBIOS"中讨论的其他器件

您好!

目前、已创建一个程序来将传感器连接到 CC2650、并将数据输出到控制台。
但是、当我尝试将此程序更改为显示输出时、没有打印任何内容。
有人知道解决这个问题的方法吗?

请告诉我…

Lina.

抱歉、我无法将其插入代码编辑器、所以我会原封不动地粘贴。

错误代码

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

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

/* XDCtools 头文件*/
#include
#include

/* BIOS 头文件*/
#include
#include
#include

/* TI-RTOS 头文件*/
#include
#include
#include
#include
//#include
#include
#include

/*板头文件*/
#include "board.h"

//用于 usleep()
#include

#include

第2048章一个条件

Task_Struct task0Struct;
char task0Stack[TASKSTACKSIZE];

Task_Structuretask0Struct1;
char task0Stack1[TASKSTACKSIZE];

/*引脚驱动程序句柄*/
静态 PIN_Handle ledPinHandle;
静态 PIN_STATE ledPinState;

/*
*应用 LED 引脚配置表:
*-所有 LED 板 LED 均熄灭。
*/
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 缓冲器和参数*/
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]=数据;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = i2cRxBuffer;
i2cTransaction.ReadCount = 0;
I2C_TRANSMIT (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_TRANSMIT (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 readTimmingParameter(){

/*初始化显示屏并尝试打开 UART 和 LCD 类型的显示屏。 */
Display_Params 参数;
Display_PARAMS_init (&params);
params.lineClearMode = display_clear_both;
Display_Handle hDisplaySerial = Display_open (Display_Type_UART、&params);

/*检查是否找到并成功打开选定的显示类型*/
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_TRANSMIT (i2c、&i2cTransaction);

i2cTxBuffer[0]= 0xA1;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer + 24;
i2cTransaction.ReadCount = 1;
I2C_TRANSMIT (i2c、&i2cTransaction);

i2cTxBuffer[0]= 0xE1;
i2cTransaction.slaveAddress = Board_BME280;
i2cTransaction.writeBuf = i2cTxBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = i2cRxBuffer + 24 + 1;
i2cTransaction.ReadCount = 7;
I2C_TRANSMIT (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、"Hello\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 //转储校准数据
int i、ret_cnt = 0;
用于(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 补偿_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;
返回 T;
}

////////////////////////////////////////////////////////////////
unsigned long int 补偿_P (signed long int ADC_P){
signed long int var1、var2;
无符号长整型 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);
如果(var1 == 0){
返回0;
}
P =(((unsigned long int)(((signed long int) 1048576)- ADC_P)-(var2 >> 12))))* 3125;
如果(P < 0x80000000){
P =(P << 1)/((unsigned long int) var1);
}其他{
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);
返回 P;
}

////////////////////////////////////////////////////////////////
unsigned long int 补偿_H (signed long int ADC_H){
带符号 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))
+((带符号长整型) 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);
返回(unsigned long int)(v_x1 >> 12);
}

////////////////////////////////////////////////////////////////
void bme280_simple (UArg arg0、UArg arg1){

/*初始化显示屏并尝试打开 UART 和 LCD 类型的显示屏。 */
Display_Params 参数;
Display_PARAMS_init (&params);
params.lineClearMode = display_clear_both;
Display_Handle hDisplaySerial = Display_open (Display_Type_UART、&params);

/*检查是否找到并成功打开选定的显示类型*/
if (hDisplaySerial){Display_print0 (hDisplaySerial、0、0、"Hello Serial!");}

//操作模式参数
uint8_t osrs_t = 0b001;//温度过采样 x 1
uint8_t osrs_p = 0b001;//压力过采样 x 1
uint8_t osrs_h = 0b001;//湿度过采样 x 1
uint8_t mode = 0b11;//正常模式
uint8_t t_sb = 0b100;// Tstandby 500ms
uint8_t filter = 0b000;//滤波器关闭
uint8_t spi3w_en = 0;// 3线 SPI 禁用

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

//打开 I2C
I2C_Params_init (&i2cParams);
i2cParams.bitrate = I2C_400kHz;
I2C = I2C_open (Board_I2C、&i2cParams);
if (i2c == NULL){
system_abort ("Error I2C initialization.");
}

//设置
I2C_writeRegister (0xF2、ctrl_hum_reg);
I2C_writeRegister (0xF4、CTRL_meas_reg);
I2C_writeRegister (0xf5、CONFIG_reg);

//修整参数读数
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 =补偿_T (temp_raw);
press_cal =补偿_P (pres_raw);
HUM_CAL = COMPARTE_H (HUM_RAW);
TEMP_ACT =(double) temp_cal / 100.0;
press_act =(双) press_cal/100.0;
hum_act =(双) hum_cal / 1024.0;

Display_print0 (hDisplaySerial、0、0、"Hello Serial!");
//Display_printf (hDisplaySerial、0、0、"Hello\n");
//Display_print3 (hDisplaySerial、0、0、"Temp:%.2fC 按:%.2fhPa Hum:%.2f%%\n"、temp_act、press_act、ham_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;

/*初始化显示屏并尝试打开 UART 和 LCD 类型的显示屏。 */
Display_Params 参数;
Display_PARAMS_init (&params);
params.lineClearMode = display_clear_both;
Display_Handle hDisplaySerial = Display_open (Display_Type_UART、&params);

/*检查是否找到并成功打开选定的显示类型*/
if (hDisplaySerial){Display_print0 (hDisplaySerial、0、0、"Hello Serial!");}

/*永久循环、交替的 LED 状态和显示输出。 */
while (1){

如果(hDisplaySerial){
/*打印到 UART */
Display_Print1 (hDisplaySerial、0、0、"LED:%s"、(!ledPinValue)?"on!":"off!");
}


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

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

//创建任务
Task_Params taskParams;
Task_Params_init (&taskParams);
taskParams.arg0 = 1000000 / Clock_tickPeriod;
taskParams.STACKSIZE = TASKSTACKSIZE;
taskParams.stack =&task0Stack;
Task_structure (&task0Struct、(Task_FuncPtr) bme280_simple、&taskParams、NULL);

//打开 LED 引脚
ledPinHandle = PIN_OPEN (&ledPinState、ledPinTable);
如果(ledPinHandle){
PIN_setOutputValue (ledPinHandle、Board_RLED、0);
PIN_setOutputValue (ledPinHandle、Board_GLED、0);
}其他{
system_abort ("Error initializing board LED pins\n");
}

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

/*启动 BIOS */
BIOS_start();

返回(0);
}

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

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Lina:

    请澄清此代码的来源、以及确切修改了哪些行。  另外、请说明为什么要 多次使用 Display_open?  如果从未调用 Display_Close、则只能使用一次。  我也不理解最终目标、因为"显示输出、如终端"与"控制台输出"相同、是一些应用实例。  如果你能以更明确的方式重新表述你的目标,我将不胜感激。

    此致、
    Ryan