Salut la compagnie ,
Ayant eu des difficultés pour initialiser mon ECU (38770 -MJE- G52) de ma Honda CB650F avec une NANO .... je vous conseille l'utilisation de la librairie AltSoftSerial !! plutôt que SoftWareserial !! j'utilise une interface K-Line maison a base de transistors , il est bien sur possible d'utiliser un circuit spécialisé comme un L9637 par exemple ...
Sofwareserial ne supporte pas l 'écriture/lecture simultanée !!!! ![]()
Mon projet sera dans un premier temps de lire les erreurs ECU et de les effacer ...
Puis de calculer le rapport engagé ... (pas d'indicateur rapport sur ma bécane pfffffffff !!)
ensuite ... avec pourquoi pas un afficheur LCD + boutons ...
Un bout de mon code ...
#include <AltSoftSerial.h>
byte buff[0xFF];
byte INS1[4] = {0xFE, 0x04, 0x72, 0x8C};
byte INS2[5] = {0x72, 0x05, 0x71, 0x00, 0x18};
byte INS3[6] = {0x7D, 0x06, 0x01, 0x01, 0x03, 0x78};
byte INS4[5] = {0x72, 0x05, 0x73, 0x01, 0x15};
byte INS5[5] = {0x72, 0x05, 0x74, 0x01, 0x14};
unsigned long startMillis;
unsigned long currentMillis;
// Initiate an instance of the altSerial class
// On ATmega 328 based Arduinos AltSoftSerial uses pin 8 for RX and pin 9 for TX
AltSoftSerial altSerial;
void setup() {
//Serial.begin(115200,SERIAL_8N1);
altSerial.begin(10400);
altSerial.setTimeout(100);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
PhaseINIT:
digitalWrite(LED_BUILTIN, HIGH);
// delay(200);
digitalWrite(9, LOW);
delay(70);
digitalWrite(9, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, LOW);
while (altSerial.available() > 0) altSerial.read();
//{0xFE, 0x04, 0x72, 0x8C}; ////=> 0E04727C
SEND_CMD(INS1, sizeof(INS1));
if (buff[0] != 0x0E) goto PhaseINIT;
//ECMID
//7205710018=020F710001019C1201FF00000000CE
SEND_CMD(INS2, sizeof(INS2));
if (buff[0] != 0x02) goto PhaseINIT;
//7D0601010378=0D090100FF90010158
SEND_CMD(INS3, sizeof(INS3));
if (buff[0] != 0x0D) goto PhaseINIT;
fin:
//DTC erreur current / last
//7205730115=020C73010056010000000027
SEND_CMD(INS4, sizeof(INS4));
if (buff[0] != 0x02) goto PhaseINIT;
//DTC erreur current / last
//7205740114=020C74010056010000000026
SEND_CMD(INS5, sizeof(INS5));
if (buff[0] != 0x02) goto PhaseINIT;
goto fin;
}
void SEND_CMD(byte *cmde, int Nb) {
altSerial.write(cmde, Nb);
READnByteAuto();
READnByteAuto();
}
void READnByteAuto() {
startMillis = millis();
memset(buff, 0, sizeof(buff));
ici:
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= 1000)
{
return;
}
if (altSerial.available() > 1)
{
altSerial.readBytes(buff, 2);
}
else
goto ici;
ici2:
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= 1000)
{
return;
}
if (altSerial.available() > buff[1]-3)
{
altSerial.readBytes(buff+2, buff[1]-2);
}
else
goto ici2;
}
Bonne prog ![]()
rylryl