Find the answer to your Linux question:
Results 1 to 2 of 2
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. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    2

    serial comm issue when reading sensors...


    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;
    }

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,422
    This is why we have debuggers. Build the code with the -g compiler flag and don't strip the executable. Then run it in gdb, single stepping it thru your problem code to see exactly what is going on.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •