Serial strange behaviour

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
vebryn
Posts: 18
Joined: 16 Dec 2017 02:38

Re: Serial strange behaviour

Post by vebryn » 23 Jun 2018 16:00

Great! SoftwareSerial library work like a charm, adopted! Do you plane to support find and readBytesUntil functions ?

vebryn
Posts: 18
Joined: 16 Dec 2017 02:38

Re: Serial strange behaviour

Post by vebryn » 23 Jun 2018 18:27

Hum, output seems dirty. I introduce a buffer (buf) to avoid Serial overhead.

Code: Select all

#include "SoftwareSerial.h"

SoftwareSerial swserial(11, 12);      // duplex mode on pins 11 and 12
char buf[512];
int i=0;

void setup() {
    swserial.begin(1200);
    Serial.begin(9600); 
}

void loop() {
    while(swserial.available()){
        buf[i]= swserial.read() & 0x7F;
        i++;
        if(i==511){
          Serial.println(buf);
          i=0; 
        }
    }
    
    delay(1000);
}
Z-Uno output
ADCO 02T 00` Y
IAX@`40 9
HCHC 009TAT 000000 B
.
IINST 002 Y
ISOUSC 30 9
/
MTDETAT 000TEC HP..
IIF HC.. <
ISO
HHPHC D .
O05708 1
PTEC H>
OPTARIF HCP 00390 -
HHPHH
Raspberry output (clean)
ADCO 524563565245 /
OPTARIF HC.. <
ISOUSC 20 8
HCHC 001065963 _
HCHP 001521211 '
PTEC HC.. S
IINST 001 I
IMAX 008 2
PAPP 01250 +
HHPHC E 0
MOTDETAT 000000 B

User avatar
PoltoS
Posts: 4126
Joined: 26 Jan 2011 19:36

Re: Serial strange behaviour

Post by PoltoS » 24 Jun 2018 08:59

May be this is because you read 7n1 with 8n1?

p0lyg0n1
Posts: 149
Joined: 04 Aug 2016 07:14

Re: Serial strange behaviour

Post by p0lyg0n1 » 24 Jun 2018 17:03

You can't read 7n1 with this, cause it has different timing. Stop bit will be "too early". I can give an idea how to modify the code of library for your purposes. How many bytes do you have in one portion of data? At this moment library uses 32 bytes for cyclic buffer.

p0lyg0n1
Posts: 149
Joined: 04 Aug 2016 07:14

Re: Serial strange behaviour

Post by p0lyg0n1 » 24 Jun 2018 17:43

Here is a modified version of Library. Place it to libraries folder an use like this:

Code: Select all

#include <SoftwareSerial7N1.h>
SoftwareSerial7N1 swserial(11, 12);
// ...
Attachments
ZUNO_SofwareSerial7N1.zip
(2.89 KiB) Downloaded 9 times

vebryn
Posts: 18
Joined: 16 Dec 2017 02:38

Re: Serial strange behaviour

Post by vebryn » 27 Jun 2018 22:40

p0lyg0n1 wrote:
24 Jun 2018 17:43
Here is a modified version of Library. Place it to libraries folder an use like this:

Code: Select all

#include <SoftwareSerial7N1.h>
SoftwareSerial7N1 swserial(11, 12);
// ...
Interesting, it gives an idea on how to modify SoftwareSerial library to support more coding method.

I think I'm wrong with 7n1. According following documentation extract, I'm based on 7e1 (7 data bits, 1 parity bit and 1 stop bit).

Image

As far as I understand, the SoftwareSerial library works twice speed as baud speed. It detects 0L and counts 8 bits. How is done synchronization ? How to be sure that 0L is a start bit and not a data bit ?

p0lyg0n1
Posts: 149
Joined: 04 Aug 2016 07:14

Re: Serial strange behaviour

Post by p0lyg0n1 » 28 Jun 2018 23:46

Start bit is always 0, stop bit is always 1. So, the first 0 is the start of transition. It's a main rule of UART protocol. So we have to work twice faster to follow the theorem of discretization. Looks like you could use the simple 8N1 UART. I don't understand why it's not work for you. Could you connect a logic analyzer to your device? Something like saleae or it's clone. At least you could use Arduino as logic analyzer for your case. The baudrate is not fast. See this https://hackaday.io/project/1633-arduin ... c-analyzer

Post Reply