cancel
Showing results for 
Search instead for 
Did you mean: 

GPS frame using P-nucleo LRWAN1

yjae
Associate II

#define U1RxBufSize 256

#define U1TxBufSize 2048

int16_t U1RxBufferPtrIN, U1RxBufferPtrOUT, U1TxBufferPtrIN, U1TxBufferPtrOUT=0;

char readableU1(void) {

  U1RxBufferPtrIN = U1RxBufSize - __HAL_DMA_GET_COUNTER(huart4.hdmarx); 

  

   

  return U1RxBufferPtrIN - U1RxBufferPtrOUT;

}

 int check_GPSBufferSize(void) {

    int currentBufferLength = readableU1();

    if (currentBufferLength > 0) 

      PRINTF("Have Buffer Length %d \n", currentBufferLength);

    return currentBufferLength ;

  }

int main

{

 Buffer[0] = 'P';

      Buffer[1] = 'I';

      Buffer[2] = 'N';

   int buffLength = check_GPSBufferSize();  

       if (!buffLength)

{

      Buffer[3] = 'G';

}

   else

      Buffer[3] = buffLength & 0xff;

}​

Part of the source. I want to set up uart port and get gps frame in PingPong ex.I want to check that the number of 'currentBufferLength' changes at the terminal. But the numbers keep the same number. Can you help me?

I can provide more source if you want.

5 REPLIES 5

So perhaps use the debugger and inspect the UART4 state and those of the DMA controller and its buffer.

Consider testing the UART4/GPS code outside the context of LoRa first, and then integrate. If DMA mode isn't working, step back and get polling mode working first.

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

 void USART4_Init(void)

{

 static UART_HandleTypeDef huart4;

 GPIO_InitTypeDef GPIO_InitStruct;

 __HAL_RCC_USART4_CLK_ENABLE();

 __HAL_RCC_GPIOC_CLK_ENABLE();

 __HAL_RCC_DMA1_CLK_ENABLE();

  

  

 /* UART TX/RX GPIO pin configuration */

 GPIO_InitStruct.Pin      = GPIO_PIN_10 | GPIO_PIN_11;

 GPIO_InitStruct.Mode     = GPIO_MODE_AF_PP;

 GPIO_InitStruct.Pull     = GPIO_PULLUP;

 GPIO_InitStruct.Speed    = GPIO_SPEED_HIGH;

 GPIO_InitStruct.Alternate = GPIO_AF6_USART4;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 /*## Configure the UART peripheral ######################################*/

 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */

 /* USART4 configured as follow:

     - Word Length = 8 Bits

     - Stop Bit = One Stop bit

     - Parity = No parity

     - BaudRate = 9600 baud

     - Hardware flow control disabled (RTS and CTS signals) */

 huart4.Instance = USART4;

 huart4.Init.BaudRate = 9600;

 huart4.Init.WordLength = UART_WORDLENGTH_8B;

 huart4.Init.StopBits = UART_STOPBITS_1;

 huart4.Init.Parity = UART_PARITY_NONE;

 huart4.Init.Mode = UART_MODE_TX_RX;

 huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart4.Init.OverSampling = UART_OVERSAMPLING_16;

 huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 if(HAL_UART_DeInit(&huart4) != HAL_OK)

 {

   Error_Handler();

 }  

 if (HAL_UART_Init(&huart4) != HAL_OK)

 {

   /* Initialization Error */

   Error_Handler();

 }

The uart4 code was made. the GPS code is not complete. However, I learned that the number of 'currentBufferLength' should change. I think the DMA is not working. Can you tell me what 'polling mode' is?

Ok, that's the initialization code, but I suggested inspecting the UART state, and DMA buffer, you're trying to determine if any data is being received into the buffer, and if any errors are flagging in either the UART or DMA controllers.

>>I think the DMA is not working.

Yet you're not showing me any of the initialization code for that?

Is it flagging some status/error? anything in the buffer?

>>Can you tell me what 'polling mode' is?

It is where your code is inspecting the status of the UART to see if it is reporting reception of any data (RXNE), and then reading that from the data register.

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

Yes. I don't see the Initialization code.Can you show me an example of a Initialization code?​

Where did you take the other DMA code from? Look there for examples. Look through the L0 HAL examples provided in the CubeL0 source trees.

Ok, so lets step back and check you can actually get some data from USART4, because we seem to be going in circles again, and not following advice.

Let's call something like this in the main loop, and see if we can actually accumulate characters in a buffer.

void CheckUSART4(void)
{
  static char rx_buffer[64];   // Local holding buffer
  static int rx_index = 0;
 
  if (USART4->ISR & USART_ISR_ORE) // Overflow
    USART4->ICR = USART_ICR_ORECF;
 
  if (USART4->ISR & USART_ISR_NE) // Noise
    USART4->ICR = USART_ICR_NCF;
 
  if (USART4->ISR & USART_ISR_FE) // Framing
    USART4->ICR = USART_ICR_FECF;
 
  if (USART4->ISR & USART_ISR_RXNE) // Received character?
  {
    char rx = USART4->RDR;
 
    rx_buffer[rx_index++] = rx;
 
    if (rx_index >= sizeof(rx_buffer))
    	rx_index = 0;
  }
}

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