Menu

UART-1

2025-07-29
2025-08-16
  • Jan Kromhout

    Jan Kromhout - 2025-07-29

    The standard uart buffer is in flashforth 5 on the scamp3 31 bytes. Is it posible to enlarge this buffer?
    Or is it posible to write my own interrupt driven buffer, without any conflict with the one now installed for handling the uart receive?

     
  • Mikael Nordman

    Mikael Nordman - 2025-08-06

    No, it is not possible without recompiling FF.

    It should possible to install your own UART RX routines but it is not trivial. You have provide your own version of RX1, RX1? and the interrupt routine. And these have to be installed after every restart using a turnkey word.

     
  • Mikael Nordman

    Mikael Nordman - 2025-08-08

    I wonder why you would you need a larger interrupt buffer ?
    Normally the application will empty the interrupt buffer to its own buffer using KEY and the scamp is quite fast to do that. Or do you have a very slow application ?

     
  • Jan Kromhout

    Jan Kromhout - 2025-08-08

    I'm interfacing the esp-01 with a scamp. Will use the AT commands, and the response in my case calling a timeserver is greater than 31 characters. After sending the command I will wait until the OK promt or ERROR promt is send back. maby yoy have other sugestions to solve this? Cheers Jan

     
  • Mikael Nordman

    Mikael Nordman - 2025-08-08

    I do not understand your problem. How are you using KEY or ACCEPT ?
    Could you describe the procedure in more detail.

     
  • Jan Kromhout

    Jan Kromhout - 2025-08-08

    I wont to read the timeserver, he send via esp-01 a stream of ascii data. My first idee was to put all in the uart buffer, and from there extract te time and date. Have no thoughts about going another direction. Are you thinking about an another way to extract?

     
  • Mikael Nordman

    Mikael Nordman - 2025-08-08

    You cannot use the interrupt buffer to store data. Your task as a application programmer is to empty the interrupt buffer as fast as possible into your application buffer using KEY and KEY? or ACCEPT (which uses KEY and KEY?)
    If the stream of data ends in a newline you can use ACCEPT to receive the data into your own buffer. If the data ends in some other way you must write your version of ACCEPT to receive your custom data. I think I have an example of receiving NMEA data somewhere. I'll try to find it.

     
  • Jan Kromhout

    Jan Kromhout - 2025-08-13

    Mikael,
    Thanks again for your response.

    The data the ESP01 sends over the UART consists of multiple parts.
    Each part is terminated with a cr and lf.
    However, Accept stops at the first received cr or lf.
    I want to place the entire received data in a buffer, textBuf (255 characters).
    Is there a solution for this in Flashfort?

    Thanks in advance.
    Jan

     
    • Mikael Nordman

      Mikael Nordman - 2025-08-16

      Do you know how many parts there are in a message ?
      You can call ACCEPT multiple times and copy the data to your own buffer.

       
    • Mikael Nordman

      Mikael Nordman - 2025-08-16

      Here is an example.

      : append ( addr len str -- )
        >r r@ dup c@ + 1+        \ addr len end+1
        swap >r r@ cmove
        r> r> dup c@ rot + swap c! 
      ;
      
      ram create mesg 256 allot
      : getmesg
        tib 20 accept tib swap mesg place
        tib 20 accept tib swap mesg append
      ;
      
       
  • Pere font vilanova

    you cam read with rx1.
    0 value index
    begin index 255 < while rx1? if rx1 textbuffer index + c ! index 1 + to index then repeat
    it's not tested, but you can test and improve and it will work.
    you can think other similar alternatives.

     
  • Jan Kromhout

    Jan Kromhout - 2025-08-16

    As answer on your question, when I make a WiFi connection with AT command there are 3 or 4 parts, but I have seen with the analyser the time between the parts are different, and unpredictable.

     
    • Mikael Nordman

      Mikael Nordman - 2025-08-16

      I was just wondering if you for a specific request get a specific amount of reponses. If it is a variable amount you must find a way to handle that.

      There is no timeout in ACCEPT so calling it from the main task would block it if there is no data coming in.

      I would put the ACCEPT calls in a background task and take each response into a separate buffer in a round robin fashion. Then with help of some global variables the main task can analyze the buffers and take whatever action is needed.

       
  • Jan Kromhout

    Jan Kromhout - 2025-08-16

    I have a question about receiving the answer from the esp01. I get several chunks of code terminated with cr/lf. But how to stop the loop of reading the charachters from the uart, to go furher with the program. The gap (ms) between the data chunks is also not constant. Have no clou how to break out this kind of loop.

     
    • Mikael Nordman

      Mikael Nordman - 2025-08-16

      The best way would be to write an accept version that supports a timeout. I don't have code for that.
      Or you could put ACCEPT in a background task as I explained earlier.

      One way would be to check with KEY? if there is a character waiting and after that call ACCEPT, then ACCEPT should not hang if just the string is terminated with a newline.

      : accept2 ( addr len -- len) key? if accept else 0 then ;
      
       

      Last edit: Mikael Nordman 2025-08-16
  • Mikael Nordman

    Mikael Nordman - 2025-08-16

    An additional note on using ACCEPT. The IO must be initialized to use RX1 and RX1? for it to work with the serial port and after using it changed back to the USB connection to use RXU RXU? TXU.
    In order for ACCEPT not to echo everything it receives ( which would mess up the esp01 I suspect), EMIT should be configured to DROP instead of TX1.

     
  • Mikael Nordman

    Mikael Nordman - 2025-08-16

    So maybe this would be feasible.

    : accept2 ( addr len -- len) key? if accept else 0 then ;
    : >uart1 ['] rx1 'key ! ['] rx1? 'key? ! ['] drop 'emit ! ;
    : >usb   ['] rxu 'key ! ['] rxu? 'key? ! ['] txu  'emit ! ;
    
    ram create resp1 32 allot
    ram create resp2 32 allot
    ram create resp3 32 allot
    ram create resp4 32 allot
    
    : connect
      s' AT+CONNECT,"bla",bla' sendcommand
      100 ms resp1 1+ 31 accept2 resp1 c!
      100 ms resp2 1+ 31 accept2 resp2 c!
      100 ms resp3 1+ 31 accept2 resp3 c! 
      100 ms resp4 1+ 31 accept2 resp4 c!
    ;
    >uart1 connect >usb
    \ check results in resp buffers
    
     

Log in to post a comment.