MaJerle / stm32-usart-uart-dma-rx-tx

STM32 examples for USART using DMA for efficient RX and TX transmission
MIT License
1.3k stars 322 forks source link

help with RX #5

Closed mjphillips1981 closed 4 years ago

mjphillips1981 commented 4 years ago

Hello,

First off thank you for these examples. I am trying to use the usart_rx_idle_line_irq_ringbuff_G0 example. But would like some guidance on checking what is coming in from the terminal. I want to send commands from the terminal and act on them but only act on them once. I have looked in the usart_rx_dma_buffer for my commands and see them, but is this the correct way of doing this? I want to check some buffer to see if the command is there, act on it, and then clear the buffer. Any help would be appreciated.

Thanks, Mike

MaJerle commented 4 years ago

If you see received data in the buffer is already a good step further.

Your processing function today looks like the one below and does 2 things:

https://github.com/MaJerle/STM32_USART_DMA/blob/b291d2184dfdd1530028da4b99887005ed738baf/projects/usart_rx_idle_line_irq_ringbuff_G0/Src/main.c#L161-L168

You need to remove function call to start new data transfer, so that finally it only writes data to buffer.

Later, in the main while loop function, you need to check for any data available in the buffer, something like

int
main(void) {
//...
//...
    while (1) {
        if (ringbuff_get_full(&usart_tx_dma_ringbuff) >0) {
            //Buffer has some data, read it using ringbuff_read function
            //and process accordingly
        }
    }
}

Are you looking for an example how to do packet communication using DMA RX and later TX?

mjphillips1981 commented 4 years ago

thank you.

Basically what I am trying to do is have a pc application running that someone can command my little control board with. But I do want the control board to send messages back to the PC as well.

MaJerle commented 4 years ago

Best is then to have 2 ringbuffers. One used to write rx received data, like now. Second to write tx data and then dma transmits it.

mjphillips1981 commented 4 years ago

i will try that. thank you for the quick response!!

MaJerle commented 4 years ago

A new project has been added to show:

Examples has not been tested on target board but should work anyway.