Arduino Mini Serial can send cannot read with specific baud

Hi !
I got this problem with my two Arduino Minis 5v 16Mhz communicating through Hc-05 modules.
At 230400 baud rate something weird is happening. Writing over Serial seems to be good ( im reading it by TeraTerm and everythings correct ), but when it comes to reading Serial, something weird is happening. There are alot of errors, and they are pretty much the same. But to be more specific, there are my codes.

Transmitter ( continously writing “a” sign ) :

void setup() { 
  Serial.begin(230400);
}

void loop() { 
   Serial.write(97);
}

Reciever ( using data array, since simultaneous writing would cause errors ) :

int data[100];
int x;

void setup() { 
  Serial.begin(230400);
  x=0;
}

void loop() { 
if(Serial.available()>0){
  data[x]=Serial.read();
  x++;
} 
if(x>=100){
 for(int i=0;i<100;i++){ 
   Serial.write(data[i]);  
 }
 while(1){}
}
}

So. Readings ( from TeraTerm ) at input are : “aaaaaaaaaaaaaaaaaaaaaaaa…”
But what came to the reciever Arduino was : “aaXaXaXaaXaXaXaaXaXaaX…”
Literally.

I understand that there could occur some errors, but why are the errors always the same ? When sending “a” there is “X”, when sending other signs, there are other errors ( but they are somehow paired Data<->Error ). What could be possible cause of such occurence ? I’ve tried the same programs at lower baud rates and everything was fine. Also adding a delay 100-200ms delay between sending individual signs removes the errors.

why 230400 ? what about using different baud?! lower one

I've tried the same programs at lower baud rates and everything was fine. Also adding a delay 100-200ms delay between sending individual signs removes the errors.

This would be one of most obvious solution for this problem ( since I tested lower bauds, right ? :smiley: ) but I simply cant. The application is meant to transmit and recieve audio signal ( live ).

Serial.write() and Serial.read() takes similiar amount of time ( measured by "micros()" ) which is ~74us for 115200 baud, and ~44us for 230400. My single audio sample is 8bit long, so single read and write operation is needed. Target frequency for transmission of voice is 8kHz, so approx 1 sample every 125us. 2*74us>125us so it has to be baud 230400 or higher ( who knows, maybe even 230400 isnt enough ). Im not sure, but Serial.write operation is pretty effective ( 115200 baud -> perfectly it would be 115200/8=14400 byte/s but with Serial.write() it's ~13513byte/s so its good enough ). I cant see any other way than increasing baud rate. I know that Arduino 16Mhz oscillator is bad for baud rates, especially those higher, but so far I cant change quartz. Using different bauds ( like 250k ) is blocked from Hc-05 side. But the thing is, that Arduino transmits data at this baud perfectly fine, and have WEIRD problem at recieving such data. The weirdness of the problem is that the Data isnt totally random signs. They match some pattern. Any ideas? :slight_smile:

then check this article it will help you allot :wink:

Oh. I've noticed two facts :

-Arduino Serial Library isnt very effective.

-230400 is very bad pick for 16Mhz clock, so are higher baudrates avaible for Hc-05 baudrates.

Theoretically 115200 baudrate would be enough, or almost enough ( i still cannot find information if we count start and stop bits in dividing baudrate ). But there will be always some delays from serial library from Arduino so... it still doesnt solve my problem. Is swapping resonator for 14.7456 Mhz ( and enabling it running at 230400 baud ) only solution ?

Try a more reliable code for receiving your data. See the 2nd example in serial input basics.

…R

Hi Robin !
Thanks for your contribution in topic. After browsing your code... I cant see any important differencies between your and mine ( besides you using char, and me using int array ). Start and end of stream markers wont work in my project, since this is not a single data sent from one Ardu to another. It's a byte-stream, so using additional characters wouldnt be necesarry. And about this "newData" bools. They are there to indicate end of package, and initiate displaying it. My solution for such thing was monitoring "x" variable value, and initiate display of package after filling whole array. If I missed something, please point me to it :slight_smile:

I was thinking that your code would loop() faster than the data arrives - but looking at it again that is probably not true.

...R

So the topic is still open :slight_smile:
If I understand those "error" rating well, my output should be totally random scraps of chars. But it's not. Sending over hc-05 at 230400 works perfectly well, and recieving is only partially good ( since its only half broken... ). The queston but why its not like "ab2093bcxnia12-0sdeas-0wq.vxc.,sd" ? And the second question is - are the higher ( than 115200 ) out of reach of my Arduinos ? :slight_smile: I mean, i know changing the oscillator to 14.7456Mhz would fix those errors... but they are so small that soldering it is probably out of my reach. And why errors occur only at recieving data...

And the second question is - are the higher ( than 115200 ) out of reach of my Arduinos ?

Nop you did not read that article ::slight_smile:

The Arduino Serial Monitor window limits you to 115200, but that's not the highest baud rate capable. You can read the Atmel and the FT232 (or whatever you're using) datasheets to find out the maximum but I am able to successfully use 230400 (twice as fast as the largest the Arduino Serial Monitor supports) with no issues.

Serial ?! what serial?! sometime you mention serial as receiver other time as transceiver! Acctully I didint understand anything
Simple, make it simple with shorter description! what exactly you are tying to do?!
and please post the whole code

Can you try sending data at 230400 baud directly from your PC using USB. That should work and if it does it suggests the problem is with your HC05 module rather than your Arduino.

I have had no trouble using USB at 500,000 baud.

...R

narzan:
Nop you did not read that article :slight_smile:

I did. I was asking about higher bauds available for hc-05 which is 230400, 460800 etc :slight_smile: I’ve posted the whole code since for now im just trying to establish working transfer between those two Arduinos at this baud rates :slight_smile: The idea of testing Serial.read() with USBPC sounds like a good idea ( i cant recall if i tried already ). Will test it asap.

[Update]

I’ve tried Serial connection at baut 230400 between PC Terminal and my Arduino and it worked flawlessly ! So the problem is with Hc-05… and only with recieving data, to be more specific, since sending works good. Any ideas why ?

[Update2]

It’s also not fault of Hc-05 itself, since my other >not_Arduinos< device are capable to communicate at 230400 without any problems ( with very similiar code ). Hmm, now I cant see the reason why it’s not working on Arduinos :slight_smile: