Go Down

Topic: [SOLVED]Serial1 is dropping bytes! (Read 728 times) previous topic - next topic

Wuerfel_21

May 24, 2015, 03:06 pm Last Edit: May 24, 2015, 05:43 pm by Wuerfel_21
While waiting for answers on the SPI on pin 7 thread, i tried sending some data(for starters i used a ps/2 trackball i had around) over serial1, and i noticed it sometimes drops data!

test code:
Code: [Select]

#include <ps2.h>

/*
 * an arduino sketch to interface with a ps/2 mouse.
 * Also uses serial protocol to talk back to the host
 * and report what it finds.
 */

/*
 * Pin 5 is the mouse data pin, pin 6 is the clock pin
 * Feel free to use whatever pins are convenient.
 */
PS2 mouse(10, 6);

/*
 * initialize the mouse. Reset it, and place it into remote
 * mode, so we can get the encoder data on demand.
 */
void mouse_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void setup()
{
  Serial1.begin(250000);
  Serial1.println("Setting up the mouse");
  mouse_init();
  Serial1.println("Starting...");
}

/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
  char mstat;
  char mx;
  char my;
  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  /* send the data back up */
  Serial1.print(mstat, BIN);
  Serial1.print("\tX=");
  Serial1.print(mx, DEC);
  Serial1.print("\tY=");
  Serial1.print(my, DEC);
  Serial1.println();
  delay(1000);  /* twiddle */
}


To see the data i ssh into the yun and do a "cat /dev/ttyATH0"

Am i doing something wrong, or is the oscillator not doing its job very well? :P

Wuerfel_21

Well, turns out i had to disable the serial shell...
Sadly, i didnt find any information about setting the port to the correct mode, so i will post instructions on how i did it...

jessemonroy650

Well, turns out i had to disable the serial shell...
Sadly, i didnt find any information about setting the port to the correct mode, so i will post instructions on how i did it...
@Wuerfel_21,
I have no information on the serial ports. Whatever you have will be greatly appreciated.
Jesse


Go Up