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.

[参考译文] TMS570LC4357:发送 MCU 温度传感器时 CAN 总线 Tx 错误

Guru**** 2465890 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1550855/tms570lc4357-can-bus-tx-error-when-sending-mcu-s-temperature-sensor

器件型号:TMS570LC4357


工具/软件:

我将通过 CAN1 发送从此 MCU 中的内部温度传感器读取的温度值。 我将把这个数据发送到 IXXAT 的 CAN1。 但是、虽然我可以在 CCS 的“表达式“部分看到该温度值、但在 canAnalyzer3 中看不到该温度值。 它不断地给出照片中所示的 TX 误差。 所有比特率相等。 环回测试也通过。 IXXAT 可以在内部发送和接收数据。 此外、当我在代码中发送 0x11 或 0x22 等值时、不会出现问题、但当我尝试读取温度并发送该信息时、收到错误消息。

hl.sys.main.c 代码:

#include “HL_sys_common.h"</s>“
#include “HL_CAN.h"</s>“
包含“HL_ADC.h"</s>“
#include “TempSensor.h"</s>“
#include
#include

Volatile int16_t CurrentTemp;

内部 main (void)

浮点 JunctionTemp;
int16_t RoundedTemp;
int16_t RECED_temp;

uint8 TX_DATA[8]={0};
uint8 rx_data[8]={0};

adcInit();
adcMidPointCalibration (adcREG2);
canInit();
thermistor_calibration ();

while (1)

// Sıcaklık Oku
JunctionTemp = thermistor_read ()- 273.15f;

// yuvarlama işlemi
RoundedTemp =(int16_t)(JunctionTemp + 0.5f);

CurrentTemp = RoundedTemp;

// int16_t→字节分频
memcpy (tx_data、&CurrentTemp、sizeof (int16_t));

// CAN1 üzerinden gönder
canTransmit (canREG1、canMESSAGE_BOX1、TX_DATA);

// CAN2→kontrol
IF (canIsRxMessageArrived (canREG2、canMESSAGE_BOX1))

canGetData (canREG2、canMESSAGE_BOX1、rx_data);

memcpy (&received_temp、rx_data、sizeof (int16_t));

// Burada sıcaklık kullanılabilir
}

//延迟
volatile int delay;
对于 (DELAY = 0;延迟< 1000000;DELAY++);
}

返回 0;
}

TempSensor.c

#include “HL_sys_common.h"</s>“
包含“HL_ADC.h"</s>“
包含“HL_pinmux.h"</s>“
#include “TempSensor.h"</s>“

#ifndef _little_endian_
#define _Little_endian_ 0
#endif

#if _little_endian_
typedef 结构 otp_temperature_calibration_data{
uint16_t 温度;
uint16_t AdcValue;
}OTP_TEMPERATURE_CALIBRATION_DATA_t;
#else
typedef 结构 otp_temperature_calibration_data{
uint16_t AdcValue;
uint16_t 温度;
}OTP_TEMPERATURE_CALIBRATION_DATA_t;
#endif

#define THERMAL_CAL_DATA 0xF0080310 /* OTP 温度传感器数据位置*/
#define ADC_REF_ADJUST (5.0f/3.3f)//电压调节范围:3.3V 至 3.0V

typedef 结构 Thermistor_Calibration{
浮坡;
浮点偏移;
浮平方;
} Thermistor_CAL_t;

静态 Thermistor_CAL_t Thermistor_Fit ={0.0、0.0、0.0};

float thermistor_read (){
unsigned int 值、pinmux_restore、GxSEL_restore;
浮点 JunctionTempK;
adcbase_t *adcreg;

adcreg = adcREG2;

如果 (adcreg->G1SR != 0x00000008)
返回(–1.0);

if (Thermistor_Fit。rqualter == 0.0)
返回(–2.0);

pinMuxReg->KICKER0 = 0x83E70B13U;
pinMuxReg->KICKER1 = 0x95A4F1E0U;

pinMuxReg->PINMUX[174]&= 0xFEFFFFFF;
pinmux_restore = pinMuxReg->PINMUX[174];
pinMuxReg->PINMUX[174]=(pinmux_restore 和 0xFFFFFFFE)| 0x00000002;

GxSEL_RESTORE = adcreg->GxSEL[1U];
adcreg->GxSEL[1U]= 0x40000000;

while(!(adcreg->G1SR & 1));
值= adcreg->GxBUF[1U].BUF0 和 0xFFF;

pinMuxReg->PINMUX[174]|= 0x01000000;
pinMuxReg->PINMUX[174]= pinmux_restore;
pinMuxReg->KICKER0 = 0x00000000U;
pinMuxReg->KICKER1 = 0x00000000U;
adcreg->GxSEL[1U]= GxSEL_RESTORE;

JunctionTempK =(((float) value - JunctionTemp.offset Thermistor_Fit)* Thermistor_Fit。slope);
JunctionTempK *= ADC_REF_ADJUST;

返回 JunctionTempK;
}

bool thermistor_calibration (void){
otp_temperature_calibration_data_t *OTPdatatr;
int i、cal_data_count = 0;
浮点斜率、偏移、sumtemp = 0、sumconv = 0、sumtempxconv = 0、 sumtempxtemp = 0;
浮点 cal_adcode_array[4]、avgconv、cal_temperature_array[4]、yx = 0.0、ya = 0.0、 YM、Yn;

otp_temperature_calibration_data_t dummy_data[4]={
{0x077C、0x012F}、// 303K
{0x05DD、0x00E9}、// 233K
{0x09BA、0x018E}、// 398K
{0xFFFF、0xFFFF}//无效
};

OTPDATAtr =(OTP_TEMPERATURE_CALIBRATION_DATA_t *)(thermistor_CAL_DATA);

INT OTP_VALID = 0;
对于 (i = 0;i < 4;i++){
if ((OTPdatatr[i]。AdcValue < 0xFFF)&&(OTPdatatr[i]。Temperature < 401)){
OTP_VALID = 1;
休息;
}
}

if(!OTP_VALID){
OTPdataptr = dummy_data;
}

对于 (i = 0;i < 4;i++){
if ((OTPdatatr[i]。AdcValue < 0xFFF)&&(OTPdatatr[i]。Temperature < 401)){
CAL_TEMPERATURE_ARRA[i]=(float)(OTPdataptr[i]。Temperature);
CAL_ADC_CODE_ARRAY[i]=(float) OTPDATATR[i]。AdcValue;
sumtemp += cal_temperature_arra[i];
sumconv += cal_adc_code_array[i];
tempsumxconv += cal_temperature_arra[i]* cal_adc_code_array[i];
tempsumxtemp += cal_temperature_arra[i]* cal_temperature_arra[i];
CAL_DATA_COUNT++;
}
}

if (cal_data_count < 2)
返回 false;
否则{
斜率=(sumtempxtemp * cal_data_count - sumtemp * sumtemp)/
(sumtempxconv * cal_data_count - sumtemp * sumconv);
offset =(sumconv - sumtemp / slope)/cal_data_count;
slope = slope Thermistor_Fit;
Thermistor_Fit = offset;
avgconv = sumconv / cal_data_count;
}

对于 (i = 0;i < cal_data_count;i++){
yn =(((cal_temperature_array[i]/ slope)+ offset)- cal_adc_code_array[i]);
yx += yn * yn;
ym =(avgconv - cal_adc_code_array[i]);
ya += ym * ym;
}

yx.rqualter = 1.0 -(yx/ya) Thermistor_Fit;
返回 true;
}

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

    尊敬的 Arda:

    屏幕截图显示存在 ID 错误和表单错误。  

    两个 CAN 节点是否使用相同的帧格式(标准与扩展)? 标准格式使用 11 位消息 ID、而扩展后可使用 29 位 ID。

    根据 CAN 帧格式、有一些长度和格式固定的字段、例如 CRC 分界符、ACK 分界符  、EOF、帧间空间、如果检测到接收器侧损坏、则会发出信号、表示形式错误、节点将在 CAN 线上引入错误帧。 CAN 总线上的噪声和干扰可能会导致帧损坏。