LIN with the Serial

Hello all!

The hw is set, namely running the TJA1021 transceiver on the AT Tiny 3216 and 1626, and apparently the master side works well, can see the signal on the LIN bus,
the code:

byte ledPin = 0;
byte brightness = 0;
byte txEnPin = 12;

byte fadeAmount = 1;

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(txEnPin, OUTPUT);

  //LIN setup
  Serial.swap(0);
  Serial.begin(19200, SERIAL_HALF_DUPLEX); //

  digitalWrite(txEnPin, HIGH);

}



void loop() {

  Serial1.println(brightness);
  delay(5);

  brightness = 100;

  Serial.write(brightness);
  Serial.flush ();
}

However, the code below does not want to work and read from the transceiver , any ideas if the code for serial is ok?

#define LED_PIN PIN_PA4

byte ledPin = 0;
byte brightness;
byte txEnPin = 12;


void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(txEnPin, OUTPUT);

  //LIN setup
  Serial.swap(0);
  Serial.begin(19200, SERIAL_HALF_DUPLEX);  

  //normal, print out serial ! ? Why is see nonsense on this tport too?
  Serial1.swap(0);
  Serial1.begin(9600);
  Serial1.println("dev board 2");

  // setting up the tja1021?
  digitalWrite(txEnPin, HIGH);
}

void loop() {
  if ( Serial.available() ) {
    
    byte t = Serial.read();

    if ( true) {
      analogWrite (ledPin, 255);
    }

    else analogWrite (ledPin, 0);

  }
 }

Any ideas comments, are more than welcome!

Best.

Your topic does not indicate a problem with IDE 1.x and therefore has been moved to a more category section of the forum.

Please post full code so those that might be able to help (not me) have something to go on.

Hi, thanks for your help!

Maybe you need to set it to LOW when Reading...

hi Rintin, tin :slight_smile:

Sorted, it was only HIGH, this actually turns on the transciever, however, now I need to have a look at how to turned it off when not needed, actually to put into sleep!

Serial wise , how to sort out the proper print, for example. if 10 is sent the slave is reading 33 ...

Best.

One idea is to have a single master that is in control of the communication.

Only the master can start a request.
Devices respond then they are addressed by a request.

Sending a data frame could be like this:

digitalWrite(txEnPin, HIGH);
Serial.write(...);
Serial.flush();
digitalWrite(txEnPin, LOW);