• Please share your s.setup() line

  • var MAX485_DE = D12;
    var RXPIN = D13;
    var TXPIN = D14;
    var Serial3 = new Serial();
    Serial3.setup(9600, {rx:RXPIN,tx:TXPIN, parity:'even'});
    Serial1.setup(9600, {parity:'even'});

  • Yes can confirm this, please check https://github.com/espruino/Espruino/issues/1510

    You are welcome to fix this ;-)


    1 Attachment

    • Bildschirmfoto 2018-10-28 um 08.13.43.JPG
  • @MaBe,
    Try this, it compiles and loads without errors, but has not tried the communication.

    /// Settings passed to jshUSARTSetup to set it the USART up
    typedef struct {
      int baudRate;            /// FIXME uint32_t ???
      Pin pinRX;
      Pin pinTX;
      Pin pinCK;               ///< Clock, or PIN_UNDEFINED
      Pin pinCTS;              ///< Clear to send, or PIN_UNDEFINED
      unsigned char bytesize;  ///< size of byte, 7 or 8
      unsigned char parity;    ///< 0=none, 1=odd, 2=even
    '#if defined(ESP8266)
      unsigned char dummy;      // insert PB
      unsigned char dummy1;     // insert PB
    '#endif
      unsigned char stopbits;  ///< 1 or 2
      bool xOnXOff;            ///< XON XOFF flow control?
      bool errorHandling;      ///< Whether to forward parity/framing errors
    } PACKED_FLAGS JshUSARTInfo;
    
    
    
    Serial2.setup(9600,{rx:D12,tx:D13,ck:D14,cts:D15,bytesize:8,parity:'even',stopbits:1});
    
     1v94.209 Copyright 2017 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 512KB:256/256, manuf 0xc8 chip 0x4013
    >
    =undefined
    >
    =undefined
    >
    =undefined
    >Se
    Serial3             Serial
    Serial2             Serial
    Serial1             Serial2
    Server
    >Seri
    Serial3             Serial
    Serial2             Serial
    Serial1             Serial2
    >Serial2._options
    ={ "rx": D12, "tx": D13, "ck": D14, "cts": D15,
      "bytesize": 8,
      "parity": "even",
      "stopbits": 1 }
    >
    =undefined
    
    

    '#if defined(ESP8266)
    '#endif
    Remove apostrophe in front of #

  • Wow nice work around - Thanks for sharing @Frida

    Hmm cause reboot for ESP8266_BOARD and ESP8266_4MB with Espruino 2v00.27

    >require("ESP8266").logDebug(true);require("ESP8266").setLog(2);
    =undefined
    >var s = new Serial();
    =Serial: {  }
    >s.setup(9600,{rx:D12,tx:D13,ck:D14,cts:D15,bytesize:8,parity:'even',stopbits:1});
     20512> Fatal exception 9(LoadStoreAlignmentCause):
    ΓΏ20512> epc1=0x4021846b, epc2=0x00000000, epc3=0x00000000, excvaddr=0x3ffff97a, depc=0x00000000
    
  • Hello @MaBe,
    Downloaded last version from 29 / 10-2018.
    Tested different things and found that 'ck' is not supported in software serial.
    One thing I figured out is that in 'serial2' when I use 'even' and I load the program again, 'esp8266' crashes. However, if I use 'Even', you can reload the program over and over again.
    Then try your software serial again without 'ck'.
    This time I use an 'uint16_t dummy; // insert PB', instead of 'char '

    PS. jeg har kun en ESP8266-01 med 512KB.

  • So after we start to understand why this causes a Fatal exception 9(LoadStoreAlignmentCause) and how to avoid it. Then soft serial needs to be extended to handle parity https://github.com/espruino/Espruino/blob/master/src/jsserial.c#L41

  • Some tests:

    Serial2.setup(9600,{});
    
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 8
    ERROR: *** PB *** PB0 = 11
    ERROR: *** PB *** PB1 = 22
    ERROR: *** PB *** PB2 = 33
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    {  }
    

    By default setup, PB0, PB1 and PB2 are not touched.

    Serial2.setup(9600,{bytesize:7});
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 7
    ERROR: *** PB *** PB0 = 0
    ERROR: *** PB *** PB1 = 0
    ERROR: *** PB *** PB2 = 0
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    { "bytesize": 7 }
    

    With this setup, PB0, PB1 and PB2 are overwritten.

    typedef struct {
      int baudRate;            /// FIXME uint32_t ???
      Pin pinRX;
      Pin pinTX;
      Pin pinCK;               ///< Clock, or PIN_UNDEFINED
      Pin pinCTS;              ///< Clear to send, or PIN_UNDEFINED
      unsigned char bytesize;  ///< size of byte, 7 or 8
      uint8_t PB0;              // insert PB
      uint8_t PB1;              // insert PB
      uint8_t PB2;              // insert PB
      unsigned char parity;    ///< 0=none, 1=odd, 2=even
      unsigned char stopbits;  ///< 1 or 2
      uint8_t PB3;              // insert PB
      uint8_t PB4;              // insert PB
      uint8_t PB5;              // insert PB
      bool xOnXOff;            ///< XON XOFF flow control?
      bool errorHandling;      ///< Whether to forward parity/framing errors
    } PACKED_FLAGS JshUSARTInfo;
    
    

    In the file 'jsserial.c' and in the function 'jsserialPopulateUSARTInfo' there are:

      jsvConfigObject configs[] = {
          {"rx", JSV_PIN, &inf->pinRX},
          {"tx", JSV_PIN, &inf->pinTX},
          {"ck", JSV_PIN, &inf->pinCK},
          {"cts", JSV_PIN, &inf->pinCTS},
          {"bytesize", JSV_INTEGER, &inf->bytesize},
          {"stopbits", JSV_INTEGER, &inf->stopbits},
    

    I do not know what it's doing, but it returns 4 bytes for 'bytesize' and 'stopbits', like 32 bits, but in 'JshUSARTInfo' they are set up as 'chars'

    That is, 'bytesize' overwrites 'parity, stopbits and xOnXOff'.

    It's worse with 'stopbits' because it will overwrite 'xOnXOff' and 'errorHandling' as well as write in an illegal address.

    Maybe we could get a 'JSV_CHAR' to these two.

    If I'm taking a'PICO 'and using:

    Serial2.setup(9600,{});
    
    No errors. Minified 2163 bytes to 70 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >{  }
    

    There's nothing going on.

    
    Serial2.setup(9600,{bytesize:8});
    
    
    No errors. Minified 2173 bytes to 80 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >Uncaught InternalError: Unsupported serial stopbits length.
     at line 1 col 32
    ...al2.setup(9600,{bytesize:8}),console.log(Serial2._options),c...
                                  ^
    > 
    

    Which shows that stopbits are overwritten by 0.

    Hope it is understandable.

  • @Frida: Thanks for testing and sharing your results

    I try to catch up:

    List of addresses of JshUSARTInfo

       br:  0x3ffff970
       rx:  0x3ffff974
       tx:  0x3ffff975
       ck:  0x3ffff976
       cts: 0x3ffff977
       bs:  0x3ffff978
       pa:  0x3ffff979
       sb:  0x3ffff97a
       xx:  0x3ffff97b
       eh:  0x3ffff97c
    

    Now I am testing with some if defs in src/jsutils.h

    
    // # if defined(ESP8266)
    // [#define](https://forum.espruino.com/search/?q=%23define) PACKED_FLAGS_MAYBE  __attribute__ ((__aligned__(16)))   
    // [#else](https://forum.espruino.com/search/?q=%23else)
    // [#define](https://forum.espruino.com/search/?q=%23define) PACKED_FLAGS_MAYBE __attribute__ ((__packed__))
    // [#endif](https://forum.espruino.com/search/?q=%23endif)
    
    

    @Gordon is this how you would thought to use PACKED_FLAGS_MAYBE

    and use this flag for jshUSARTSetup

    /// Settings passed to jshUSARTSetup to set it the USART up
    typedef struct {
      int baudRate;            /// FIXME uint32_t ???
      Pin pinRX;
      Pin pinTX;
      Pin pinCK;               ///< Clock, or PIN_UNDEFINED
      Pin pinCTS;              ///< Clear to send, or PIN_UNDEFINED
      unsigned char bytesize;  ///< size of byte, 7 or 8
      unsigned char parity;    ///< 0=none, 1=odd, 2=even
      unsigned char stopbits;  ///< 1 or 2
      bool xOnXOff;            ///< XON XOFF flow control?
      bool errorHandling;      ///< Whether to forward parity/framing errors
    } PACKED_FLAGS_MAYBE JshUSARTInfo;
    
  • It is not only 'ESP8266', 'PICO' also has problems.

  • Ouch, so let me double check with my pico and than extend this issue with the label "pico board"

  • Wow, ok - sorry everyone (especially @MaBe for thinking this was just ESP8266 specific).

    Thanks @Frida for pointing this out - it's the jsvConfigObject - we define stopbits/etc as JSV_INTEGER, which assumes 32 bits - so the code that scans the serial initialisation object writes past where it should.

    I'll commit a fix for this in the next hour or so - and I'll check out the other config object uses in case there are other similar issues elsewhere.

  • Donated 100,00 USD to
    Pur3 Ltd

  • Wow, thank you - that's awesome! Especially given your previous donations as well!

    Thanks for everyone's help in tracking this down too. It's one of those nice cases where having Espruino on more platforms means more bugs get found and it gets more reliable for everyone.

    Just FYI, the bug/fix is on https://github.com/espruino/Espruino/issues/1510 - in the end I went with just changing the call to jsvReadConfigObject to point to ints and copying them (as it seems that's what I'd done in other places).

    As you suggested, JSV_CHAR would be a nicer idea, but we're using enums from the main interpreter where there isn't such a thing as a char. I guess it might make more sense to move to having a different set of enums for jsvConfigObject - it'd probably help to catch issues at compile-time too.

  • Well Gordon, next time I fetch my Espruino boards for testing as well :)

    Just tested the fix, works great, thanks lot for that quick fix!

    Do you have plans to handle parity ?

  • Do you have plans to handle parity ?

    I do at some point, but honestly that's probably just 'when I need it'.

    If you want it, I'dd to a pull request. At least on sending it's just one extra bit that's pretty easy to calculate.

  • Not need on my side, will ask again if I needed

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

"Serial1.on('data', function (data) {......" not works for me, is works for any other ??

Posted by Avatar for user94070 @user94070

Actions