View previous topic :: View next topic |
Author |
Message |
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Sat Apr 05, 2014 6:29 pm Post subject: receive on Uart |
|
|
Hi,
Enviroment work: arduino2560 R3, Bascom avr 2077.
I connected 2560 and pc with rs485. I have Uart1 with buffer:
Code: | Config Serialin1 = Buffered , Size = 100 , Bytematch = All |
and the right interrupt:
Code: | 'Label called when UART receives a char
Serial1bytereceived:
While Ischarwaiting(#2) > 0 'while there are bytes in the buffer
A = 0
A = Inkey(#2)
Print #2 , A
Waitms 10
Wend
Return |
The problem is that when I send from terminal 1 byte es: 5D, it answer with 5D (93). But if I send 5D 5D, it answer with value that i don't understand.
Please, can you explain me waht happen?
Best Regards
(BASCOM-AVR version : 2.0.7.7 ) _________________ Bascom AVR full |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Apr 05, 2014 9:10 pm Post subject: Re: receive on Uart |
|
|
suibaf wrote: | Please, can you explain me waht happen? |
Improper use of the buffered routine and improper use of the ISR-extension Serial1bytereceived.
Bascom contains samples, which show proper use. |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Sun Apr 06, 2014 8:04 am Post subject: |
|
|
It seems to me rather reasonless first to make an input buffer an then try to do something after each byte received.
You need no bytematch in your code.
Code: | Config Serialin1 = Buffered , Size = 100
Enable Interrupts 'needed for buffered serial
Do
If Ischarwaiting(#2) = 1 Then 'if there is a byte in the buffer ;;;; Edit: "Then" added
A = Inkey(#2)
Print #2 , A
End If
Loop
End |
(According to Bascom help example.)
Last edited by Visovian on Sun Apr 06, 2014 11:22 am; edited 1 time in total |
|
Back to top |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Sun Apr 06, 2014 9:52 am Post subject: |
|
|
Inkey no work in my case because i have zero value on transmission. (According to Bascom help)
And, i have tested your code but no work. In my opinion because i have RS485, timing problem may be. Now i have found a solution but i have problem with printbin. I explain:
Code: | Printbin #2 , Rcv_buff(1) ; Num_byte |
Num_byte = 7, but printbin send on serial all array.
If I replace num_byte with 7 it work perfectly. Is it not possible to pass to printbin a variable that specify number byte?
Thanks and best regards[/quote] _________________ Bascom AVR full |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Sun Apr 06, 2014 11:18 am Post subject: |
|
|
Quote: | Is it not possible to pass to printbin a variable that specify number byte? |
You can use for example
Code: | For I = 1 To Num_byte
Printbin Rcv_buff(i) ; 1
Next
|
|
|
Back to top |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Sun Apr 06, 2014 11:42 am Post subject: |
|
|
Yes that is a solution!
But why it no possible topass to printbin the number of byte with a variable? And if it is no possible, why Bascom does not warn? _________________ Bascom AVR full |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Sun Apr 06, 2014 12:12 pm Post subject: |
|
|
Quote: | But why it no possible topass to printbin the number of byte with a variable? |
Simply because Bascom cannot do everything that comes to one's mind.
Bascom supposes (just like the other languages) that user will himself write nonincluded functions.
Quote: | if it is no possible, why Bascom does not warn? |
But it is clearly described in Bascom-help:
PRINTBIN
...
The number of bytes to send can be specified by an additional numeric parameter. |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Sun Apr 06, 2014 1:07 pm Post subject: |
|
|
Quote: | if it is no possible, why Bascom does not warn? |
If you ask why a compilation error is not reported, it is because there is no syntax error.
Code: | Printbin #2 , Rcv_buff(1) ; Num_byte |
It is a valid code. It means:
Printbin whole array Rcv_buff() , then Printbin value of variable Num_byte. |
|
Back to top |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Sun Apr 06, 2014 2:42 pm Post subject: |
|
|
Visovian, thank you very mach for your help!
Best Regards
Fabio _________________ Bascom AVR full |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Sun Apr 06, 2014 3:55 pm Post subject: |
|
|
Good Luck! |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
|
Back to top |
|
|
suibaf
Joined: 03 Oct 2004 Posts: 32 Location: Lecce
|
Posted: Tue Apr 15, 2014 10:40 am Post subject: |
|
|
In Bascom help, config serialin there is:
When using the BYTEMATCH option, you must preserve the registers you alter.
What does it mean? Can you explain me please? _________________ Bascom AVR full |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 15, 2014 9:09 pm Post subject: |
|
|
the buffered routines are interrupt driven. only the used registers are saved. the bytematch was just intended to set some flag so a user known that some data was received.
in such a case you do not need to do a thing.
but some write complete apps inside this byte match interrupt which destroys registers which are not saved. in such a case, use pushall/popall to make sure you do not destroy regs during the interrupt.
and remember : keep the time in the byte match small since otherwise you might miss data. _________________ Mark |
|
Back to top |
|
|
|