cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to establish UART communication between Arduino nano and STEVAL-ESC002V1

shashank7
Associate II

Hey,
While doing UART communication between Arduino nano and STEVAL-ESC002V1  
When i start my UART communication the control goes to function,

void USART1_IRQHandler(void)
{
#ifdef UART_COMM
uint32_t isrflags = READ_REG(huart.Instance->ISR);
uint32_t cr1its = READ_REG(huart.Instance->CR1);
/* -----------UART in mode Receiver ---------------------------------------------------*/
if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
   if ((huart.gState!=HAL_UART_STATE_TIMEOUT)&&(huart.gState!=HAL_UART_STATE_ERROR))
    {
       huart.gState = HAL_UART_STATE_READY;
       huart.RxState &= ~HAL_UART_STATE_READY;
       huart.RxState |= HAL_UART_STATE_BUSY_RX;
      if (UART_Receive_IT(&huart)==HAL_OK)
       {
         UART_Set_Value();
       }
}
/* Clear RXNE interrupt flag */
__HAL_UART_SEND_REQ(&huart, UART_RXDATA_FLUSH_REQUEST);
}
/*------- UART in mode Transmitter (transmission end) -----------------------------*/
if(((isrflags & USART_ISR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
UART_EndTransmit_IT(&huart);
return;
}
#endif
}



The control goes to "UART in mode Transmitter", but i think the control should go to "Uart in mode  Receiver", the first if statement in which the ISR & SART_ISR_RXNE is not getting true. 
Please guide what should i do, 
Please guide me with the solutions so that i can eliminate my problem, and move for further development.
Below down i'm also attaching the reference Arduino nano code

 
#include <SoftwareSerial.h>
SoftwareSerial STM(12,11); //Rx,Tx
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  STM.begin(9600);
  // Serial.print("Arduino code step-up....");
}

void loop()
{
  // put your main code here, to run repeatedly:
  STM.print("SETSPD,");
  STM.print(2000);

}

Edited to apply source code formatting - please see How to insert source code for future reference.

3 REPLIES 3
STuser2
Senior II

Is it possible that you test the UART communication independently using another serial monitor device if uart interrupt is triggered or not ?


@STuser2 wrote:

test the UART communication independently using another serial monitor device  ?


^^^ Absolutely this!  ^^^

 

@shashank7 You are making the classic mistake of trying to do both ends of the link at once.

This give you too many unknowns:

  • Is the problem in your SMT32 ?
  • Is the problem in your Arduino ?
  • Is the problem in the connection between the two ?
  • Is it some combination of any or all of the above ?

So, as always, break the problem down into simpler steps.

  1. Test your STM32 on its own against a PC terminal.
    Test thoroughly that it can correctly send & receive, and handle errors.
  2. Test your Arduino on its own against a PC terminal.
    Test thoroughly that it can correctly send & receive, and handle errors.
  3. Now you have confidence that both the STM32 and Arduino parts work correctly - so now is the time to bring them together.

 

Also, before getting into the interrupt-driven comms, make sure that basic blocking comms works (HAL_UART_Transmit).

 

See also: Debugging Serial Comms.

 

#BothEnds #BothEndsUART

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User

@shashank7 wrote:

 

void USART1_IRQHandler(void)
{
#ifdef UART_COMM
uint32_t isrflags = READ_REG(huart.Instance->ISR);
uint32_t cr1its = READ_REG(huart.Instance->CR1);
/* -----------UART in mode Receiver ---------------------------------------------------*/
if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{

What is the point of testing USART_CR1_RXNEIE within the interrupt handler ?

  • If it's not set, the interrupt can never occur;
  • If the interrupt has occurred, it must be set!
A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.