Pages: [1]   Go Down
Author Topic: Arduino BT and serial repeater  (Read 1633 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm using Arduino BT (ATmega328) as "gateway" between a PC and another board (with ATmega164P). The serial connection between the two boards is @ 9600 baud (tried also lower rates). The arduino code is very simple:

Code:
#include <NewSoftSerial.h>

int rxPin = 2;
int txPin = 3;

NewSoftSerial mySerial(rxPin, txPin);

void setup() {
  Serial.begin(115200);
  mySerial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    mySerial.print((char) Serial.read());
  }
  
  if (mySerial.available()) {
    Serial.print((char) mySerial.read());
  }
}


First of all, one question: the serial between atmega328 and the BT chip (WT11) is @ 115200. But it seems I can send data over the virtual COM on the pc at any rate. Is it correct?


Now, let's see the problems. When my own board transmits data to arduino, it repeats correctly each byte to the pc.
When is the PC that sends data to arduino, it repeats only first 3 bytes to my own board. Example: if I send abcdefghi, it will repeats only abc. Of course if I send char-by-char there is no problem.

I was thinking about some buffer underrun (with so small strings?) and implemented a circular buffer:

Code:
#include <NewSoftSerial.h>

#define BUFFER_SIZE  32
#define BUFFER_MASK  (BUFFER_SIZE - 1)

int rxPin = 2;
int txPin = 3;
int head = 0;
int tail = 0;
char buffer[BUFFER_SIZE];

NewSoftSerial mySerial(rxPin, txPin);

void setup() {
  Serial.begin(115200);
  mySerial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    buffer[head] = Serial.read();
    head = (head + 1) & BUFFER_MASK;
  }    
  
  if (head != tail) {
    mySerial.print(buffer[tail]);
    tail = (tail + 1) & BUFFER_MASK;
  }
  
  if (mySerial.available()) {
    Serial.print((char) mySerial.read());
  }
}

But the behavior is the same.
I checked with the oscilloscope: just the first three bytes are transmitted over.

Any hints?

Thanks!
Marco
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13471
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could also be something blocking the receiving of the chars.
DOes the string abcdefghi comes in completely?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm pretty sure of this. If I repeat the incoming chars on the same serial (between PC and arduino) it works fine, even if I transmit a long file.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13471
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Can you tell which device is connected to the hardware serial and which to the NewSoftwareSerial?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm talking about the Arduino BT, thus the hardware serial is connected to the BT module WT11 on the Arduino board itself.
The software serial is connected to an ATmega164P (with hw uart) on my own board.
Logged

Pages: [1]   Go Up
Jump to: