Skip to main content
BSang
Associate II
August 27, 2019
Solved

Read and write Bluetooth communication byte format

  • August 27, 2019
  • 2 replies
  • 1779 views

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...

This topic has been closed for replies.
Best answer by BSang

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

Sorry....

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

2 replies

JoniS
Senior
August 27, 2019

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
BSangAuthorBest answer
Associate II
August 27, 2019

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

Sorry....

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

Tesla DeLorean
Guru
August 28, 2019
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..