cancel
Showing results for 
Search instead for 
Did you mean: 

UART-1 working code reads NULL

DRAME.1
Associate II

Hi clive 

I have interfaced UART DATA device(sender) and NUCLEOF401RE(receiver) 

I have set the proper BAUD RATE 115200

I am using UART-1 to receive data

I generated the code in the IDE and first tested for transmit functionality and it works fine

I took RX TX and GND from F401RE and connect to USB to TTY converter and was able to send the data to the terminal

I was confident that transmit is working fine from the generated code 

NUCLEOF401RE TX(PA9)D8 GND RX(PA10)D6 ---------TRANSMIT---------> UART TO TTY TX RX GND worked fine 

This above experiment was done to make sure generated codes are proper

Now My goal is to receive the data from my Data Device UART to F401RE

I connected the TX RX PINS OF DATA DEVICE ------------> NUCLEOF401RE TX(PA9)D8 GND RX(PA10)D6

Following is the code written

I see that the voltage level in the multimeter of UART signal from data device its around 3.6 V

I think the voltage level should not be an issue as i was able to receive the data on arduino as well using serial read api

That makes me think pin voltage level in arduino and arduino shield voltage level are fine Attached the screen shot 

I am not able to receive the data and its empty 

I have configured the baud rate 115200 

I am not sure what is the exact function to receive the data and test this

I have the follwoing code 
 
 
 
 /* Configure the system clock */
 
 SystemClock_Config();
 
 
 
 /* USER CODE BEGIN SysInit */
 
 
 
 /* USER CODE END SysInit */
 
 
 
 char deepak[10]="testing";
 
 uint8_t receive_testing[10]={0};
 
 /* Initialize all configured peripherals */
 
	MX_GPIO_Init();
 
	//MX_USART2_UART_Init();
 
		MX_USART1_UART_Init();
 
 /* USER CODE BEGIN 2 */
 
 
 
 // HAL_UART_Transmit(&huart1,"Deepakprint",10,100);
 
 // HAL_UART_Transmit(&huart1,deepak,10,100);
 
 // HAL_UART_Transmit(&huart1,"ABHIJITH",10,100);
 
 
 
 int r=0;
 
 
 
 for(r=0;r<100;r++)
 
 {
 
	 //HAL_UART_Transmit_IT(&huart1,"deepak",10);
 
	 HAL_UART_Receive_IT(&huart1,receive_testing,10);
//There are no values in the receive_testing function I did inline debugging as well the *pdata has no value 
 
 }

The values in receive_testing is NULL only

Can you please help I am sure something is wrong in my program only 

2 REPLIES 2
TDK
Guru

How do you know data is actually being sent? Can you see it on a scope/logic analyzer?

You shouldn't call HAL_UART_Receive_IT repeatedly. You should only call it when setting up a new receive transmission. Try it in blocking mode first to get it working.

Logic level of 3.6V is probably not a problem. It's possible the TTL device has a pullup to 5V which is then limited by the STM32 protection diodes.

If you feel a post has answered your question, please click "Accept as Solution".

How do you know data is actually being sent? Can you see it on a scope/logic analyzer?

I made the same connections to Arduino Board and wrote a program to receive the code using serial read

I was able to read the data succesfully

My data is something like this thats keep logging and i need to receive

Battery voltage 7836 v

Battery Charge 86 %

Battery Current -9 mA

Battery voltage 7836 v

Battery Charge 86 %

Battery Current -5 mA

Battery voltage 7838 v

Battery Charge 86 %

so my assumption is the same voltage levels would be fine and data is present

Now I wrote a code that receives the data on STM32H7B3I-DK

I see that The call back function is being called everytime I am able to get it till here But i see that my Buffer is empty

My data comes continously as per above format

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {

///The call back comes everytime but data in receive is unchanged

HAL_UART_Receive_IT(&huart1,&receive_testing_1,1);

}

Can you please provide sometips please

Attached my

  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
 
osThreadId defaultTaskHandle;
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_USART1_UART_Init(void);
void StartDefaultTask(void const * argument);
 
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
uint8_t receive_testing_1;
uint8_t receive_testing[100];
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
///The call gets invoked everytime But receive_testing_1does not have my data
	 HAL_UART_Receive_IT(&huart1,&receive_testing_1,1);
}
char wifiRxChar[100]={0};
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
 
//  HAL_UART_Receive_IT(&huart1,rx_data,4);
/Transmit works fine 
  int r=0;
  int ch;
 
	 HAL_UART_Receive_IT(&huart1,&receive_testing,10);
//after running this receive_testing is still 0
 
 
  /* USER CODE END 2 */
 
  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */
 
  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */
 
  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */
 
  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */
 
  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
 
  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */
 
  /* Start scheduler */
  osKernelStart();
 
  /* We should never get here as control is now taken by the scheduler */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Thank you

Deepak R