Part Number: TMS570LC4357
Tool/software:
I'm sending the temperature value read from the internal temperature sensor in this MCU via can1. I'm sending this data to ixxat's can1. However, while I can see this temperature value in the "expressions" section in CCS, I can't see it in canAnalyser3. It constantly gives the tx error shown in the photo. All bitrates are equal. The loopback test also passed. ixxat can send and receive data internally. Additionally, when I send values like 0x11 or 0x22 in the code, no problems occur, but when I try to read the temperature and send this information, I get an error.

hl.sys.main.c code:
#include "HL_sys_common.h"
#include "HL_can.h"
#include "HL_adc.h"
#include "TempSensor.h"
#include <string.h>
#include <stdint.h>
volatile int16_t CurrentTemp;
int main(void)
{
float JunctionTemp;
int16_t RoundedTemp;
int16_t received_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 → byte dizi
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
}
// Delay
volatile int delay;
for(delay = 0; delay < 1000000; delay++);
}
return 0;
}
TempSensor.c
#include "HL_sys_common.h"
#include "HL_adc.h"
#include "HL_pinmux.h"
#include "TempSensor.h"
#ifndef _little_endian_
#define _little_endian_ 0
#endif
#if _little_endian_
typedef struct OTP_temperature_calibration_data {
uint16_t Temperature;
uint16_t AdcValue;
} OTP_temperature_calibration_data_t;
#else
typedef struct OTP_temperature_calibration_data {
uint16_t AdcValue;
uint16_t Temperature;
} OTP_temperature_calibration_data_t;
#endif
#define THERMISTOR_CAL_DATA 0xF0080310 /* OTP Temperature Sensor Data Location */
#define ADC_REF_ADJUSTMENT (5.0f / 3.3f) // Voltage adjustment from 3.3V to 3.0V
typedef struct Thermistor_Calibration {
float slope;
float offset;
float rsquared;
} Thermistor_CAL_t;
static Thermistor_CAL_t Thermistor_Fit = {0.0, 0.0, 0.0};
float thermistor_read() {
unsigned int value, pinmux_restore, GxSEL_restore;
float JunctionTempK;
adcBASE_t *adcreg;
adcreg = adcREG2;
if (adcreg->G1SR != 0x00000008)
return (-1.0);
if (Thermistor_Fit.rsquared == 0.0)
return (-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));
value = 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 - Thermistor_Fit.offset) * Thermistor_Fit.slope);
JunctionTempK *= ADC_REF_ADJUSTMENT;
return JunctionTempK;
}
bool thermistor_calibration(void) {
OTP_temperature_calibration_data_t *OTPdataptr;
int i, cal_data_count = 0;
float slope, offset, sumtemp = 0, sumconv = 0, sumtempxconv = 0, sumtempxtemp = 0;
float cal_adc_code_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} // Invalid
};
OTPdataptr = (OTP_temperature_calibration_data_t *)(THERMISTOR_CAL_DATA);
int otp_valid = 0;
for (i = 0; i < 4; i++) {
if ((OTPdataptr[i].AdcValue < 0xFFF) && (OTPdataptr[i].Temperature < 401)) {
otp_valid = 1;
break;
}
}
if (!otp_valid) {
OTPdataptr = dummy_data;
}
for (i = 0; i < 4; i++) {
if ((OTPdataptr[i].AdcValue < 0xFFF) && (OTPdataptr[i].Temperature < 401)) {
cal_temperature_array[i] = (float)(OTPdataptr[i].Temperature);
cal_adc_code_array[i] = (float)OTPdataptr[i].AdcValue;
sumtemp += cal_temperature_array[i];
sumconv += cal_adc_code_array[i];
sumtempxconv += cal_temperature_array[i] * cal_adc_code_array[i];
sumtempxtemp += cal_temperature_array[i] * cal_temperature_array[i];
cal_data_count++;
}
}
if (cal_data_count < 2)
return FALSE;
else {
slope = (sumtempxtemp * cal_data_count - sumtemp * sumtemp) /
(sumtempxconv * cal_data_count - sumtemp * sumconv);
offset = (sumconv - sumtemp / slope) / cal_data_count;
Thermistor_Fit.slope = slope;
Thermistor_Fit.offset = offset;
avgconv = sumconv / cal_data_count;
}
for (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;
}
Thermistor_Fit.rsquared = 1.0 - (yx / ya);
return TRUE;
}
