Pages: [1]   Go Down
Author Topic: Serial.available() returns nothing on Atmega1280 (arduino mega)  (Read 811 times)
0 Members and 1 Guest are viewing this topic.
Curitiba PR, Brazil
Online Online
Sr. Member
****
Karma: 0
Posts: 254
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a huge code (more than 10000 lines), but is something like this:

Code:
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
« Last Edit: January 24, 2012, 04:11:52 pm by Osias Neto » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Curitiba PR, Brazil
Online Online
Sr. Member
****
Karma: 0
Posts: 254
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And if you disconnect this debugging Arduino?
Logged

Curitiba PR, Brazil
Online Online
Sr. Member
****
Karma: 0
Posts: 254
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And if you disconnect this debugging Arduino?
Nothing changes :/
Logged

Curitiba PR, Brazil
Online Online
Sr. Member
****
Karma: 0
Posts: 254
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just try it:
Code:
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?
« Last Edit: January 25, 2012, 12:50:17 pm by Osias Neto » Logged

Curitiba PR, Brazil
Online Online
Sr. Member
****
Karma: 0
Posts: 254
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks for help
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: