Go Down

Topic: Serial.available() returns nothing on Atmega1280 (arduino mega) (Read 922 times) previous topic - next topic

Osias Neto

Jan 24, 2012, 10:08 pm Last Edit: Jan 24, 2012, 10:11 pm by Osias Neto Reason: 1
I have a huge code (more than 10000 lines), but is something like this:

Code: [Select]

void setup()
{
   Serial.begin(9600); // PC
   Serial1.begin(1200); // Flex Led
   Serial2.begin(1200); // FL do BMV que testa o BMC
   Serial3.begin(1200); // FL do BMC que testa o BMV
   
   Wire.begin(); // entra como mestre i2c

  analogWrite(5, 100);
}

void loop
{
      Wire.beginTransmission(9);
      Wire.write('a');
      Wire.endTransmission();

      Wire.beginTransmission(10);
      Wire.write('b');
      Wire.endTransmission();
     
      if (Serial2.available()>0) Serial.print( Serial2.read());
      if (Serial3.available()>0) Serial.print( Serial3.read());
      if (Serial1.available()>0) Serial.print( Serial1.read());
}


My problem is, Serial(2,3,1).available is returning nothing, but I can read the characters with a scope.

I know it's not a connection problem... does someone know about any "compatibility" problem because to many communications + PWM?

I'm trying to eliminate the possibilities, I'm also considering a RAM problem (but the sofware is not freezing anyway).

Could someone help me?

Any hint is welcome

Nick Gammon


My problem is, Serial(2,3,1).available is returning nothing, but I can read the characters with a scope.


Just to clarify, you mean they are returning zero? How do you know this? You might be getting a non-printable character.

Nick Gammon


My problem is, Serial(2,3,1).available is returning nothing, but I can read the characters with a scope.


What about with a logic analyzer? The data might be garbage. Anyway, can you reproduce with a minimal sketch like you showed?

Osias Neto

when I said "scope" I mean that I use another Arduino connected in paralel with the comunication (for debug pourposes) and this other Arduino read the characters as expected, but at the same time the "main Arduino" doesn't receive anything =/

My code is much more complicated than I show (its about 20000 lines O.O ), but it's about the in the final... I'm really thinking the problem is about RAM, because I'm using a lot of libraries like wire, spi, flash and EEPROM, and have a lot of strings to a lcd (i2c). Of course I'm using Flash to avoid overflow the RAM with strings, but I'm think it's not enough...

Quote
Just to clarify, you mean they are returning zero? How do you know this? You might be getting a non-printable character.[/quote
I means if I do "variable = Serial2.available()", variable will be always 0, but actualy I can see that's not true.

Nick Gammon


Osias Neto

Quote
And if you disconnect this debugging Arduino?

Nothing changes :/

Osias Neto

#6
Jan 25, 2012, 01:53 pm Last Edit: Jan 25, 2012, 06:50 pm by Osias Neto Reason: 1
I just try it:
Code: [Select]

if (Serial2.available()>0)
{
  Serial.print( Serial2.read());
  Serial.print("c");
}

else
{
  Serial.print("a");
  Serial2.print("b");
}

I'm receiving nothing on Serial Monitor, so Serial.print is not working too!

Any idea?

Osias Neto

I found the problem! I didn't know is required pull ups on these lines, only a noob mistake :P

Thanks for help

Nick Gammon

I didn't know that either. Mind you, my test worked. Still, glad it works for you. :)

Go Up