2018-08-19 09:54 PM
I have to receive a string in stm32f030 from USART using LL library through the interrupt.
2018-08-20 12:31 AM
do you have demo board ?
search for serial port example for that board.
did you use the Cube ?
2018-08-20 03:04 AM
I have a evaluation Kit but i need to know how to receive a string from USART since i am able to receive byte data at a time.
2018-08-20 03:39 AM
can you show me your code where you receive a byte ?
then I will be able to show you how to save a string.
2018-08-20 04:02 AM
void receive_usart1()
{
if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
rx_data_2=LL_USART_ReceiveData8(USART1);
}
// In interrupt
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
receive_usart1();
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
}
2018-08-20 04:53 AM
just declare a buffer globally U1RxBuffer[256]; and a pointer U1RxBufferPtrIN
simply
void receive_usart1()
{
if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
Usart1RxDMABuffer[U1RxBufferPtrIN++] = LL_USART_ReceiveData8(USART1);;
if (U1RxBufferPtrIN >= U1RxBufSize) U1RxBufferPtrIN = 0;
}
that will get it into a buffer..
or else use DMAs
#define U1RxBufSize 256
#define U1TxBufSize 2048
char Usart1TxDMABuffer[U1TxBufSize];
char Usart1RxDMABuffer[U1RxBufSize];
int16_t U1RxBufferPtrIN, U1RxBufferPtrOUT, U1TxBufferPtrIN, U1TxBufferPtrOUT;
char TxDMA1BufHasData, DMA1BufAlmostFull;
in the cube, if you enable the DMA in circular mode, it will fill the Usart1RxDMABuffer directly.
I run this once at startup:
void initUart1RxDMABuffer(void) { // stream directly into RxBuffer
if (HAL_UART_Receive_DMA(&huart2, (uint8_t *)Usart1RxDMABuffer, U1RxBufSize) != HAL_OK)
{
// Transfer error in reception process
//_Error_Handler(__FILE__, __LINE__);
printf("initUart1RxDMABuffer Failed\n");
}
else
printf("initUart1RxDMABuffer OK!\n");
}
that will get it into the same buffer, but under DMA control,
that way, you wont lose any data if you are tardy...
2018-08-20 05:22 AM
I am a bit confused since what are you telling is relating with the DMA control and i only doing in transmit and reception mode.
I need to transmit a string and what the received string is i need to cut and modify it and than again transmit it.
The received string is of length approximately 100.
And please tell me the flow to write "void initUart1RxDMABuffer(void) " this function if necessary.
2018-08-20 05:25 AM
initialise the RxDma stuff before while(1)
2018-08-20 05:26 AM
did you initialise the DMA circular buffer in the cube ?
2018-08-20 05:38 AM
void receive_usart1()
{
if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
uint8_t rxdata =LL_USART_ReceiveData8(USART1);
...
}
So what's to stop you putting the data into a buffer, or processing it with a state machine?
If the data has some type of form. ie GPS NMEA sentences, you can watch for a start character to resynchronize the buffer, and a <CR><LF> pair to terminate the buffer and hand the string off to a processing routine.