Go Down

Topic: Reading a RS232 frame and extracting a byte (Read 1 time) previous topic - next topic

tf68

What happens if you put this in setup instead of loop?

Code: [Select]
 
myservo.write(50);                  // enables FADEC to be in running mode                           // waits for the servo to get there
analogWrite(3,127);                 //simulates RPM signal (~29KRPM)


And now I'm out of ideas, good luck!

marc426

I will try it tonight.

And thank you for your help!!

Another interrogation from yesterday :
I connected the FADEC to a USB to RS232 / TTL converter and even though the serial terminal (termite in my case) did recognize and communicate with it, I only had [00] coming in.

But connecting through the arduino, no problem at all...


Marc

marc426

Ok,

Tried to put the instructions in the setup instead of the loop ==> no difference...

I tried with my MEGA (and thus eliminating the softwareserial) and I get different results but not necessarily better...

Now I get some numbers and  a lot of 0's between them, something like this (not actual extract) :

Code: [Select]

0
0
0
252
0
0
0
155
0
235
0
0
0
160
...

marc426

I have a doubt now...

Might be silly to ask but : until now I've been only connecting the TX from the FADEC to the RX on the arduino but not any other pin (no RS to TX).
Can that change anything? For me the serial is full duplex and since there's no CTS or CTR etc... there's no "exchange" between the receiver and the sender...

Am I right?

marc426

Hi everyone,

Been trying to solve this problem again this weekend.
So I tried with a MEGA which has 4 native serial channels and...

At first it didn't work but then I upped the serial to PC speed and at 19200 it started working for a while and then at 57600 it worked for 10 minutes without any problem (didn't try any longer than that).

Tried again at home with the UNO but even with 57600, it didn't work...

But anyway, has anyone encontered this kind of desynchronization problem already?

Thanks for the help,


Marc

marc426

Hi guys,

starting to see the light at the end of tunnel (it's working but with a serial to PC >19200bauds) but still got a couple of questions if anyone bothers to read anymore  :D

So here's a bit of code I put in my MEGA to check if I still get my synchro (252 followed by 253) correctly.

Code: [Select]

byte incomingByte;
const int frameLength=50;
char buff[frameLength];
byte c;
int i;

void setup()
{
  Serial.begin(19200);
  Serial.println("Salut");
  Serial2.begin(2400);

}

void loop()
{

if(Serial2.available()>0);
{
Serial.println(Serial2.read());
}
  } 


But even though I test the serial.available() being > to 0, i sometimes get -1 between two correct bytes. Sometimes even two "-1"!

I thought testing for serial.available()>0 would take care of that problem but it seems not... Why?? I tried with a condition >1 with the same results...


Thanks for the help!


Marc

Robin2


But even though I test the serial.available() being > to 0, i sometimes get -1 between two correct bytes. Sometimes even two "-1"!


What data is being sent to your Mega, and what is it coming from?  You may have said earlier but this is a long Thread.

I'm not sure if it was mentioned earlier but when using an Uno you can't use the Servo library and SoftwareSerial in the same sketch as they interfere with each other. You could use the ServoTimer2 library which you will need to download. I got my copy here. Alternatively I wrote an alternative and basic version of software serial here.

...R

tf68

Well Serial.available() will prevent reading the buffer when it is empty. So the -1's very likely represent incoming data. If the datatype is char 255 will print as -1, if the datatype is byte 255 will print as 255. You can cast the Serial.read() as a byte.

Code: [Select]
Serial.println((byte)Serial2.read());

Go Up