cancel
Showing results for 
Search instead for 
Did you mean: 

Using 2 UART on STM32?

antonius
Senior

Dear Members,

I want to read a result from my GPS,

it's Neo 6M

I initialized 2 UARTs UART 1 for PC and UART 2 for GPS,

I got this result :

INIT CODE GPS NEO - 6M....

                           

From GPS : 0690X0000087jMhQAI.png

Is it receiving properly ?

The code :

 char in[8];

printf("From GPS : ");

  HAL_UART_Receive(&huart2, (uint8_t *)in, 8, 1000);

HAL_UART_Transmit(&huart1, (uint8_t *)in, 8, 1);

printf("\r\n");

Green LED on GPS module is blinking...

Thanks

35 REPLIES 35

I have some confuse regarding such type of function

"void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart"

like this also

"HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)"

they are only use before main or any where in main because i am using ADC my program goes in function where is ADC value is used but its' not show me ADC value on my screen so i want to 0 use "HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)" function. it will help or not

is void USART_GPS_IRQHandler(void) // Sync and Queue NMEA Sentences

equal to

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) ?

so I will move the content of that function to this function ?

I don't understand the code ?? how can I connect it with my STM32L152RE ?

antonius
Senior

Here's my STM32CubeMX file, has IRQ for USART2 been enabled ?

I recheck it, it is, but may be something else missing ?

anyone ?

antonius
Senior

the code :

/* USER CODE BEGIN 0 */
void startRx()
{
  // pretty inefficient but will probably be ok for 9600
  uint32_t offset = (rxChars & 0x1f); // so count is actual receive count but offset is buffer index
  HAL_UART_Receive_IT(MYUART, rxBuffer+offset, 1);
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
{
 if (huart==MYUART)
 {
 rxChars += 1; // char is already in our buffer, inc count and bail out quickly since this is a callback
 }
}
 
 
				
/* USER CODE END 0 */
 
in main :
	printf("From GPS : ");
		  if (lastRxChars != rxChars)
    {
			printf("now I have %lu chars\n", rxChars);
			lastRxChars = rxChars;
			startRx();
    }
 
it never gets inside if ....??

without

 if (lastRxChars != rxChars)

I got :

   INIT CODE GPS NEO - 6M....

From GPS : now I have 0 chars

INIT CODE GPS NEO - 6M....

It is the USART2_IRQHandler() or whatever the #define says it is.

The HAL Callback methods are far too circuitous and not really compatible with the byte-at-a-time interrupts coming from the USART. NMEA data rarely falls on convenient 10 or 100 byte boundaries.

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

Ok, so we're about 25 questions into the thread before the specific STM32 part is identified.

What board is this on? A standard NUCLEO board, or something else?

It would take some effort on my part to port this to the L1 platform.

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

STM32L152LE

It's Nucleo board without a programmer on it, so I use ST-link for it,

Please find STM32CubeMX file below, is it right ?

Thanks

STM32L152 doesn't have ICR register ...??

can I disable it ?