Skip to content

Commit 91855f5

Browse files
author
Max 'MaxMax' Mönikes
committed
Minor Changes in Terminal Program
1 parent c18a7bf commit 91855f5

File tree

4 files changed

+86
-36
lines changed

4 files changed

+86
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# A Arduino Library for the Infineon TLE9012 Battery Management IC
1+
# An Arduino Library for the Infineon TLE9012 Battery Management IC
22

33
This Library aims to be an easy to use solution to experiment with the TLE9012 BMS IC from Infineon. There are a couple examples included in the examples folder to get you started using the basic functions of the library. More complex examples are planed to be added in the future. Examples are written for a ESP32 Node MCU but can be adapted to other boards by passing an appropriate HardwareSerial instance to the tle9012.init() function. If RX and TX pins are fixed for the architecture just pass 0 for the rxpin and txpin arguments.
44

TLE9012.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,52 @@ iso_uart_status_t TLE9012::readRegisterSingle(uint8_t nodeID, uint16_t regaddres
998998
return status;
999999
}
10001000

1001+
iso_uart_status_t TLE9012::readRegisterSingle_ext(uint8_t* nodeID, uint16_t* regaddress, uint16_t* result)
1002+
{
1003+
ISOUART_LOCK();
1004+
iso_uart_status_t status;
1005+
uint8_t response_buffer[9];
1006+
1007+
status = isoUART_TIMEOUT;
1008+
1009+
isoUARTClearRXBUffer();
1010+
isoUARTReadRequest(*nodeID, *regaddress);
1011+
1012+
uint32_t starttime = millis();
1013+
while((millis()-starttime) < ISOUART_TIMEOUT)
1014+
{
1015+
if(hisoUART->available() > 8)
1016+
{
1017+
hisoUART->readBytes(response_buffer,9);
1018+
status = isoUART_OK;
1019+
break;
1020+
}
1021+
}
1022+
1023+
//Check if Timeout occured
1024+
if(status != isoUART_OK)
1025+
{
1026+
status = isoUART_TIMEOUT;
1027+
ISOUART_UNLOCK();
1028+
return status;
1029+
}
1030+
1031+
#ifdef SOFT_MSB_FIRST
1032+
msb_first_converter(&(response_buffer[4]),5);
1033+
#endif
1034+
uint8_t crc = crc8(&response_buffer[4],4);
1035+
1036+
*result = (((uint16_t) response_buffer[6])<<8) | ((uint16_t) response_buffer[7]);
1037+
*regaddress = (uint16_t) response_buffer[5];
1038+
*nodeID = (uint8_t) response_buffer[4];
1039+
1040+
if(crc != response_buffer[8])
1041+
status = isoUART_CRC_ERROR;
1042+
1043+
ISOUART_UNLOCK();
1044+
return status;
1045+
}
1046+
10011047
/**
10021048
* @brief isoUART function to write a value to a single register on a single node in the daisy chain
10031049
*

TLE9012.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ typedef struct
391391

392392
//Low Level Routines for direct register Access
393393
iso_uart_status_t readRegisterSingle(uint8_t nodeID, uint16_t regaddress, uint16_t* result); //Read data from a single register
394+
iso_uart_status_t readRegisterSingle_ext(uint8_t* nodeID, uint16_t* regaddress, uint16_t* result); //Extended Read Function that reads back all parameters (data, return frame address and returned node ID)
394395
iso_uart_status_t writeRegisterSingle(uint8_t nodeID, uint16_t regaddress, uint16_t databuffer); //Write data to a single register
395396

396397
iso_uart_status_t readRegisterBroadcast(uint16_t regaddress, uint16_t* result); //Write a broadcast to all devices in the daisy chain

examples/Terminal_Interface/Terminal_Interface.ino

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ The following commands are implemented:\n \
5353
-K update_rate : Reset Watchdog every update_rate interval in milliseconds\n\
5454
-? Show Manual\n";
5555

56+
HardwareSerial Console = Serial0;
57+
5658
void setup() {
57-
Serial.begin(115200); //Start Console interface
58-
tle9012.init(&Serial1, 1000000,0,0); //Initialize driver with 2Mbit
59+
Console.begin(115200); //Start Console interface
60+
Console.println("Start completed");
61+
tle9012.init(&Serial1, 2000000,RXPIN,TXPIN); //Initialize driver with 2Mbit
5962
}
6063

6164
void loop() {
@@ -88,7 +91,7 @@ void handleTerminal()
8891
{
8992

9093
//Check if new data was received
91-
uint8_t rx_len = Serial.available();
94+
uint8_t rx_len = Console.available();
9295

9396
//Handle overflow situations by resetting the buffer
9497
if((rx_len+terminalbufferrecvlen) > 64)
@@ -100,7 +103,7 @@ void handleTerminal()
100103
}
101104

102105
//Read Bytes from Serial RX Buffer to terminalbuffer
103-
Serial.readBytes(&terminalbuffer[terminalbufferrecvlen], rx_len);
106+
Console.readBytes(&terminalbuffer[terminalbufferrecvlen], rx_len);
104107

105108
//Check newly received data for \n end of line character
106109
uint8_t eol_char_found = 0;
@@ -136,15 +139,15 @@ void interpretCommand(const char commandbuffer[], uint8_t bufferlength)
136139

137140
if(sscanf(commandbuffer,"%s",cmd) == 1) //Read command
138141
{
139-
Serial.write(commandbuffer,bufferlength);
142+
Console.write(commandbuffer,bufferlength);
140143
if(!strcmp(cmd,"IL")) //Emulate IL Command (no function because no ring bus mode is supported by this library)
141144
{
142-
Serial.println("IL OK");
145+
Console.println("IL OK");
143146
}
144147

145148
else if(!strcmp(cmd,"IH")) //Emulate IH Command (no function because no ring bus mode is supported by this library)
146149
{
147-
Serial.println("IH OK");
150+
Console.println("IH OK");
148151
}
149152

150153
else if((strcmp(cmd,"WH") == 0) | (strcmp(cmd,"WL") == 0)) //Write data to a single register of a single device on the bus
@@ -157,61 +160,61 @@ void interpretCommand(const char commandbuffer[], uint8_t bufferlength)
157160
iso_uart_status_t status = tle9012.writeRegisterSingle(dev_address, reg_address, data);
158161
if(status == isoUART_OK)
159162
{
160-
Serial.print("WL ");
161-
Serial.print(" ");
162-
Serial.print(dev_address,HEX);
163-
Serial.print(" ");
164-
Serial.print(reg_address, HEX);
165-
Serial.println(" OK 8000");
163+
Console.print("WL ");
164+
Console.print(" ");
165+
Console.print(dev_address,HEX);
166+
Console.print(" ");
167+
Console.print(reg_address, HEX);
168+
Console.println(" OK 8000");
166169
}
167170
if(status == isoUART_TIMEOUT)
168171
{
169-
Serial.println("TIMEOUT");
172+
Console.println("TIMEOUT");
170173
}
171174
if(status == isoUART_CRC_ERROR)
172175
{
173-
Serial.println("CRC ERROR");
176+
Console.println("CRC ERROR");
174177
}
175178
}
176179
else
177180
{
178-
Serial.println("INVALID COMMAND FORMAT");
181+
Console.println("INVALID COMMAND FORMAT");
179182
}
180183
}
181184

182185
else if((strcmp(cmd,"RH") == 0) | (strcmp(cmd,"RL") == 0)) //Read data from a single register of a single device on the bus
183186
{
184187

185188
uint8_t dev_address;
186-
uint8_t reg_address;
189+
uint16_t reg_address;
187190
uint16_t data;
188191

189192
if(sscanf(commandbuffer, "%s %d %x", cmd, &dev_address, &reg_address) == 3)
190193
{
191-
iso_uart_status_t status = tle9012.readRegisterSingle(dev_address, reg_address, &data);
194+
iso_uart_status_t status = tle9012.readRegisterSingle_ext(&dev_address, &reg_address, &data);
192195
if(status == isoUART_OK)
193196
{
194-
Serial.print("RL ");
195-
Serial.print(dev_address,HEX);
196-
Serial.print(" ");
197-
Serial.print(reg_address,HEX);
198-
Serial.print(" ");
199-
Serial.print(data,HEX);
200-
Serial.print(" OK ");
201-
Serial.println("8000");
197+
Console.print("RL ");
198+
Console.print(dev_address,HEX);
199+
Console.print(" ");
200+
Console.print(reg_address,HEX);
201+
Console.print(" ");
202+
Console.print(data,HEX);
203+
Console.print(" OK ");
204+
Console.println("8000");
202205
}
203206
if(status == isoUART_TIMEOUT)
204207
{
205-
Serial.println("TIMEOUT");
208+
Console.println("TIMEOUT");
206209
}
207210
if(status == isoUART_CRC_ERROR)
208211
{
209-
Serial.println("CRC ERROR");
212+
Console.println("CRC ERROR");
210213
}
211214
}
212215
else
213216
{
214-
Serial.println("INVALID COMMAND FORMAT");
217+
Console.println("INVALID COMMAND FORMAT");
215218
}
216219
}
217220

@@ -224,26 +227,26 @@ void interpretCommand(const char commandbuffer[], uint8_t bufferlength)
224227
{
225228
watchdog_time = wd_time;
226229
watchdog_active = 1;
227-
Serial.print("Watchdog kicking time change to ");
228-
Serial.print(watchdog_time);
229-
Serial.println(" ms");
230+
Console.print("Watchdog kicking time change to ");
231+
Console.print(watchdog_time);
232+
Console.println(" ms");
230233
}
231234
else
232235
{
233236
watchdog_active = 0;
234-
Serial.println("Watchdog kicker deactivated");
237+
Console.println("Watchdog kicker deactivated");
235238
}
236239
}
237240
}
238241

239242
else if(!strcmp(cmd,"?")) //Print Helppage
240243
{
241-
Serial.print(helppage);
244+
Console.print(helppage);
242245
}
243246

244247
else //No valid command was detected
245248
{
246-
Serial.println("INVALID COMMAND");
249+
Console.println("INVALID COMMAND");
247250
}
248251

249252
}

0 commit comments

Comments
 (0)