Pages: [1]   Go Down
Author Topic: serial.available OK with IDE and KO with C language  (Read 1198 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is an exmple of a code writen with the IDE and tested with the termnal include into IDE. Every thinks are OK, the Serial.available() works fine.

setup()
{  Serial.begin(57600) ;
   Serial.println("Hello, world!") ;
...
}
loop()
{...  i = Serial.available() ; sprintf(errmsg," AVAIL %d",i); Serial.println(errmsg) ; ...


Every thinks are OK.

Now, I write the same code in C language with the plugin eclipse (http://www.baeyens.it/eclipse/), with the same hardware, on the same computer, the same USB port, .... of course I can load the code on the target. The println command works fine, but the available() commande always return 0. I use the IDE terminal as terminal like in the first example.

Have you some ideas ? Do I use the right RX port ? A configuration ? Does the IDE libraries are the same as the C libraries ?

SoftwareSerial mySerial(0,1) ; // RX, TX == 1
 
void setup()
{
   mySerial.begin(57600) ;
   mySerial.println("Hello, world!") ;
...
}

void loop()
{ ...
 j = mySerial.available() ; sprintf(errmsg," AVAIL %d",j); mySerial.println(errmsg) ;

Logged

Chile
Offline Offline
Edison Member
*
Karma: 35
Posts: 1251
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you can't use the pin 0,1 with software serial (besides there is no point of doing that)
Logged

My website: http://ried.cl

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have right.

What I need is the Serial object in Cpp, like in the IDE. I don't understand how to have Serial in C :
  • Serial is not found by the link editor
  • Serial seems to be a C know symbol
  • Serial.begin is defined

I imagined that SerialSoftware was a solution, but it is not.

Do you know how to use Serial in C ?
Logged

Chile
Offline Offline
Edison Member
*
Karma: 35
Posts: 1251
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I always use the IDE, but just compile once verbose and you will see what includes to do it yourself without the IDE.
Logged

My website: http://ried.cl

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you know how to use Serial in C ?
The Arduino IDE is C.  What you don't see is that the IDE adds the appropriate headers to the code before passing it off to the compiler.  Eclipse doesn't know to do that.  So you need to include "HardwareSerial.h" yourself.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Pages: [1]   Go Up
Jump to: