Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SW 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
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 519

blank.gif
PostPosted: Fri Jul 16, 2004 4:40 pm    Post subject: SW UART Reply with quote

Forgive my crossposting but I am tearing my hair out over this Confused

I am not able to make Inkey (Bascom-AVR 1.11.7.4) work on anything other than a hardware UART on a Mega128. It DOES work in the simulator however.

For example:

Code:


Dim SerialData as String * 1

Open "COMA.5:9600,8,N,1" For Input As #2

Serial Data = InKey(#2)

 


The above ALWAYS returns nothing but if I use a hardware UART, it works fine.

Anyone else run across this?


[/code]
Back to top
View user's profile
Jerry

Bascom Member



Joined: 25 May 2004
Posts: 40
Location: New York

usa.gif
PostPosted: Sun Jul 18, 2004 12:57 pm    Post subject: Reply with quote

Rolling Eyes 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
View user's profile
Jerry

Bascom Member



Joined: 25 May 2004
Posts: 40
Location: New York

usa.gif
PostPosted: Sun Jul 18, 2004 1:02 pm    Post subject: Reply with quote

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

Administrator



Joined: 09 Apr 2004
Posts: 5319
Location: Holland

blank.gif
PostPosted: Mon Jul 19, 2004 12:03 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 519

blank.gif
PostPosted: Mon Jul 19, 2004 12:14 am    Post subject: Reply with quote

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

Administrator



Joined: 09 Apr 2004
Posts: 5319
Location: Holland

blank.gif
PostPosted: Sat Jul 24, 2004 2:51 pm    Post subject: Reply with quote

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
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