Go Down

Topic: reading data from serial port (Read 903 times) previous topic - next topic

ageurtse

Hello,

i try to read data from a serial port and converting it to a unsigned short.
this works so far.
but when i wan't to send a file to the board (1280 bytes)
it stalls at aproximate 440 bytes (the counter i stall's at 222 or 221)

what could it be ?

Below is the program code, later on i which to use the native usb port on my DUE, but for now i stick with the programming port (or i keep switching my usb cable)
the purpose is to load a image from serial port and display it on the tft.




Code: [Select]

#include <UTFT.h>


extern uint8_t SmallFont[];

UTFT myGLCD(CTE36);   // Remember to change the model parameter to suit your display module!

void setup()
{
  delay(1000);
  Serial.begin(115200);
  while (!Serial);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
 
  myGLCD.clrScr();
}


void loop()
{
  unsigned short image[1280];
  int i=0, l=0;
  byte highbyte,y;


  y=0;
  i=0;

  myGLCD.setColor(255,0,0);
  myGLCD.print("Waiting for data",0,0);
   
  while(i < 640){

    if(Serial.available())
    {
    myGLCD.printNumI(l,0,10);
    myGLCD.printNumI(i,0,20);
    l++;
    switch (y)                                     
      {
       case 1:{                                        // if y=1 then load the lowbyte of the unsigned short
        image[i]=(Serial.read() + (highbyte << 8));   // put the lowbyte and higbyte in the image array
        i++;
        y=0;
        break;
      }
      case 0: {                                        // if y=0 load highbyte of the unsgned short
        highbyte=Serial.read();           
        y=1;
        break;
      } 
    }
  }
}
  myGLCD.print("done",0,210);             
  myGLCD.drawBitmap(100,100,32,20,image);
}

PaulS

If there is at least one byte available, read both of them.

I don't think so.


Zaplady

#2
Apr 03, 2013, 07:04 pm Last Edit: Apr 03, 2013, 09:14 pm by Zaplady Reason: 1
Hi ageurtse
I was facinated by your post because your code, although unvenventional, looks like it should be able to download your 1280 bytes correctly before it started again through loop. I cannot comment on the GLCD part as I do not have one. I tried this on an Arduino Uno and found that it could, in fact, download the 1280 bytes if I sent them from processing one at a time. However, I could create a very similar problem to yours by setting the bauds rates to a different value at either end e.g. 9600 on processing to match the 115200 on the Arduino and I wondered if that was causing your problem?
Mrs Z

[Edit] I can also get the problem to happen if I start sending the data to the Arduino before it is ready to receive it.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy