Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

receive on Uart

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Sat Apr 05, 2014 6:29 pm    Post subject: receive on Uart Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Sat Apr 05, 2014 9:10 pm    Post subject: Re: receive on Uart Reply with quote

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
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Sun Apr 06, 2014 8:04 am    Post subject: Reply with quote

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
View user's profile
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Sun Apr 06, 2014 9:52 am    Post subject: Reply with quote

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
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Sun Apr 06, 2014 11:18 am    Post subject: Reply with quote

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
View user's profile
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Sun Apr 06, 2014 11:42 am    Post subject: Reply with quote

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
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Sun Apr 06, 2014 12:12 pm    Post subject: Reply with quote

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
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Sun Apr 06, 2014 1:07 pm    Post subject: Reply with quote

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
View user's profile
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Sun Apr 06, 2014 2:42 pm    Post subject: Reply with quote

Visovian, thank you very mach for your help!

Best Regards

Fabio

_________________
Bascom AVR full
Back to top
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Sun Apr 06, 2014 3:55 pm    Post subject: Reply with quote

Good Luck!
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sun Apr 06, 2014 11:59 pm    Post subject: Reply with quote

A search of this forum with keyword printbin would have shown that the useage of printbin has been discussed many times. For example quite recently:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12096&highlight=printbin

Would suggest that before posting, users use the search first, to save us answering the same questions multiple times.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
suibaf

Bascom Member



Joined: 03 Oct 2004
Posts: 32
Location: Lecce

italy.gif
PostPosted: Tue Apr 15, 2014 10:40 am    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Tue Apr 15, 2014 9:09 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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