Hello all,
I'm trying to use the bluetooth to send and receive data by the UART of dsPic30F. I used the code of this tutorial http://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/
On micro side I use a dsPic30F and a MIKROELEKTRONIKA Basic compiler. The code on dsPic is very easy:
Basically the micro send back what it receive on the UART
The app side I used this code to send the char "f":
On the editText (et_log) everything works properly and every time I push the btw_send I can see :
Phone: f
ECU: f
The second step is send back something different. the variable "receive" is a byte, it represent the ASCII value of char "f". If I add 1 the char sent back should be "g". If I try to change the code of dsPic with :
it doesn't work anymore. I aspect to receive "g" instead of "f" but for some reason the app doesn't receive nothing. Any idea
Thanks
I'm trying to use the bluetooth to send and receive data by the UART of dsPic30F. I used the code of this tutorial http://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/
On micro side I use a dsPic30F and a MIKROELEKTRONIKA Basic compiler. The code on dsPic is very easy:
B4X:
inizio:
delay_ms(1)
if (UART1_Data_Ready() = 1) then
receive = UART1_Read()
UART1_Write(receive)
end if
goto inizio
Basically the micro send back what it receive on the UART
The app side I used this code to send the char "f":
B4X:
Sub AStream_NewData (Buffer() As Byte)
LogMessage("ECU", BytesToString(Buffer, 0, Buffer.Length, "ASCII"))
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken", True)
btn_send.Enabled = False
End Sub
Sub AStream_Terminated
AStream_Error
End Sub
Sub btn_send_Click
pb_avanzamento.Progress=0
AStream.Write("f".GetBytes("ASCII"))
LogMessage("Phone", "f")
pb_avanzamento.Progress=100
End Sub
Sub LogMessage(From As String, Msg As String)
et_log.Text = et_log.Text & From & ": " & Msg & CRLF
et_log.SelectionStart = et_log.Text.Length
End Sub
On the editText (et_log) everything works properly and every time I push the btw_send I can see :
Phone: f
ECU: f
The second step is send back something different. the variable "receive" is a byte, it represent the ASCII value of char "f". If I add 1 the char sent back should be "g". If I try to change the code of dsPic with :
B4X:
inizio:
delay_ms(1)
if (UART1_Data_Ready() = 1) then
receive = UART1_Read()
receive = receive + 1
UART1_Write(receive)
end if
goto inizio
it doesn't work anymore. I aspect to receive "g" instead of "f" but for some reason the app doesn't receive nothing. Any idea
Thanks