Pages: [1]   Go Down
Author Topic: Interrupt when receivind seriel data  (Read 197 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I want to get data from a GPS and send them over Ethernet (as Telnet).
I have made a simple program that receives the data from the PGS and sends the data to the seriel port on the USB and to the Ethernet. The output from the GPS shows up both places but some parts are missing. I have found out that it only happens when I want to send the data to Ethernet. It seems like that "client = server.available();" is taking too long time.
My hope is now that I can add an ISR that puts the GPS data into a ringbuffer. But I can't find a way to do this.

My code:

#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#define rxPin 3
#define txPin 2

SoftwareSerial mySerial(rxPin, txPin, true); // RX, TX

byte ip[]      = {192, 168, 14, 224};   
byte dnsSrv[]   = {192, 168, 14, 1};
byte gateway[]   = {192, 168, 14, 1};
byte subnet[]   = {255, 255, 255, 0};
byte mac[]   = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetServer server(23);
EthernetClient client;
int sData;

void setup() 
{
   Serial.begin(9600);
   mySerial.handle_interrupt;
   mySerial.begin(4800);

   Ethernet.begin(mac, ip, dnsSrv, gateway, subnet);
   server.begin();

}

void loop() // run over and over
{
   if (mySerial.available())
   {
      sData = mySerial.read();
      Serial.write(sData);
      client = server.available();
      if (client)
         client.write(sData);
   }
}

-----------
Best regards, Brian
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
My hope is now that I can add an ISR that puts the GPS data into a ringbuffer. But I can't find a way to do this.
I don't think this is the right approach. A couple of other possibilities come to mind.

First would be buffering the data in loop(), until the end of a sentence arrived, and then sending that buffer all at once to the client.

The second would be ignoring the GPS unless there was a client to receive the data. Establishing a connection to the server for each character read from the GPS is going to take more time than is available.
Logged

Pages: [1]   Go Up
Jump to: