Hi guys, it looks like I might have figured out the checksum issue with the kunteng lcd's. It would be great if some others with kunteng displays could second this before committing anything.
The UART transmission from the display contains 14 words instead of the 13 that where in the code so I've updated the size of the buffer.
(this is what I logged trough uart when logging the incoming uart with a buffer 20 long, as you can see the buffer gets filled with 14 values):
<\n>buffervalue 0=16<\r>
<\n>buffervalue 1=1<\r>
<\n>buffervalue 2=202<\r>
<\n>buffervalue 3=105<\r>
<\n>buffervalue 4=0<\r>
<\n>buffervalue 5=74<\r>
<\n>buffervalue 6=5<\r>
<\n>buffervalue 7=202<\r>
<\n>buffervalue 8=4<\r>
<\n>buffervalue 9=20<\r>
<\n>buffervalue 10=5<\r>
<\n>buffervalue 11=50<\r>
<\n>buffervalue 12=14<\r>
<\n>buffervalue 13=14<\r>
<\n>buffervalue 14=0<\r>
<\n>buffervalue 15=0<\r>
<\n>buffervalue 16=0<\r>
<\n>buffervalue 17=0<\r>
<\n>buffervalue 18=0<\r>
<\n>buffervalue 19=0<\r>
<\n>crc =74<\r>
<\n>-----------------------------------------------------------------<\r>
Next it seems like the first received byte (16 in decimal) is omitted when making the checksum since it is a check by itself (to indicate the start of the new package I'm thinking)-> just like how the fixed first byte (65 decimal) when transmitting to the display is omited from the checksum as per snipped below:
Code:
// calculate CRC xor
ui8_crc = 0;
for (ui8_j = 1; ui8_j <= 11; ui8_j++) {
ui8_crc ^= ui8_tx_buffer[ui8_j];
-> this was not omited in the current master so I've changed the diplay_update() function from display.h into:
Code:
void display_update() {
// fill local buffer from uart ringbuffer
uart_fill_rx_packet_buffer(ui8_rx_buffer, 14, &ui8_UARTCounter);
// Check for reception of complete message
if ((ui8_UARTCounter > 13) || (ui8_rx_buffer[ui8_UARTCounter - 1] == 0x0E)) {
ui8_UARTCounter = 0;
// validation of the package data
ui8_crc = 0;
for (ui8_j = 1; ui8_j <= 13; ui8_j++) {
if (ui8_j == 5) continue; // don't xor B5
ui8_crc ^= ui8_rx_buffer[ui8_j];
}
if (ui8_crc==ui8_rx_buffer [5]) // see if CRC is ok
{
// Light On/Off
lcd_configuration_variables.ui8_light_On = ui8_rx_buffer [1] & 128;
// Walk mode
if ((ui8_rx_buffer[1] & 7)==6) {lcd_configuration_variables.ui8_ReverseDriveModus_On = 1;}
else {lcd_configuration_variables.ui8_ReverseDriveModus_On = 0;}
//Assist level
lcd_configuration_variables.ui8_assist_level = ui8_rx_buffer [1] & 7;
lcd_configuration_variables.ui8_max_speed = 10 + ((ui8_rx_buffer [2] & 248) >> 3) | (ui8_rx_buffer [4] & 32);
lcd_configuration_variables.ui8_wheel_size = ((ui8_rx_buffer [4] & 192) >> 6) | ((ui8_rx_buffer [2] & 7) << 2);
lcd_configuration_variables.ui8_p1 = ui8_rx_buffer[3];
lcd_configuration_variables.ui8_p2 = ui8_rx_buffer[4] & 0x07;
lcd_configuration_variables.ui8_p3 = ui8_rx_buffer[4] & 0x08;
lcd_configuration_variables.ui8_p4 = ui8_rx_buffer[4] & 0x10;
lcd_configuration_variables.ui8_p5 = ui8_rx_buffer[0];
lcd_configuration_variables.ui8_c1 = (ui8_rx_buffer[6] & 0x38) >> 3;
lcd_configuration_variables.ui8_c2 = (ui8_rx_buffer[6] & 0x37);
lcd_configuration_variables.ui8_c4 = (ui8_rx_buffer[8] & 0xE0) >> 5;
lcd_configuration_variables.ui8_c5 = (ui8_rx_buffer[7] & 0x0F);
lcd_configuration_variables.ui8_c12 = (ui8_rx_buffer[9] & 0x0F);
lcd_configuration_variables.ui8_c13 = (ui8_rx_buffer[10] & 0x1C) >> 2;
lcd_configuration_variables.ui8_c14 = (ui8_rx_buffer[7] & 0x60) >> 5;
digestLcdValues();
send_message();
}
}
}
That seems to work for me for any display setting I could come up with without the crc's getting out of sync. Only parameter 11, (communication protocol version) gets the crc's out of sync as expected. I'm not sure how the old protocol works and if it is worth implementing this, if you do, knock yourself out on it
Let me know if this tests ok for others as well, I can try to commit my the code to master or feel free to do it yourself.
(also I corrected the walk mode bit status in the code above as it was not working in its current form)