在“线程:LM63”中讨论的其他部件
大家好,
我正在使用带有 cc1312r1板的NTC温度传感器。 在我想通过 i2c将此温度值写入lm63板之后,我能够读取模拟值。不是I2C不能读取。
uINT16_t adcValue=0;
uINT16_t ledStatus=0;
uINT16_t adcThreshold=800;
浮子T;
双输出电压,热敏电阻,热敏电阻,温度;
浮点R1 =1万;
float logR2,R2;
浮子C1 = 1.0.09249522亿e-03,C2 = 2.3.78405444亿e-04,C3 = 2.0.19202697亿e-07;
//定义I2C总线索引的名称
#define lm63_address 0x4C
I2C_Params lm63参数;
I2C_HANDLE lm63手柄;
I2C_Transaction lm63Transaction ={0};
uINT16_t写数据[2];
UINT8_t ReadData[2];
void lm63_ReadData();
/*
*
*========= mainThread =========
*/
#定义ADC
#ifdef ADC
#endif
void *mainThread(void *arg0)
{
// UINT32_t number=0;
/*调用驱动程序初始化函数*/
GPIO初始化();
DISPLAY_INIT();
ADC_INIT();
I2C_INIT();
//初始化显示参数
Display_Params uartParams;
Display_Handle uartHandle;
Display_Params_init(&uartParams);
uartHandle=Display_open(Display_Type_UART,&uartParams);
//ADC初始化
ADC_Params adcParams;
ADC_HANDLE适配器;
ADC_PARAM_INIT (&adcParams);
adchandle=adc_open(config_adc_0,&adcParams);
//I2C初始化
I2C_Params_init (&lm63params);
lm63params.bitrate = I2C_400kHz;
lm63params.transferMode=I2C_MODE_blocking;
lm63Handle = I2C_OPEN (CONFIG_I2C_0,&lm63params);
同时(1)
{
UINT16_t结果;
result=adc_convert (adchandle,&adcValue);
// output_voltage =((adcValue * 3.3)/ 4095.0);
output_voltage =((adcValue * 3.3)/ 3123.0);
//热敏电阻=(3.3 *(10 / output_voltage))- 10);/*电阻单位为千欧*/
热敏电阻=(9.78)/(3.3 - OUTPT_VOLTAGE);
热敏电阻=热敏电阻* 1000;/*电阻(欧姆)*/
Therm_res_ln = logf (热敏电阻);
/* Steinhart-Hart热敏电阻公式:*/
/*开尔文温度= 1 /(A + B[ln (R)]+ C[ln (R)]^3)*/
/*,其中A = 0.0.01129148亿 ,B = 0.0.00234125亿 ,C = 8.7.6741万 *10^-8 */
//温度=(1 /(0.0.01129148亿 +(0.0.00234125亿 * therm_res_ln)+(0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln));/*开尔文温度*/
温度=(1 /(0.0.2108万508173</xmt-block>50.8173万 +(0.00007979204727 * therm_res_ln)+(0.0.0065万35076315</xmt-block>3507.6315万 * therm_res_Ln * therm_res_ln * therm_res_ln));/*开尔文温度*/
Temperature = temperature - 273.15 ;/* Temperature in摄氏度*/
//writeddata[0]=LM63_Addr[key_index_count];
writeddata[0]=0x50;
// writeddata[1]=温度;
writeddata[1]=13;
lm63Transaction.slaveAddress=lm63_address;
lm63Transaction.writeBuf=写入数据;
lm63Transaction.writeCount=2;
lm63Transaction.readBuf=&ReadData;
lm63Transaction.ReadCount=1;
I2C_TRANSFER (lm63Handle,&lm63Transaction);
}
// Display_Print1 (uartHandle,0,0,"ADC value is =%d,adcValue);
// Display_Print1 (uartHandle,0,0,"T value is =%f",T);
// usleep(5万);
}
谢谢。