Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial comm issue when reading sensors...

Status
Not open for further replies.

kievari

Member level 2
Joined
Mar 14, 2010
Messages
51
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,740
Hi,
I have a configuration consisting of:

1. my Atmega168 MCU connected to some servo motors and sensors, and
2. my Linksys WRT54GL router working under OpenWRT Linux WhiteRussian 9.
3. they have a working and tested serial connection.

Now my problem.
I open a file descriptor to my serial port called /dev/tts/1, and read a sensor (the second

sensor commented, as you see bellow). This works perfect. Then I uncomment the next

sensor, but the code continues to behave as if I didn't uncomment it!

If before the reading of the next sensor I first close my original file descriptor and reopen it, it

starts to work right, but this is inefficient, as I have various sensors and it is not logical to open

and close port for each of them!

Reading Ultrasonic first, and then Digital encoders or vice versa makes no difference.

The code in my MCU is fairly simple and tested. It does nothing but read/write as Linux

commands.

How can I approach to reveal where the problem is?

Linux code:
Code:
//motorController opens "/dev/tts/1" serial port.
   bzero(buffer,256);
    
   while(1==1)
   {
     fprintf(motorController, "@sp\n" ); //s:sensor, p:ping.
     fscanf(motorController, "%s", buffer);
     printf("Ping: %s\n", buffer);

     bzero(buffer,256);

/*
     fprintf(motorController, "@sel\n" ); //e: encoder, l:left.
     fscanf(motorController, "%s", buffer);
     printf("Left Encoder: %s\n", buffer);

     bzero(buffer,256);
*/
   }
    
   fclose(motorController);
   return 0;
}
 

Without knowing too much about what you are doing it sounds
to me as if your file system is caching your code.

Look for a means of flushing the cache associated with the file handle
or - if my idea is correct - you will have to close and re-open as you are
doing - or finally - find a way to prevent your system caching your files (probably not the best solution - use No.1 if you can)

jack
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top