Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Serialin buffer

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Wed Dec 16, 2020 6:27 pm    Post subject: Serialin buffer Reply with quote

Hi!
Serialin buffer Max. length iz 255 Bytes.
Is there a way to make it bigger?

Br
Andrej

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Wed Dec 16, 2020 7:04 pm    Post subject: Reply with quote

Do you know HELP?
Juast loock up Config Serialin!
Regards Hubert
Back to top
View user's profile
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Wed Dec 16, 2020 7:39 pm    Post subject: Reply with quote

Hubert, you are so kind. Please Look by yourself, and let me know, what "help" says about Max. buffer length.
Thanks.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Dec 16, 2020 8:25 pm    Post subject: Re: Serialin buffer Reply with quote

andro wrote:
Serialin buffer Max. length iz 255 Bytes.

The help tells:
Quote:
Size
A numeric constant that specifies how large the input buffer should be. The space is taken from the SRAM. The maximum is 255.


As you write exactly the same as the help tells, somehow you must not understand what you write.
Tell us exactly which one from the words you wrote you do not understand.

If you've succeeded to manage that, you may also understand:
Quote:
CONFIG SERIALIN
....
The following internal variables will be generated for UART0:

_RS_HEAD_PTR0 , a byte counter that stores the head of the buffer

_RS_TAIL_PTR0 , a byte counter that stores the tail of the buffer.

_RS232INBUF0 , an array of bytes that serves as a ring buffer for the received characters.

_RS_BUFCOUNTR0, a byte that holds the number of bytes that are in the buffer.

that these variables are all bytes, or an array of bytes. A byte can hold values from 0 to 255, this applies the same for _RS_BUFCOUNTR0, which holds the number of bytes in the buffer at runtime.
Quote:
Is there a way to make it bigger?

Sure.
Options are:
1) Throw enough money after Mark and you will get your special version.
2) Write your own buffered input, the disadvantage is: you can not use Bascom's standard input functions.
3) Describe your exact problem and after we have found out that your demand is in reality utter nonsense and not required at all, you can save 1), and 2), and additionally lots of time and expenses.

No need to thank me for this advise, you're welcome.
Back to top
View user's profile
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Wed Dec 16, 2020 10:21 pm    Post subject: Reply with quote

What I do not understand is, What's wrong with both of You...?

A have never encountered such rude answers, not at this Forum, neither at some other.

Conversation with you 2 completed.
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Wed Dec 16, 2020 10:41 pm    Post subject: Reply with quote

Hi Andre,

Here the nice guy from Holland. Wink

It's not that easy to increase the receiver buffer. The data and pointers of the receive buffer are now stored in bytes. Bytes can hold up values to 255.
To increase the buffer size you need to change all those bytes variable to word variable in the librarys and that's a lot of work. And because you are the first that encounters this problem the priority to change this is low.
Low as in close to zero.

I'm working myself now 25 years with Bascom and had never a problem with a to small receive buffer.
If your buffer of 255 bytes is to small then you are not processing the data fast enough or something else is going wrong.
Maybe you can tell us what kind of data you try to handle that requires that big buffer.

You can always design your own ring buffer that can hold more data. Have a look at $SERIALINPUT to capture the received data and do something with it.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Dec 17, 2020 6:45 pm    Post subject: Reply with quote

andro wrote:
What I do not understand is, What's wrong with both of You...?

Nothing is wrong beside your lack of understanding,
I've presented a few feasible solutions and you're still that taciturn not to describe why you think to need an oversized buffer,

If the manual of your car tells you, max speed is 120mph, then you think you can ask a forum how to get it go double as fast, while you don't even tell why.
And then you expect specialists to take you by the hand to teach you all sorts of engine tuning?
LOL, in what fantasy world you're living?

Give, and it shall be given unto you.
You gave what?

Nothing, beside quoting the help.
I had at least the decency to give you some hints, and all you ingrate was able is to ask what's wrong with me.
So what's wrong with you?
Evert Smile wrote:
Have a look at $SERIALINPUT

Interesting. Missed that.
Thanks.
Back to top
View user's profile
hgrueneis

Bascom Member



Joined: 04 Apr 2009
Posts: 902
Location: A-4786 Brunnenthal

austria.gif
PostPosted: Thu Dec 17, 2020 9:09 pm    Post subject: Reply with quote

andro,

I rather think, there is something wrong with you than us,
if you can not read the 'Help' and be fine with it.
If I were you, I would not ask again.
Nobody was rude, just realistic!
And if you are so arrogant, why ask at all?

Regards
Hubert
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Dec 17, 2020 9:56 pm    Post subject: Reply with quote

covid is nasty as it is. so lets do an extra effort here to remain calm. i do not have much time to look after heated threads.

just with all communication it is a matter of interpretation.
i think the TS read the help and knows about the max size. so i consider this a normal question.
it all depends on what TS has in mind.
do you want to know if there is a setting, or some special lib or are you looking for some code?

there is no built in way. because of the overhead and because one can best use HW handshake.
But when there is a need for a big buffer it is not so hard to create one yourself.

Just as with support it is important to give as much details as possible.

_________________
Mark
Back to top
View user's profile Visit poster's website
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Fri Dec 18, 2020 4:35 am    Post subject: Reply with quote

One approach that often works, as mentioned already, is to simply use a small buffer and have a routine that reads its data and puts it into a large que / array / circular buffer, (your code), from which the remainder of the program then draws the data as needed.

That can be done with polling, receive interrupts, timed interrupts, the event system, etc.

JC
Back to top
View user's profile Visit poster's website
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Sun Dec 20, 2020 5:55 pm    Post subject: Reply with quote

Hi,

The problem is in a demand, to send HTML POST to a WEB server, using ESP8266. It's everything fine, but server returns a burst of around 400byte, in case of Error404 even more.
Baudrate is 115200. This burst is faster then I'm able to empty the serialin buffer. I did my own 'serialin, that looks like this:



Code:

'***************** UART5 interrupt ESP8266 ********************************************************
On Usarte1_rxc Rx_int6
Enable Usarte1_rxc , Hi

'**************************************************************************************************
 


Sure; I enable interrupts, since Ialso us timer:
Code:

'  _____  ___  __  __  _____  ____
' |_   _||_ _||  \/  || ____||  _ \
'   | |   | | | |\/| ||  _|  | |_) |
'   | |   | | | |  | || |___ |  _ <
'   |_|  |___||_|  |_||_____||_| \_\s
'*************************************************************************************************
'********************** TIMER CONFIG *************************************************************

Config Tcd0 = Normal , Prescale = 64
Tcd0_per = 5000                                             'period: __ms;
'*************************************************************************************************
On Tcd0_cca Compared0_int
Enable Tcd0_cca , Lo
'*************************************************************************************************
'*************************************************************************************************

Enable Interrupts
 



TIMER ISR:

Code:

'************************************************************************************************************************
'************************************************************************************************************************
'************************************************************************************************************************
'************************************************************************************************************************
'  _____  ___  __  __  _____      ____   _      ___  ____  _____
' |_   _||_ _||  \/  || ____|    / ___| | |    |_ _|/ ___|| ____|
'   | |   | | | |\/| ||  _|      \___ \ | |     | || |    |  _|
'   | |   | | | |  | || |___      ___) || |___  | || |___ | |___
'   |_|  |___||_|  |_||_____|    |____/ |_____||___|\____||_____|

'************************************************************************************************************************
'************************************************************************************************************************
'************************* &#268;ASOVNA  REZINA 10ms *************************************************************************
Compared0_int:
Tcd0_intflags.0 = 1

   Gosub Serial_check6                                      'ESP8266

Return
 


Code:


'(
  ____  _____ ____  ___    _    _          ____ ___  __  __    __
 / ___|| ____|  _ \|_ _|  / \  | |        / ___/ _ \|  \/  |  / /_
 \___ \|  _| | |_) || |  / _ \ | |       | |  | | | | |\/| | | '_ \
  ___) | |___|  _ < | | / ___ \| |___    | |__| |_| | |  | | | (_) |
 |____/|_____|_| \_\___/_/   \_\_____|    \____\___/|_|  |_|  \___/

')


'ISR  COM6  (ESP8266)

Rx_int6:
'Toggle Led1
   If Volume6 = 3500 Then
      Goto Skip_full6
   End If

   Incr Volume6
   Incr Head
   If Head > 3500 Then
      Head = 1
   End If

   Sbuf6(head) = Usarte1_data
Skip_full6:
Return


'*******************************************************************************
' ESP8266
'find a message - 0x0A as end of message; call from TIMER ISR
Serial_check6:

If Msg6 = 1 Then
   Goto Receive_end6
End If

If Volume6 = 0 Then
   Goto Receive_end6
End If


If Tail = 0 Then
    Incr Tail
End If

Com6_s = Chr(sbuf6(tail))                                   'read from buffer
Decr Volume6
Incr Tail
If Tail > 3500 Then
   Tail = 1
End If

If Com6_s = Chr(10) Then                                    'is there a LF ?
   If Com6_n = 0 Then                                       'if LF is the first character, then drop the packet
      Stringx6 = ""
      'Incr Com2_err
      Goto Serial_check6
   Else                                                     'LF is at the enda; message OK
      Com6_n = 0
      Msg6 = 1                                              'set Msg6 flag
      String_main6 = Stringx6                               'copy message to main string var.
      Goto Receive_end6                                     'pazi da v main najprej obdelaš main string, preden resetiraš MSG flag!!??
   End If
End If

'***************** any character received ********************

If Com6_n = 0 Then                                          'if Com_n = 0 this is first character
   Stringx6 = ""
   Stringx6 = Stringx6 + Com6_s
   Incr Com6_n                                              'incr Com_n
Else
      If Com6_n > 3500 Then                                 'check the length
         Com6_n = 0
         'Incr Com2_err                                      'if to long, inc error count
         Stringx6 = ""
         Goto Serial_check6                                 'continue
      Else
         Incr Com6_n                                        'length is OK,
         Stringx6 = Stringx6 + Com6_s                       'add received char.
         Goto Serial_check6                                 'continue
      End If
End If
Goto Serial_check6
'**********************
Receive_end6:
Return
'==========================================================================
 


Msg6 is a variable, that gives the main loop the information, that there is a message in a String_main6 variable.
You can see, if I'm not fast enough, Msg6=1 blocks emptying the buffer. That's whay original 255 bytes is not enough.
The code works, but sometimes in my buffer reamins some bytes, that can not be used.

Therefore, I went back to Basom serialin buffering, including CTS/RTS controll.
I'm able to pause ESP8266, however, now the serialout buffer seems not to be working right.
With external serial monitor I can see, that Xmega sends wrong POST message to ESP - only one byte is always wrong - actualy, it is replaced by 0x08 (bacspace).
The post messsage is like this:



Code:

     Content_txt = "<mm><ci>" + Card_id_txt + "</ci><ii>" + Item_id_txt + "</ii><dkey>" + Device_key_txt + "</dkey><cd>05.09.20</cd><ct>21:49:30</ct></mm>"

      'string2 115

      If Content_length > 99 Then
         Print #6 , "AT+CIPSEND=115"
      Else
         Print #6 , "AT+CIPSEND=114"
      End If
      Waitms 5
      Print #6 , "POST /mm/service/service1.ashx?cmd=save_event HTTP/1.1"       'http://___.si/mm/service/service1.ashx
      Print #6 , "Host: ___.si"
      Print #6 , "Content-Length: " ; Content_length_txt
      Print #6 , "Expect: 100-continue"
      Print #6 , ""
      Waitms 30
 


Sent to ESP (external monitor):
41 54 2b 43 49 50 53 45 4e 44 3d 31 31 34 0d 0a AT+CIPSEND=114..
50 4f 53 54 20 2f 6d 6d 2f 73 65 72 76 69 63 65 POST /mm/service
2f 73 65 72 76 69 63 65 31 2e 61 73 68 78 3f 63 /service1.ashx?c
6d 64 3d 73 61 76 65 5f 65 76 65 6e 74 20 48 54 md=save_event HT
54 50 2f 08 2e 31 0d 0a 48 6f 73 74 3a 20 62 6e TP/..1..Host: bn
74 2e 73 69 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 t.si..Content-Le
6e 67 74 68 3a 20 38 38 0d 0a 45 78 70 65 63 74 ngth: 88..Expect
3a 20 31 30 30 2d 63 6f 6e 74 69 6e 75 65 0d 0a : 100-continue..
0d 0a

Bold 0x08 is wrong! It shoulbd be 0x31.

I know, code above is rather 'confusing'. It was actualy made a few years ago, since I was not able to receive 0x00, using original Seriallin.
But it works fine if messages are shorter then 255B.

Any idea?
Do You suggest to use SAVEALL with Usarte1_rxc ISR? Or to PUSH / POP some particualr registers?
A DMA 'transferr' might be an option, but I'm somehow avoiding DMA (lack of understanding).

Thanks in advance.
Andrej
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Dec 20, 2020 8:09 pm    Post subject: Reply with quote

andro wrote:
Baudrate is 115200. This burst is faster then I'm able to empty the serialin buffer.

Then your code is too ineffective.
115200 Baud are, with start and stop-bit, 11520 bytes per second, assuming the XMega runs with 32MHz, you have 32000000 / 11520 = 2777 cycles to handle one received byte.
This is easily feasible, but not with your code.

For example, such actions:
Code:
Stringx6 = Stringx6 + Com6_s

are costly in terms of cycles, especially if Stringx6 is already longer.
Bascom uses zero-terminated strings, a string does not know it's length, thus in above code Bascom needs to search through the string, byte by byte, till it finds the terminating zero.
Then Com6_s is written into the place of the zero and the next byte becomes the zero terminator.

Let's say you have already 300 bytes in Stringx6 and machine code: load, compare and jump takes 5 cycles, then you have wasted 1500 of your 2777 cycles in above command, only for searching the string's end.
Your other code needs also some cycles.

To speed this up, do an Overlay over the string, dimension a string-index, then address the array with index, save the byte, increase index, write terminating zero.
Or keep everything within the income-buffer, only check for message-end. If end is reached, use a fast routine to copy from buffer- to target-string.
This will cost less. For the rest of the code, I can not imagine that I'd use a timer for this.
Back to top
View user's profile
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Sun Dec 20, 2020 8:23 pm    Post subject: Reply with quote

Hi MWS

Huh, I would newer thougth, this pice of code takes so many cycles. Thanks for this. I apriciate your hint, how to handle this problem other way.
In this app, I'm only doing with ascii, so the 0x00 will never ocure, thus, I can only look for the <LF> at the end and quick copy from the buffer.

Regarding time slicing - the exact timing is crucial in my application . Some events must repeat at exact time period. I have posted only a small part of the code.


BR
Andrej
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Sun Dec 20, 2020 9:38 pm    Post subject: Reply with quote

DMA is the answer ... and easy to implement. And, you'll find that the uC is not blocked while the USART (or other DMA device) is active - just react to the Interrupt.

See: https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14077

You'll find other samples I've posted as well.

E
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum