View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
|
Back to top |
|
|
Jerry
Joined: 25 May 2004 Posts: 40 Location: New York
|
Posted: Sun Jul 18, 2004 12:57 pm Post subject: |
|
|
That's interesting. I believe I have used a software UART with the Inkey(). Did you try dimensioning the variable as a byte and using Chr(bytevariable) as shown in the Bascom Help example under OPEN? I am not able to test at the moment. Remember that a String is always terminated with a zero, which is not printable text. |
|
Back to top |
|
|
Jerry
Joined: 25 May 2004 Posts: 40 Location: New York
|
Posted: Sun Jul 18, 2004 1:02 pm Post subject: |
|
|
Also there is no buffering when using a software port so you should be looking at the input using a do loop.
Dim Serialdata as String * 2
Open "COMA.5:9600,8,N,1" For Input As #2
Do
Serialdata = InKey(#2)
Loop until Serialdata <> "" |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Jul 19, 2004 12:03 am Post subject: |
|
|
As the SW UART has no buffer, INKEY() will check if there is a startbit.
But when you checked, and there is none, short after this, the startbit/byte could come !
I used SW UART in combination with an interrupt (INT0 or INT1) to react on the start bit, and then with WAITKEY, i received the byte.
INKEY() for the SW UART is only usable when you use it in a loop, or when you use it in combination with an interrupt. _________________ Mark |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Mon Jul 19, 2004 12:14 am Post subject: |
|
|
Thanks for the suggestions, guys. For what it's worth, I did try using a Do Loop when looking for the Inkey(#2) data but it didn't work correctly either. Here's a code snippet that I've tried (I cannot use any of the INTs because I am dealing with existing hardware):
Code: |
Open "COMA.6:9600,8,N,1" For Output As #1
Open "COMA.5:9600,8,N,1" For Input As #2
Print #1, "VM 0" ; Chr(13) ; 'select VFO
Do
SerialIn = Inkey(#2) 'look for reply from radio
Incr ErrorCounter
If ErrorCounter > 20000 Then 'if no ACK or NACK
Call RadioError
ErrorCounter = 0
Exit Sub
End If
Loop Until SerialIn = "V" 'ACK from radio
ErrorCounter = 0 'reset counter
'
Print #1, " ; Chr(13) ;
Do
SerialIn = Inkey(#2)
Incr ErrorCounter
If ErrorCounter > 20000 Then
Call RadioError
ErrorCounter = 0
Exit Sub
End If
Loop Until SerialIn = "V"
ErrorCounter = 0
|
The first Inkey loop always works but the 2nd *never* does (I've tried Serialin as both a string * 1 and a byte and it makes no difference).
Moving everything over to a HW UART works fine but I was trying to avoid tieng it up, as my design currently uses USART0 for RS232 to a computer and USART1's pins are used for other things.
[/code] |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jul 24, 2004 2:51 pm Post subject: |
|
|
As the is not buffer and inkey() only checks the startbit, when your other code runs and the startbits is gone, it will not detect the byte.
so use waitkey(), or use inkey() in combination with an interrupts so you can act quick on the startbit. _________________ Mark |
|
Back to top |
|
|
|