Menu

usart receive

Help
risros
2011-02-13
2013-05-30
  • risros

    risros - 2011-02-13

    I'm having troubles receiving with HSerReceive. It doesn't work neither with nor without using interrupt,
    Sending is ok, but there is no receive
    Interrupt is triggered, I noticed that. But no byte received.

    Did any succeed to receive with HSerReceive?

     
  • Hugh Considine

    Hugh Considine - 2011-02-13

    HSerReceive certainly should work, I used it just the other day. There was a version of GCBASIC in late 2009 where HSerReceive didn't work properly, what version do you have?

    If your version of GCBASIC is newer than Jan 2010, there must be something else going wrong - either in your program or inside GCBASIC. Could you please post your code?

     
  • Nobody/Anonymous

    I have a version from 10.2.2010, which is, I suppose, the latest.

    So I am using an intterupt on RX data ready and check if modem returns "OK".
    If it does, the LED should go on for a second.

    ;Chip Settings
    #chip 16F876,4
    #config LVP=OFF, BODEN=OFF, WDT=OFF, OSC=XT
    ;Defines (Constants)
    #define DIODA PORTC.4
    #define switch1 PORTB.1
    #define USART_BAUD_RATE 19200
    #define USART_BLOCKING true
    ;Variables
    Dim char1 As integer
    Dim char2 As integer
    ;Interrupt Handlers
    On Interrupt UsartRX1Ready Call readmodem
    Dir PORTC.6 Out
    Dir PORTC.7 In
    InitUSART
    WAIT 3 s
    dir DIODA OUT
    dir PORTB IN
    set DIODA OFF
    blinkled
    HSerPrint "AT"
    HSerPrintCRLF
    char1=0
    char2 = 0
    loop1:
    If switch1=ON then
        alarm
        wait 10 s
    End If
    Goto loop1
    Sub alarm
        HSerPrint "AT+CMGW=21"
        HSerSend 13
        wait 1 s
        HSerPrint "xxxxxxxxxxxxxxxxxxxxxxxx"
        HSerSend 26
        wait 1 s
    End Sub
    Sub readmodem
        If RCIF On Then
            HSerReceive char1
        End If
        If RCIF On Then
            HSerReceive char2
        End If
    ;if response is "OK":
        if (char1=79) and (char2=75) then
            SET DIODA ON
            wait 1 s
            SET DIODA OFF
        End If
    End Sub
    Sub blinkled
        SET DIODA ON
        wait 50 ms
        SET DIODA OFF
        wait 50 ms
        SET DIODA ON
        wait 50 ms
        SET DIODA OFF
        wait 50 ms
        SET DIODA ON
        wait 50 ms
        SET DIODA OFF
    End Sub
    
     
  • Nobody/Anonymous

    any ideas?

     
  • Nobody/Anonymous

    Try only receiving one character at a time.
    Most PICs have a uart that only holds one character in its FIFO
    so you need to read each character as it comes in.
    The readmodem sub is trying to receive 2 characters at once.
    The code as it is will never get a character for char2.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.