Android Question Serial too fast

freetoair

Member
Licensed User
Longtime 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
 

JordiCP

Expert
Licensed User
Longtime 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.
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime 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...
 
Upvote 0
Top