Good evening everyone!

I got this Bluetooth module HC-05 in my hands. I picked it up to stm32vldiscovery by uart (used the 1st uart). The reciprocal part is written under Android on this manual . There was a problem trying to transfer the elementary sequence “okay”. I tried to convey this:

void USART_PutSequence(uint8_t *sequence) { while(*sequence != 0) { USART_SendData(USART1, (uint8_t)*sequence); sequence++; } } 

So:

 void USART_PutSequence(uint8_t *sequence) { USART_SendData(USART1, (uint8_t)sequence[0]); USART_SendData(USART1, (uint8_t)sequence[1]); USART_SendData(USART1, (uint8_t)sequence[2]); USART_SendData(USART1, (uint8_t)sequence[3]); } 

In any case, only “y” comes in, that is, the last byte. Can anyone come across such a problem? Something I don’t really want to transfer arrays byte-by-byte, while synchronizing with delays.

  • And what does the logger show - the whole sequence or only the last? - Barmaley
  • Only the last. There is an assumption that the interrupt module from the UART reads only one byte from there and tries to transmit it. At this time, another interruption arrives and so on until the end of the sequence. But it’s more like a nonsense - the UART should be read before the buffer is empty ... - RomanoO
  • By the way, that's what. [here] [1] write that the connection needs to be transferred to the COM-port mode (correctly put it?). How can this be interpreted to android? 1: robocraft.ru/blog/electronics/587.html - RomanoO
  • And how much does uint8_t take ??? 8 bytes or 8 bits? - Barmaley
  • A bit, of course - RomanoO

1 answer 1

The solution was found in the polling of the Transmit Completed bit after sending the next byte:

 void USART_PutSequence(uint8_t *sequence) { while(*sequence != 0) { USART_SendData(USART1, (uint8_t)*sequence); while (!(USART1->SR & USART_FLAG_TC)); } } 
  • Better transfer the array through interrupts =) In general, yes, Uart is not fast and you have to wait until the sending is completed. - Alexey Sonkin
  • Yes, I already figured it out. Only here, how to use DMA, I did not understand. It is necessary to analyze every incoming byte - quite expensive it turns out. - RomanoO
  • This is a separate question. Roughly speaking - you tell him how many bytes to copy at what event, from where and where - so he copies. - Alexey Sonkin
  • It's clear. But to launch it, it seems, is necessary manually. So I am doing this by interrupting UARTa, but after that there is no data in the data receiver ... - RomanoO
  • Depends on the task. Read more about DMA. - Alexey Sonkin