Buonasera,
dato che ora che leggo nel modo corretto la LIN la stringa che devo leggere è molto più semplice ho provato a riscrivere il codice.
Non mi da errori di compilazione ma le ventole non girano o meglio si mettono a girare quando vogliono solo al massimo della velocità.
Ho bisogno del vostro aiuto:
// CODICE RILEVAZIONE EVENTI SU LINBUS LEXUS e COMANDO VENTOLE PWM
#include <DuePWM.h>
#define PIN_CS 2
#define PIN_FAULT 9
#define PWM_FREQ1 20000
#define PWM_FREQ2 20000
uint32_t pwm_duty = 255; // 255 = 0% duty cycle
DuePWM pwm( PWM_FREQ1, PWM_FREQ2 );
byte comando;
byte last_comando;
static byte trovato[3] = { 0, 0, 0 };
byte actuallyRead;
unsigned long lastRx;
void setup(void)
{
pinMode(PIN_CS, OUTPUT);
pinMode(PIN_FAULT, OUTPUT);
digitalWrite(PIN_CS, HIGH);
digitalWrite(PIN_FAULT, LOW);
Serial.begin(9600); //debug serial
Serial.println("Due debug Comms");
Serial2.begin(9600); //LIN Serial Rx
pwm.setFreq1( PWM_FREQ1 );
pwm.setFreq2( PWM_FREQ2 );
pwm.pinFreq1( 6 ); // Pin 6 Vent SX freq set to "pwm_freq1" on clock A
pwm.pinFreq2( 7 ); // Pin 7 Vent DX freq set to "pwm_freq2" on clock B
comando = 0x0;
last_comando = 0x0;
}
void loop(void)
{
label:
if ((millis() - lastRx) > 500)
{
if (Serial2.available())
{
actuallyRead = Serial2.read();
lastRx = millis();
//Serial.println(actuallyRead, HEX); //qui leggo correttamente la LIN
if (actuallyRead == 0x55)
{
trovato[1] = 0x55;
actuallyRead = Serial2.read();
lastRx = millis();
if (actuallyRead == 0x78)
{
trovato[2] = 0x78;
actuallyRead = Serial2.read();
lastRx = millis();
if (actuallyRead == 0x0)
{
trovato[3] = 0x0;
byte comando = Serial2.read();
lastRx = millis();
if ( comando != last_comando)
{
void Switch_Case_Comando ();
}
else
{
goto label;
}
}
else
{
goto label;
}
}
else
{
goto label;
}
}
else
{
goto label;
}
}
else
{
goto label;
}
}
}