Uart and timer problem.

soleyj

New member
I am using the teensy 4.1 to comunicate via rs-485 with arduino mega.

I have two sketches one without a timer that works, and other with timer that doesn't wo
Code:
IntervalTimer myTimer;

void setup() {
  // put your setup code here, to run once:
  Serial2.begin(500000);
  pinMode(2,OUTPUT);
  myTimer.begin(mainTimer,20000);
}

void loop() {

  // put your main code here, to run repeatedly:

}

void mainTimer(){
    static byte data[]={11,1,12};
  digitalWrite(2,HIGH);
  Serial2.write(data,3);
  digitalWrite(2, LOW);
}

In this code the arduino don't recive the data. But yes without the rs-485 perhiperal

Code:
IntervalTimer myTimer;

void setup() {
  // put your setup code here, to run once:
  Serial2.begin(500000);
  pinMode(2,OUTPUT);
  myTimer.begin(mainTimer,20000);
}

void loop() {
  static byte data[]={11,1,12};
  digitalWrite(2,HIGH);
  Serial2.write(data,3);
  digitalWrite(2, LOW);
  // put your main code here, to run repeatedly:

}

void mainTimer(){
  
}

And with this code the Arduino receives the data.

For now I don't have an oscilloscope to see the data is sent.

Any suggestions?
 
In your first case, you are sending it about 50 times per second. In the second case you are sending it continuously.

Sometimes for debugging things like this without a scope or logic analyzer, I would toggle pin 13 digitalToggleFast(13); (need to do a pin mode in setup to output)
Where you are doing the writes and see if you notice the led going on and off. Note at those speeds you won't see it stay on, but should see it flicker or dim...
 
Back
Top