Android Question Serial too fast

Discussion in 'Android Questions' started by freetoair, Sep 3, 2015.

Similar threads

B4A Code Snippet [B4X] Bytes To File
B4A Code Snippet [B4X] Change the background alpha level
B4A Code Snippet [B4X] Convert bitmap to BMP format
B4A Tutorial GUI AVD Manager / Emulator
B4A Code Snippet Binary2String
  1. freetoair

    freetoair Member Licensed User

    Serial port on Android has a very short stop start time between two bytes . I have a problem that the microcontroller does not have time to recognize the stop bit of the byte just received from the start bit of the next. Is there any way to extend this time?


    Sub konverzija (Value As Int)

    outpkt(2)=0
    outpkt(1)=0
    outpkt(0)=0

    Do Until (Value < 100)
    Value = Value - 100
    outpkt(2) = outpkt(2)+1
    Loop
    outpkt(2) =Bit.ShiftLeft(outpkt(2),4)
    outpkt(2) = Bit. Or(outpkt(2),komanda)

    sout.WriteBytes(outpkt,2,1)
    sout.Flush

    Do Until (Value < 10)
    Value = Value - 10
    outpkt(1) = outpkt(1)+1
    Loop
    outpkt(1) =Bit.ShiftLeft(outpkt(1),4)

    outpkt(0) = Value
    outpkt(0) = Bit. Or(outpkt(1),outpkt(0))

    sout.WriteBytes(outpkt,0,1)
    sout.Flush
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    You can use a timer to add a delay.
     
    JordiCP likes this.
  3. JordiCP

    JordiCP Well-Known Member Licensed User

    I have never worked with Android serial port. But you could try to change the settings from 8N1 (or whatever you have now) to 8N2

    This way, the stop bit period will be doubled.
     
  4. DavideV

    DavideV Active Member Licensed User

    As Erel said, send a byte at a time using a timer .
    But if your microcontroller has an hardware serial port (not simulated) then consider to use that port/pins.
    also use interrupts on hardware serial port to save received bytes to a buffer . By this way you should be able to send more bytes at a time...
     
    KitCarlson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice