is inverted SUART non-blocking?

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
JWinters
Posts: 106
Joined: Mon Feb 04, 2008 4:56 pm
Location: North Carolina, USA
Contact:

is inverted SUART non-blocking?

Post by JWinters » Sat Jun 07, 2008 4:08 pm

If I use the SUART module in True mode, it works as a blocking function. However, if I use it in Inverted mode, it doesn't operate as a blocking call and my code sails right though the UART.Readbyte without actually catching any real data (well it reports byte 255).

I think I now understand why someone once called this module 'useless'. If they were trying to receive data in Inverted mode, there is no way to actually catch it.

Here's me code.

Code: Select all

Program SUART_TEST

Device = 18F4610
Clock = 40
Config OSC = HSPLL
Include "SUART.bas"

Dim ByteIn As Byte

UART.SetBaudrate(sbr9600)
UART.SetMode(umInverted)
UART.Pacing = 1000
UART.SetTX(PORTB.0)
UART.SetRX(PORTB.4)

Here:

    UART.Write("listening...",13,10)
    ByteIn = UART.ReadByte()
    UART.Write("Received '",ByteIn,"'",13,10)
    DelayMS(1000)

GoTo Here
Last edited by JWinters on Sun Jun 08, 2008 2:33 pm, edited 1 time in total.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sun Jun 08, 2008 11:27 am

There's a typo in the SUART 'ReadByte()' routine. You need to change two lines of code. The original is this...

Code: Select all

Public Function Access ReadByte() As Byte
   Dim Index, Pin, Mode As Byte
   
   // get port, pin and mode...
   Pin = FRX.Pin
   FSR0 = FRX.AddrPort
   Mode = FMode
   Index = 8  
ASM-
   ; look For start Bit...
   movf    INDF0, W         ; <Read Bit>
   btfsc   Mode, 1                 
   comf    W                           
   andwf   Pin, W                      
   btfss   STATUS, Z               
   bra     $ - 10                     
End ASM
   HalfBT                   
ASM-
   movf    INDF0, W         ; <Read Bit>
   btfsc   Mode, 1          
   comf    W                
   andwf   Pin, W           
   btfss   STATUS, Z        
   bra     $ - 24 

you need to edit like this...

Code: Select all

ASM-
   ; look For start Bit...
   movf    INDF0, W         ; <Read Bit>
   btfsc   Mode, 1                 
   comf    WREG             ; <- *** changed from "W" ***
   andwf   Pin, W                      
   btfss   STATUS, Z               
   bra     $ - 10                     
End ASM
   HalfBT                   
ASM-
   movf    INDF0, W         ; <Read Bit>
   btfsc   Mode, 1          
   comf    WREG             ; <- *** changed from "W" ***
   andwf   Pin, W           
   btfss   STATUS, Z        
   bra     $ - 24 
Here is some test code which I simulated in ISIS, all now works as expected...

Code: Select all

Device = 18F452
Include "SUART.bas"

Dim ByteIn As Byte

UART.SetBaudrate(sbr9600)
UART.SetMode(umInverted)
UART.SetTX(PORTC.6)
UART.SetRX(PORTC.7)

While true
    UART.Write("listening...",13,10)
    ByteIn = UART.ReadByte()
    UART.Write("Received '",ByteIn,"'",13,10)
Wend

Post Reply