主题中讨论的其他器件:CC1350、 TMP116
工具/软件:Code Composer Studio
尊敬的专家:
我使用的是 cc1350 Launch Pad 和 i2c 示例、我声明了浮动变量、我只希望打印2个小数点、但这打印4个小数点我无法限制小数点、因此可以帮助我找到解决我问题的解决方案。
Display_printf (display、0、0、"Temp:%.2fC"、temperature);
谢谢你
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.
工具/软件:Code Composer Studio
尊敬的专家:
我使用的是 cc1350 Launch Pad 和 i2c 示例、我声明了浮动变量、我只希望打印2个小数点、但这打印4个小数点我无法限制小数点、因此可以帮助我找到解决我问题的解决方案。
Display_printf (display、0、0、"Temp:%.2fC"、temperature);
谢谢你
您好 Clement、
感谢您的回复、但我尝试使用 sprintf 方法、但我得到的结果相同、只打印一次、但我在 while 函数中写入代码
我的标题中添加了 stdio.h
#include
#include
#include
#include
//#include
//#include
/*驱动程序头文件*/
#include
#include
#include
然后是我的代码
while (1)
{
/*指向芯片温度寄存器并读取它的2个字节*/
TxBuffer[0]= TMP116_DIE_TEMP;
i2cTransaction.slaveAddress = Si7021_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 2;
IF (I2C_transfer (i2c、&i2cTransaction))
{
char buf[64];
TEMPER =(rxBuffer[0]<< 8)|(rxBuffer[1]);
温度=(175.72*温度)/65536;
温度-= 46.85;
sprintf (buf、"缓冲区:%3.2fC\n"、温度);
Display_printf (display、1、0、"Temp:%3.2fC\n"temperature);
display_printf (display、1、0、"%s"、buf);
}
我尝试使用 sprintf 方法并添加字段宽度、但如果使用 sprintf 方法、我会得到相同的结果和一个结果、而 CC1350不会向 UART 打印任何内容。
我的当前结果是
HUMI:72.32.7271%
温度:27.8181C
但我只需要两个小数点即可打印 UART
谢谢你
您好!
我可以告诉您、以下代码使用 SDK v3.10打印"Temp:12.35C"。
静态 Display_Handle 显示; Display_init (); display = Display_open (Display_Type_UART、NULL); char buffer[10]; 浮点温度= 12.3456789; sprintf (buffer、"%.2f"、temperature); Display_printf (display、 1、0、"温度:%SC\n"、缓冲区);
您能告诉我您使用的是哪个 SDK 版本吗?
此致、
e2e.ti.com/.../i2ctmp116.chiClement、
我使用的 SDK 版本与 v3.10相同
但我无法在代码中获得两个小数点
我随附了完整的代码供您参考、请帮助查找代码中的错误。
我在代码中禁用了该行。
谢谢你
BIOS 用户指南的第8.3节:
Timer_handle timerHandle;
int main (void)
{
Error_Block EB;
Timer_Params timerParams;
Task_Handle;
Error_init (&EB);
Timer_Params_init (&timerParams);
timerParams.period = 2000;//
timerHandle = Timer_create (Timer_any、tickFxn、&timerParams、&EB);
if (timerHandle =
arg1){System_abort ("计时器创建失败");}&Handle = Task_create (masterTask、NULL、EB){"System_abort ("taskarg 失败)
"(task_arge"}(task_abort);任务 Uarge"(任务失败)(任务失败)
//检测到需要更改计时器周期
Timer_stop (timerHandle)的条件;
Timer_setPeriodMicroSecs (4000);//将2ms 更改为4ms */
Timer_start (timerHandle);
...
}
void tickFxn (UArg0)
{
System_printf ("当前周期=%d\n"、
Timer_getPeriod (timerHandle);
}
尊敬的 Keith、
我已经尝试过、但无法连续获得结果、这是我的代码
while (1)
{
/*指向芯片温度寄存器并读取它的2个字节*/
TxBuffer[0]= 0xE3;
i2cTransaction.slaveAddress = Si7021_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 2;
IF (I2C_transfer (i2c、&i2cTransaction))
{
// char buf[64];
char buffer[10];
浮点型= 12.3456789;
sprintf (buffer、"%.2f"、tem);
display_printf (display、1、0、"Test:%sc\n"buffer);
TEMPER =(rxBuffer[0]<< 8)|(rxBuffer[1]);
温度=(175.72*温度)/65536;
温度-= 46.85;
//sprintf (buf、"缓冲器:%.2fC\n"、温度);
Display_printf (display、1、0、"Temp:%.2fC\n"temperature);
//Display_printf (display、1、0、"%s"、buf);
我使用 while ()连续运行和打印数据,但我的 cc1350 Launchpad 只打印一次数据,而不重复。
输出:
启动 i2ctmp116示例
I2C 已初始化!
测试:12.35C
然后、我的 launchpad 不做任何类似的事情会被击中或悬挂、或者我不知道的事情。