USART Question

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

USART Question

Post by Widgetman » Mon Jan 19, 2009 5:11 pm

Hi,
I am trying to figure out how to use the USART.DataAvailableTimeout
command to read in a undetermined amount of bytes from the USART and store them to my SD card. Can someone show me a example on how to use this as a timeout to know when the data has stopped coming in.

Thanks for the help

What I am trying to get to work:

1 sit idle waiting for charcters to start coming into the USART RX pin
2 Open a File on the SD card and start writing the bytes
3 when the data stops then close the file

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Mon Jan 19, 2009 9:41 pm

This might work for you...I use it for my gps logger:

Code: Select all

Function NMEA_SENTENCE(pHEADER As String) As String * 100
    Dim GPS_CHAR As Char
    Dim GPS_CHARPOS As Byte
    Dim GPS_RXBUFFER_LENGTH As Byte
    GPS_RXBUFFER_LENGTH = 100
    
    
    If WaitForStrTimeout(pHEADER,2500) = True Then
        GPS_CHARPOS = 0
        While True										' Create a loop to receive the serial string
            GPS_CHAR = USART.ReadByte()                 ' Receive a character serially
            RESULT(GPS_CHARPOS) = GPS_CHAR              ' Store Character
            Inc(GPS_CHARPOS)                            ' Increment the index
    
            If GPS_CHAR = #13 Or GPS_CHAR = #10 Then 
                Break				' Exit the loop if the string reaches the end
            EndIf
            
            If GPS_CHAR = "*" Then 
                GPS_RXBUFFER_LENGTH = GPS_CHARPOS + 1   ' Set Test to get 2 more characters
            EndIf
            
            If GPS_CHARPOS > GPS_RXBUFFER_LENGTH Then   ' Terminate reading
                RESULT(GPS_CHARPOS) = NULL
                Break      ' Repeat the loop until the buffer runs out
            EndIf                
        Wend
    Else
        UART.Write("USART TIMEOUT = ",RESULT,13,10)        
    EndIf
    RESULT = pHEADER + RESULT
End Function
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Post by Widgetman » Tue Jan 20, 2009 7:00 pm

Thanks a bunch for the help. You guys are great for newbies like me tryin to learn :)

Post Reply