cancel
Showing results for 
Search instead for 
Did you mean: 

Read and write Bluetooth communication byte format

BSang
Associate III

Hi Community,

I'm studying about the android program and stm32f407vet based controller.

The question I asked before is almost clear by using DMA USART.

I'm Transmit and Receive like under code.

code(IN STM32)

uint8_t rxBuffer;

int SIZE_OF_RX_TX = 1;

if (huart->Instance == USART3)

{

HAL_UART_Transmit_DMA(&huart1, rxBuffer, SIZE_OF_RX_TX);

HAL_UART_Transmit_DMA(&huart3, rxBuffer, SIZE_OF_RX_TX);

HAL_UART_Receive_DMA(&huart1, rxBuffer, SIZE_OF_RX_TX);

HAL_UART_Receive_DMA(&huart3, rxBuffer, SIZE_OF_RX_TX);

}

it means that receive USART3(BLUETOOTH) and TRANSMIT USART1 and USART3

and make a interuupt USART1 and USART3.

but in Android bluetooth only send byte array

code(in ANDROID)

void sendData(String text)

{

outputStream.write(text.getBytes("UTF-8"));

}

when I debug android program, and when I send text "1",

byte result is '49'

but when I send it to bluetooth usart3, the value sometimes broken.

and wrong value is occured.

Q.

is there a way to convert byte data USART?

How can I? I really don't know... help...

1 ACCEPTED SOLUTION

Accepted Solutions
BSang
Associate III

Oh Thanks,, I found why data is wrong....

Sorry....

I set a baud rate between bluetooth and microcontroller incorrectly...

View solution in original post

3 REPLIES 3
JoniS
Senior

Do you mean that when you send "1", your microcontroller sometimes receives wrong value?(something else than 49) or does this happen with other values only, like byte values higher than 127 when you don't receive what you send?​

Edit: you don't need to convert "byte" values, it's 8bit value which does fit into a char or uint8_t which ever you use, however Java does not know what is "unsigned" and behaves differently for values between 128-255 than C.

BSang
Associate III

Oh Thanks,, I found why data is wrong....

Sorry....

I set a baud rate between bluetooth and microcontroller incorrectly...

Related continuation https://community.st.com/s/question/0D50X0000BFypGBSQZ/hal-usart-dma-buffer-reset-method

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..