Skip to content

Commit 7e5f8f0

Browse files
author
Max 'MaxMax' Mönikes
committed
Read Register Broadcast Bugfix, Multiread initial implementation, increased N_Slaves default limit
1 parent af3e02d commit 7e5f8f0

File tree

2 files changed

+118
-19
lines changed

2 files changed

+118
-19
lines changed

TLE9012.cpp

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ iso_uart_status_t TLE9012::readRegisterBroadcast(uint16_t regaddress, uint16_t*
11391139

11401140
for(uint8_t n = 0; n < N_DEVICES; n++)
11411141
{
1142-
uint8_t crc = crc8(&response_buffer[4+(n*N_DEVICES)],4);
1143-
result[n] = (((uint16_t) response_buffer[6+(n*N_DEVICES)])<<8) | ((uint16_t) response_buffer[7+(n*N_DEVICES)]);
1144-
if(crc != 0)
1142+
uint8_t crc = crc8(&response_buffer[4+(5*n)],4);
1143+
result[n] = (((uint16_t) response_buffer[6+(n*5)])<<8) | ((uint16_t) response_buffer[7+(n*5)]);
1144+
if(crc != response_buffer[8+(n*5)])
11451145
status = isoUART_CRC_ERROR;
11461146
}
11471147

@@ -1204,30 +1204,118 @@ iso_uart_status_t TLE9012::writeRegisterBroadcast(uint16_t regaddress, uint16_t
12041204
/**
12051205
* @brief Configure the multiread function on all devices
12061206
*
1207-
* @note currently not supported
1207+
* @note All devices in the daisy chain must have the same multiread address
12081208
*
12091209
* @param cfg multiread configuration containing information about what registers shall be reed with a multiread command
12101210
* @return iso_uart_status_t returns status of the bustransaction
12111211
*/
1212-
iso_uart_status_t TLE9012::configureMultiread(multiread_cfg_t cfg) //Write a multiread configuration to all devices in the daisy chain
1212+
iso_uart_status_t TLE9012::configureMultiread(multiread_cfg_t* cfg) //Write a multiread configuration to all devices in the daisy chain
12131213
{
1214-
return isoUART_OK; //Multiread is unsuported for the moment
1214+
1215+
uint16_t multiread_cfg_reg = ((cfg->n_pcvm) & 0xF) |
1216+
((cfg->bvm_sel & 0x1) << 4) |
1217+
((cfg->ext_temp_sel & 0x7) << 5) |
1218+
((cfg->ext_temp_r_sel & 0x1) << 8) |
1219+
((cfg->int_temp_sel & 0x1) << 9) |
1220+
((cfg->scvm_sel & 0x1) << 10) |
1221+
((cfg->stress_pcvm_sel & 0x1) << 11);
1222+
1223+
cfg->n_responses = cfg->n_pcvm + cfg->bvm_sel + cfg->ext_temp_sel + cfg->ext_temp_r_sel + cfg->int_temp_sel + cfg->scvm_sel + cfg->stress_pcvm_sel;
1224+
1225+
iso_uart_status_t status = writeRegisterBroadcast(MULTI_READ_CFG, multiread_cfg_reg);
1226+
1227+
return status; //Multiread is unsuported for the moment
12151228
}
12161229

12171230
/**
12181231
* @brief isoUART function to perform a multiread operation
12191232
*
1220-
* @note currently not supported
1233+
* @note Broadcast multiread is not possible
12211234
*
1235+
* @param nodeID targed address for the multiread command
12221236
* @param databuffer databuffer for the multiread command. The databuffer must have a large enough size to prevent bufferoverflow
12231237
* @return iso_uart_status_t returns status of the bustransaction
12241238
*/
1225-
iso_uart_status_t TLE9012::multiRead(multread_result_t* databuffer) //Multiread command from all devices in the chain
1239+
1240+
iso_uart_status_t TLE9012::multiRead(uint8_t nodeID, multiread_cfg_t cfg, multread_result_t* databuffer) //Multiread command from all devices in the chain
12261241
{
12271242
ISOUART_LOCK();
1243+
iso_uart_status_t status;
1244+
uint8_t response_buffer[5*cfg.n_responses+4];
1245+
1246+
status = isoUART_TIMEOUT;
1247+
1248+
isoUARTClearRXBUffer();
1249+
isoUARTReadRequest(BROADCAST_ID, MULTI_READ);
1250+
1251+
uint32_t starttime = millis();
1252+
while((millis()-starttime) < ISOUART_TIMEOUT)
1253+
{
1254+
if(hisoUART->available() > (3+(5*cfg.n_responses)))
1255+
{
1256+
hisoUART->readBytes(response_buffer,4+5*cfg.n_responses);
1257+
status = isoUART_OK;
1258+
break;
1259+
}
1260+
}
1261+
1262+
//Check if Timeout occured
1263+
if(status != isoUART_OK)
1264+
{
1265+
status = isoUART_TIMEOUT;
1266+
ISOUART_UNLOCK();
1267+
return status;
1268+
}
1269+
1270+
#ifdef SOFT_MSB_FIRST
1271+
msb_first_converter(&response_buffer[4],5*cfg.n_responses);
1272+
#endif
1273+
1274+
for(uint8_t n = 0; n < cfg.n_responses; n++)
1275+
{
1276+
uint8_t crc = crc8(&response_buffer[4+(5*n)],4);
1277+
if(crc != response_buffer[8+(n*5)])
1278+
status = isoUART_CRC_ERROR;
1279+
return status;
1280+
}
1281+
1282+
if(cfg.n_pcvm > 0)
1283+
{
1284+
for(uint8_t n = 0; n < cfg.n_pcvm; n++)
1285+
{
1286+
databuffer->pcvm[n] = (((uint16_t) response_buffer[6+(n*5)])<<8) | ((uint16_t) response_buffer[7+(n*5)]);
1287+
}
1288+
}
1289+
1290+
if(cfg.bvm_offset != 0)
1291+
databuffer->bvm = (((uint16_t) response_buffer[6+(cfg.bvm_offset*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.bvm_offset*5)]);
1292+
1293+
if(cfg.n_pcvm > 0)
1294+
{
1295+
for(uint8_t n = 0; n < cfg.ext_temp_sel; n++)
1296+
{
1297+
databuffer->ext_temp[n] = (((uint16_t) response_buffer[6+((n+cfg.ext_temp_sel_offset)*5)])<<8) | ((uint16_t) response_buffer[7+((n+cfg.ext_temp_sel_offset)*5)]);
1298+
}
1299+
}
1300+
12281301

1302+
if(cfg.ext_temp_r_offset != 0)
1303+
databuffer->r_diag = (((uint16_t) response_buffer[6+(cfg.ext_temp_r_offset*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.ext_temp_r_offset*5)]);
1304+
1305+
if(cfg.int_temp_sel_offset != 0)
1306+
databuffer->int_temp = (((uint16_t) response_buffer[6+(cfg.int_temp_sel_offset*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.int_temp_sel_offset*5)]);
1307+
1308+
if(cfg.scvm_offset_high != 0)
1309+
databuffer->scvm[0] = (((uint16_t) response_buffer[6+(cfg.scvm_offset_high*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.scvm_offset_high*5)]);
1310+
1311+
if(cfg.scvm_offset_low != 0)
1312+
databuffer->scvm[1] = (((uint16_t) response_buffer[6+(cfg.scvm_offset_low*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.scvm_offset_low*5)]);
1313+
1314+
if(cfg.stress_pcvm_offset != 0)
1315+
databuffer->stress_pcvm = (((uint16_t) response_buffer[6+(cfg.stress_pcvm_offset*5)])<<8) | ((uint16_t) response_buffer[7+(cfg.stress_pcvm_offset*5)]);
1316+
12291317
ISOUART_UNLOCK();
1230-
return isoUART_OK; //Multiread is unsuported for the moment
1318+
return status;
12311319
}
12321320

12331321
//---------------------------------------------------------------------------

TLE9012.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ SOFTWARE.
3636
// Defines for Lib Configuration
3737
//-----------------------------------------------------------------------------
3838

39-
#define N_DEVICES 1 //Number of devices in the daisy chain
39+
#define N_DEVICES 10 //Maximum Number of devices in the daisy chain (assuming 64 byte Serial buffer)
4040
#define ISOUART_TIMEOUT 100 //IsoUART Timeout in Milliseconds
41+
#define N_MAXCELLS 12
42+
#define N_MAXTEMP = 5
4143

4244
#define SOFT_MSB_FIRST //undef in case the hardware serial port can be configured to handle MSB First in Hardware
4345
//#define THREAD_SAFE //Uncomment if Thread safety is required -> add code to mutex lock makros for your RTOS/Scheduler
@@ -104,13 +106,22 @@ typedef enum
104106
*/
105107
typedef struct
106108
{
107-
uint8_t n_pcvm;
108-
uint8_t bvm_sel;
109-
uint8_t ext_temp_sel;
110-
uint8_t ext_temp_r_sel;
111-
uint8_t int_temp_sel;
112-
uint8_t scvm_sel;
113-
uint8_t stress_pcvm_sel;
109+
uint16_t n_pcvm;
110+
uint16_t bvm_sel;
111+
uint16_t ext_temp_sel;
112+
uint16_t ext_temp_r_sel;
113+
uint16_t int_temp_sel;
114+
uint16_t scvm_sel;
115+
uint16_t stress_pcvm_sel;
116+
uint8_t n_responses;
117+
118+
uint8_t bvm_offset;
119+
uint8_t ext_temp_sel_offset;
120+
uint8_t ext_temp_r_offset;
121+
uint8_t int_temp_sel_offset;
122+
uint8_t scvm_offset_high;
123+
uint8_t scvm_offset_low;
124+
uint8_t stress_pcvm_offset;
114125
} multiread_cfg_t;
115126

116127
/** Data structure holding the results of a multiread operation
@@ -397,8 +408,8 @@ typedef struct
397408
iso_uart_status_t readRegisterBroadcast(uint16_t regaddress, uint16_t* result); //Write a broadcast to all devices in the daisy chain
398409
iso_uart_status_t writeRegisterBroadcast(uint16_t regaddress, uint16_t databuffer); //Read a register as broadcast from all devices in the chain
399410

400-
iso_uart_status_t configureMultiread(multiread_cfg_t cfg); //Write a multiread configuration to all devices in the daisy chain
401-
iso_uart_status_t multiRead(multread_result_t* databuffer); //Multiread command from all devices in the chain
411+
iso_uart_status_t configureMultiread(multiread_cfg_t* cfg); //Write a multiread configuration to all devices in the daisy chain
412+
iso_uart_status_t multiRead(uint8_t nodeID, multiread_cfg_t cfg, multread_result_t* databuffer); //Multiread command for a device on the chain
402413

403414
};
404415

0 commit comments

Comments
 (0)