Android Question How to send the word 16 bits (hex: FFFF) from Android to AVR?

Picon

Member
Licensed User
Hello all Masters of B4A
How to send the word 16 bits (hex: FFFF) from Android to AVR?
I use this:
B4A
HC-05
AVR ATmega328P (no Arduino, no raspberry)

Code B4A info:
in BTmanager:
B4X:
Sub Class_Globals
Private AStream As AsyncStreams
End Sub

-----
Public Sub SendMessage (msg As String)
AStream.Write(msg.GetBytes("utf8"))
End Sub
For Example:

When I want to send A0F5 (bin: 1010000011110101)
in AVR (UDR0) I have only ASCII code representation: 49
This is a representation only of the last bit of the whole:
1010 0000 1111 0101.
A, 0, F ang 3bits (010) of 5 are lost.
Do any of you know why this is happening?

Code AVR info:
B4X:
static uint8_t ReadByte(void)
{
while ( !( UCSR0A & (1<<RXC0) ) ); // waiting loop for data in the register UDR0
return UDR0;
}
 
Last edited:

Picon

Member
Licensed User
Erel, thank you for the tip.
My problem is that i don't use Arduino.
I have specially designed my own SCH & PCB with ATmega on board with the BT module connected and Arduino is not useful in my case.
For ATmega software I use AVR Studio.
 
Upvote 0

Picon

Member
Licensed User
Yes,
I have in B4A:
B4X:
Dim a As Byte
Dim b As Byte
a= 0xAB
b= 0x56
Public Sub SendArray (a As Byte, b As Byte)
    AStream.Write(Array As Byte(a, b)) 
End Sub

in "C" code for AVR I have:
B4X:
uint8_t low  = ReadByte();                           
uint8_t high = ReadByte();                           
uint16_t Data_A = ( uint16_t )low + ( high <<8 );

then I write (from Boot Loader Flash Section section) the variable "Data_A" to Flash memory (adrr: 0x2A0) and after reading the content I have this result:

16bits.jpg

To change the order (AB56 or 56AB) you need to swap the order "a" and "b" in the sending function, or swap the "low" and "high" order in the receiving function in the AVR code.
 
Upvote 0
Top