Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Receiving zero(0) bytes

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

Bascom Member



Joined: 03 Feb 2006
Posts: 153
Location: EU

blank.gif
PostPosted: Mon Jan 14, 2019 3:12 pm    Post subject: Receiving zero(0) bytes Reply with quote

Is there some way of receiving (UART) zero bytes (e.g. 0,0,0,0), because Ischarwaiting=0 if all bytes are zero(0), only if one is >0 (0,0,0,1) then it worrks fine (it detects that something is received). Problem is because slave send some empty bytes data which can't be changed.
Thanks

(BASCOM-AVR version : 2.0.8.1 )

_________________
A clever person solves a problem. A wise person avoids it. Albert Einstein
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Mon Jan 14, 2019 4:18 pm    Post subject: Reply with quote

Hi,

Maybe a Do Loop while ISCHARWAITING. Something like:-

Code:
 
   While Ischarwaiting(#2) = 1                           'loop through data
      Rfid_char = Inkey(#2)                              'Get 1 byte
      If Rfid_char = 2 Then                              'Chr 2 - Start of MSG
        Rfid_ptr = 0                                    'Reset pointer
      Else
        Incr Rfid_ptr                                   'Move to next byte
        Rfid_array_local(rfid_ptr) = Rfid_char          'Save char to array
      End If
      If Rfid_ptr >= 12 Then                             ' correct length
        Rfid_have_buffer = 1                            'tell user space
        Rfid_ptr = 0                                    'Reset buffer pointer
        Exit While                                      'Move on
      End If
    Wend
 


In this example CHR(2) is the start of a message the message is always 12 bytes long and the data lands in a Byte array (Rfid_array_local). Note I'm using buffered serial i/o so this routine doesn't need to be called that often.


Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Jan 14, 2019 5:31 pm    Post subject: Re: Receiving zero(0) bytes Reply with quote

Flash wrote:
because Ischarwaiting=0 if all bytes are zero(0)

Your statement is wrong.

Ischarwaiting() returns an 1 for a byte received, doesn't matter of the byte's value.
Your code - which you do not show - is flawed.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Mon Jan 14, 2019 6:22 pm    Post subject: Reply with quote

see the help about null character
I suppose you know but ...
null ascii 0 is different of "0" chr ( 48 )

Help said
"you can send and receive both with While the Inkey() will get the character from the HW UART when there is a character in the buffer, it will return a zero when the character is zero. This makes it unusable to work with binary data that might contain the value 0."

Ischarwaiting()

"While the Inkey() will get the character from the HW UART when there is a character in the buffer, it will return a zero when the character is zero. This makes it unusable to work with binary data that might contain the value 0.
With IsCharWaiting() you can first check for the presence of a character and when the function returns 1, you can retrieve the character with Inkey or Waitkey."

so ischarwaiting return 1 when you send it a null but inkey see nothing.

so please send us a your code
JP
Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Flash

Bascom Member



Joined: 03 Feb 2006
Posts: 153
Location: EU

blank.gif
PostPosted: Mon Jan 14, 2019 7:29 pm    Post subject: Re: Receiving zero(0) bytes Reply with quote

MWS wrote:
Flash wrote:
because Ischarwaiting=0 if all bytes are zero(0)

Your statement is wrong.

Ischarwaiting() returns an 1 for a byte received, doesn't matter of the byte's value.
Your code - which you do not show - is flawed.


This is not a code, I know that Ischarwaiting() returns an 1, here is question why it don't return 1 when I received e.g. three bytes in a row and all of this three have value 0x00, shouldn't Ischarwaiting() recognize this bytes with value=0?
This is the simple code (AT90CAN):
Code:
 
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0    
Open "COM2:" For Binary As #2
Config Serialin1 = Buffered , Size = 100

'Slave send some bytes (3 or more) with 0x00 values (I can see them on logic analyzer) on COM2 UART - Ischarwaiting(#2) = 0

 If Ischarwaiting(#2) = 1 Then                           'loop through data
 'do something
 Else
 'do something
 End if
 

When is one of the received byte with value >0 (e.g. 0x01) then is all ok -Ischarwaiting(#2) = 1. I don't need to use inkey, waitkey, inputbin etc. only confirmation of receipt.

_________________
A clever person solves a problem. A wise person avoids it. Albert Einstein
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Jan 14, 2019 8:22 pm    Post subject: Re: Receiving zero(0) bytes Reply with quote

Flash wrote:
This is not a code,

Yes, you're right, these are only unrelated lines, but no code which would allow to tackle the issue.
Quote:
I don't need to use inkey, waitkey, inputbin etc. only confirmation of receipt.

Without use of any of these, or similar commands the input buffer won't be emptied and no incoming data is read..
Makes no sense.
If you expect help, post a compilable example which shows the problem.
Back to top
View user's profile
Flash

Bascom Member



Joined: 03 Feb 2006
Posts: 153
Location: EU

blank.gif
PostPosted: Tue Jan 15, 2019 10:11 am    Post subject: Reply with quote

Adding some time for UART to setup after Print command solved problem.
Code:
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0    
Open "COM2:" For Binary As #2
Config Serialin1 = Buffered , Size = 100

Printbin #2, command_byte 'for slave

'Slave send some bytes (3 or more) with 0x00 values (I can see them on logic analyzer) on COM2 UART - Ischarwaiting(#2) = 0

Waitus 200 'UART need some time for setup

 If Ischarwaiting(#2) = 1 Then                           'loop through data
 'do something
 Else
 'do something
 End if


Tnx all

_________________
A clever person solves a problem. A wise person avoids it. Albert Einstein
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