Skip to content

Commit 4f254c9

Browse files
author
Max 'MaxMax' Mönikes
committed
Changed example to use higher level functions
1 parent 21e3e3a commit 4f254c9

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

examples/TLE9012_Library/TLE9012_Library.ino

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,45 @@ SOFTWARE.
2929

3030
TLE9012 tle9012;
3131

32+
ntc_config_t ntc_config = {.ntc_resistance=100000,.ntc_b_value=3000};
33+
34+
3235
void setup() {
3336
// put your setup code here, to run once:
3437
tle9012.init(&Serial2, 2000000,16,17);
3538
Serial.begin(115200);
3639
Serial.println("Boot completed");
3740
tle9012.wakeUp();
3841
delay(200);
39-
tle9012.writeRegisterSingle(0, 0x01, 0x0FFF);
40-
tle9012.writeRegisterSingle(0, 0x36, 0x0800);
42+
tle9012.setExtendedWatchdog(0);
43+
tle9012.setNodeID(0, 1, 1);
44+
tle9012.writeMailboxRegister(1, 0xAA55);
45+
46+
uint16_t mailbox = tle9012.readMailboxRegister(1);
47+
if(mailbox == 0xAA55)
48+
Serial.println("Mailbox Check completed");
49+
50+
tle9012.setNumberofCells(1, 12);
51+
tle9012.setTempSensorsConfig(1, 5, ntc_config);
52+
uint16_t ptconf = 0;
53+
tle9012.readRegisterSingle(1, 0x01, &ptconf);
54+
Serial.println(ptconf);
4155
}
4256

4357
void loop() {
44-
iso_uart_status_t status = isoUART_OK;
45-
uint16_t cellVoltages[12];
46-
// put your main code here, to run repeatedly:
47-
tle9012.wakeUp();
48-
delay(5);
49-
status = tle9012.writeRegisterBroadcast(0x3D, 0x007F);//Trigger WDT
50-
tle9012.writeRegisterBroadcast(0x18, 0xEE61);
5158

52-
delay(5);
53-
uint8_t errors = 0;
54-
for(uint8_t n = 0; n < 12; n++)
59+
// put your main code here, to run repeatedly:
60+
tle9012.readTemperatures(1);
61+
for(uint8_t n = 0; n < 5; n++)
5562
{
56-
errors += (uint8_t) tle9012.readRegisterSingle(0, 0x19+n, &cellVoltages[n]);
57-
58-
Serial.print("Cell Voltage: ");
63+
Serial.println("-------------------------------------------");
64+
Serial.print("Resistance ");
5965
Serial.print(n+1);
60-
Serial.print(" is ");
61-
Serial.print((float) 5*cellVoltages[n]/65536);
62-
Serial.print(" V\n");
66+
Serial.print(" : ");
67+
Serial.print(tle9012.devices[0].ntc_resistances[n]);
68+
Serial.print("\n");
69+
Serial.println("-------------------------------------------");
6370
}
64-
65-
Serial.print("Status: ");
66-
Serial.println(status+errors);
67-
delay(100);
71+
delay(1000);
6872

6973
}

0 commit comments

Comments
 (0)