Skip to main content
Explorer
June 20, 2024
Question

battery management system not communicating via RS485 with STM32

  • June 20, 2024
  • 6 replies
  • 7934 views

Hello,

I have a SEPLOS brand battery management system card, and I want to read temperature and voltage data from this card. Initially, I will use an STM32F407VGT6 board to read data from the SEPLOS battery management system card via RS485. I am sending the commands first to get the data, but although the data is being sent, I cannot perform the reading operation. What do you think could be the reason for this problem?

The PDF I will send below contains an information sheet about how I should read data from the SEPLOS brand battery management system via RS485. Please look at the PDF and my code to see if you can find where I might be making a mistake.

 

WhatsApp Görsel 2024-06-20 saat 21.37.12_9c1a0877.jpg

WhatsApp Görsel 2024-06-20 saat 21.37.12_c44ef19d.jpg

WhatsApp Görsel 2024-06-20 saat 21.37.12_d9796b56.jpg

thank you for answer

    This topic has been closed for replies.

    6 replies

    Graduate II
    June 20, 2024

    Please use the </> icon to paste in code, not attach as bitmaps, thanks.

    I'd perhaps be concerned about how you have it wired to the STM32, the pins, the RS485 driver, and how you gate that as an output.

    Use a scope or logic analyzer to review the signals you generated on the wires, and the responses, if any, from the BMS

     

    sezear07Author
    Explorer
    June 20, 2024
    I checked my connections and there are no issues. I am sending you the code again.
    Technical Moderator
    June 21, 2024

    Hello @sezear07  and welcome to the community.

    Please read the following recommendations on this link on how to post a thread on this community.

    Thank you for your understanding. 

    Graduate II
    June 21, 2024

    How is your main loop()? Can you post the code using <> method? After sending read request do you do the read ?

    sezear07Author
    Explorer
    June 21, 2024

    I am sending it below

    Graduate
    June 21, 2024

    Have you tried using a SEPLOS USB adapter with a terminal program on a PC to determine that the SEPLOS is functioning correctly ?

    sezear07Author
    Explorer
    June 21, 2024

    Yes, SEPLOS has its own programs, and with these programs, I can read temperature and voltage data.

    Graduate
    June 21, 2024

    Good.

    Connect another 485 to USB adapter on the network to a terminal program, run the SEPLOS program, then your configuration and compare to see where the disconnect is. The terminal program won't provide timing, but will show the command and response sequence. The terminal will probably have to be in HEX mode.

    Graduate II
    June 21, 2024

    Can you post your full code?

    sezear07Author
    Explorer
    June 21, 2024
    /* USER CODE BEGIN Header */
    /**
     ******************************************************************************
     * @file : main.c
     * @brief : Main program body
     ******************************************************************************
     * @attention
     *
     * Copyright (c) 2024 STMicroelectronics.
     * All rights reserved.
     *
     * This software is licensed under terms that can be found in the LICENSE file
     * in the root directory of this software component.
     * If no LICENSE file comes with this software, it is provided AS-IS.
     *
     ******************************************************************************
     */
    /* USER CODE END Header */
    /* Includes ------------------------------------------------------------------*/
    #include "main.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;
    DMA_HandleTypeDef hdma_usart1_rx;
    DMA_HandleTypeDef hdma_usart1_tx;
    
    /* USER CODE BEGIN PV */
    
    uint16_t VoltageCells1;
    uint16_t VoltageCells2;
    uint16_t VoltageCells3;
    uint16_t VoltageCells4;
    uint16_t VoltageCells5;
    uint16_t VoltageCells6;
    uint16_t VoltageCells7;
    uint16_t VoltageCells8;
    uint16_t VoltageCells9;
    uint16_t VoltageCells10;
    uint16_t VoltageCells11;
    uint16_t VoltageCells12;
    uint16_t VoltageCells13;
    uint16_t VoltageCells14;
    uint16_t VoltageCells15;
    
    uint16_t TemperatureCells1;
    uint16_t TemperatureCells2;
    uint16_t TemperatureCells3;
    uint16_t TemperatureCells4;
    uint16_t TemperatureCells5;
    uint16_t TemperatureCells6;
    uint16_t TemperatureCells7;
    uint16_t TemperatureCells8;
    
    uint16_t ChargeDıschargeCurrent;
    uint16_t TotalBatteryVoltage;
    uint16_t ResidualCapacity;
    uint16_t CustomNumber;
    uint16_t BatteryCapacity;
    uint16_t SOC;
    uint16_t RatedCapacity;
    uint16_t NumberOfCycle;
    uint16_t SOH;
    uint16_t PortVoltage;
    
    
    
    
    
    
    uint8_t NmbOfCells;
    uint8_t NmbOfTmp;
    uint8_t CmdGROUP;
    uint8_t flag;
    uint8_t a =0;
    
    
    
    uint8_t RxData[4096];
    uint8_t ReceiveData[75];
    
    uint16_t indx = 0;
    int Count = 0;
    uint16_t timer=0;
    /* USER CODE END PV */
    
    /* Private function prototypes -----------------------------------------------*/
    void SystemClock_Config(void);
    static void MX_GPIO_Init(void);
    static void MX_DMA_Init(void);
    static void MX_USART1_UART_Init(void);
    /* USER CODE BEGIN PFP */
    
    /* USER CODE END PFP */
    
    /* Private user code ---------------------------------------------------------*/
    /* USER CODE BEGIN 0 */
    
    void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
    {
    
    	indx = size;
    	count++;
    	timer = 0;
    	HAL_UARTEx_ReceiveToIdle_DMA(&huart1, RxData, sizeof(RxData));
    
    }
    
    void SeplosBms_Write()
    {
    
    
    	uint8_t Tx1Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x34, 0x34, 0x45,
    				0x30, 0x30, 0x32, 0x30, 0x30, 0x46, 0x44, 0x33, 0x35, 0x0D}; // Get #0pack Telecommand Data.
    
    	uint8_t Tx2Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x30, 0x30, 0x31,
    					0x30, 0x34, 0x42, 0x30, 0x30, 0x46, 0x44, 0x33, 0x42, 0x0D}; // Get #0pack CID2 NORMAL Data.
    
    	uint8_t Tx3Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x34, 0x32, 0x45,
    						0x30, 0x30, 0x32, 0x30, 0x30, 0x46, 0x44, 0x33, 0x37, 0x0D}; // Get #0pack telemetry Data.
    
    	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
    	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
    
    	HAL_UART_Transmit(&huart1, Tx1Data, sizeof(Tx1Data), 1000);
    	HAL_Delay(500);
    	HAL_UART_Transmit(&huart1, Tx2Data, sizeof(Tx2Data), 1000);
    	HAL_Delay(500);
    	HAL_UART_Transmit(&huart1, Tx3Data, sizeof(Tx3Data), 1000);
    	HAL_Delay(500);
    
    
    }
    
    void SeplosBms_Read()
    {
    
    	
    
    	for(int i=0; i<=75; i++)
    	{
    
    		if(HAL_UART_Receive(&huart1, RxData, sizeof(RxData), 1000) == HAL_OK) // Bu kısım değişecek //
    		{
    
    			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
    			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
    
    
    		}
    
    
    		ReceiveData[a] = RxData[i];
    
    		uint8_t a =0;
    		uint8_t b =0;
    		flag = (uint8_t)(ReceiveData[a] << (b)); a+=1;
    		CmdGROUP = (uint8_t)(ReceiveData[a] << (b+8)); a+=1; b+=8;
    		NmbOfCells = (uint8_t)(ReceiveData[a] << (b+8)); a+=1; b+=8;
    
    	 VoltageCells1 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells2 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells3 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells4 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells5 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells6 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells7 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells8 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells9 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells10 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells11 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells12 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells13 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells14 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells15 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    		NmbOfTmp = (uint8_t)(ReceiveData[a] << (b+8)); a+=1;b+=8;
    
    		TemperatureCells1 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells2 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells3 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells4 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells5 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells6 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells7 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells8 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    		ChargeDıschargeCurrent = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TotalBatteryVoltage = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		ResidualCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		CustomNumber = (uint8_t)(ReceiveData[a] << (b+8)); a+=1;b+=8;
    		BatteryCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		SOC = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		RatedCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		NumberOfCycle = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		SOH = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		PortVoltage = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    
    		HAL_Delay(1000);
    		a=i++;
    
    	}
    
    
    
    }
    
    /* 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_DMA_Init();
     MX_USART1_UART_Init();
     /* USER CODE BEGIN 2 */
     HAL_UARTEx_ReceiveToIdle_DMA(&huart1, RxData, sizeof(RxData));
    
     /* USER CODE END 2 */
    
     /* Infinite loop */
     /* USER CODE BEGIN WHILE */
     while (1)
     {
     /* USER CODE END WHILE */
    
     /* USER CODE BEGIN 3 */
    
    	 SeplosBms_Write();
    	 HAL_Delay(500);
    	 SeplosBms_Read();
    
    
    
     }
     /* USER CODE END 3 */
    }
    
    /**
     * @brief System Clock Configuration
     * @retval None
     */
    void SystemClock_Config(void)
    {
     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    
     /** Configure the main internal regulator output voltage
     */
     __HAL_RCC_PWR_CLK_ENABLE();
     __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
    
     /** Initializes the RCC Oscillators according to the specified parameters
     * in the RCC_OscInitTypeDef structure.
     */
     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
     RCC_OscInitStruct.HSEState = RCC_HSE_ON;
     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
     RCC_OscInitStruct.PLL.PLLM = 4;
     RCC_OscInitStruct.PLL.PLLN = 168;
     RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
     RCC_OscInitStruct.PLL.PLLQ = 4;
     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
     {
     Error_Handler();
     }
    
     /** Initializes the CPU, AHB and APB buses clocks
     */
     RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
     |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
     RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
     RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
     RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
     RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
    
     if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
     {
     Error_Handler();
     }
    }
    
    /**
     * @brief USART1 Initialization Function
     * @PAram None
     * @retval None
     */
    static void MX_USART1_UART_Init(void)
    {
    
     /* USER CODE BEGIN USART1_Init 0 */
    
     /* USER CODE END USART1_Init 0 */
    
     /* USER CODE BEGIN USART1_Init 1 */
    
     /* USER CODE END USART1_Init 1 */
     huart1.Instance = USART1;
     huart1.Init.BaudRate = 9600;
     huart1.Init.WordLength = UART_WORDLENGTH_9B;
     huart1.Init.StopBits = UART_STOPBITS_1;
     huart1.Init.Parity = UART_PARITY_NONE;
     huart1.Init.Mode = UART_MODE_TX_RX;
     huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
     huart1.Init.OverSampling = UART_OVERSAMPLING_16;
     if (HAL_UART_Init(&huart1) != HAL_OK)
     {
     Error_Handler();
     }
     /* USER CODE BEGIN USART1_Init 2 */
    
     /* USER CODE END USART1_Init 2 */
    
    }
    
    /**
     * Enable DMA controller clock
     */
    static void MX_DMA_Init(void)
    {
    
     /* DMA controller clock enable */
     __HAL_RCC_DMA2_CLK_ENABLE();
    
     /* DMA interrupt init */
     /* DMA2_Stream2_IRQn interrupt configuration */
     HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
     /* DMA2_Stream7_IRQn interrupt configuration */
     HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);
    
    }
    
    /**
     * @brief GPIO Initialization Function
     * @PAram None
     * @retval None
     */
    static void MX_GPIO_Init(void)
    {
     GPIO_InitTypeDef GPIO_InitStruct = {0};
    /* USER CODE BEGIN MX_GPIO_Init_1 */
    /* USER CODE END MX_GPIO_Init_1 */
    
     /* GPIO Ports Clock Enable */
     __HAL_RCC_GPIOH_CLK_ENABLE();
     __HAL_RCC_GPIOD_CLK_ENABLE();
     __HAL_RCC_GPIOA_CLK_ENABLE();
    
     /*Configure GPIO pin Output Level */
     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
    
     /*Configure GPIO pins : PD12 PD13 PD14 PD15 */
     GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
    
    /* USER CODE BEGIN MX_GPIO_Init_2 */
    /* USER CODE END MX_GPIO_Init_2 */
    }
    
    /* USER CODE BEGIN 4 */
    
    /* USER CODE END 4 */
    
    /**
     * @brief This function is executed in case of error occurrence.
     * @retval None
     */
    void Error_Handler(void)
    {
     /* USER CODE BEGIN Error_Handler_Debug */
     /* User can add his own implementation to report the HAL error return state */
     __disable_irq();
     while (1)
     {
     }
     /* USER CODE END Error_Handler_Debug */
    }
    
    #ifdef USE_FULL_ASSERT
    /**
     * @brief Reports the name of the source file and the source line number
     * where the assert_param error has occurred.
     * @PAram file: pointer to the source file name
     * @PAram line: assert_param error line source number
     * @retval None
     */
    void assert_failed(uint8_t *file, uint32_t line)
    {
     /* USER CODE BEGIN 6 */
     /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
     /* USER CODE END 6 */
    }
    #endif /* USE_FULL_ASSERT */
    sezear07Author
    Explorer
    June 21, 2024

    I haven't completely finished the code yet. Initially, I wrote it using the normal HAL_UART_TRANSMIT() function. Later, they suggested that listening to the idle line with DMA would yield better results. Therefore, I am trying to integrate the HAL_UARTEx_ReceiveToIdle_DMA(&huart1, RxData, sizeof(RxData)); function into the system.

    Graduate II
    June 21, 2024

    Your receive method makes no sense, it loops, has a blocking UART_Receive() of unknown length.

    Loops around that 76 times, doesn't define the memory buffer's it is using in this context. Based on RxData[i] it's 76 characters long, but how is that supposed to synchronize with the data transmitted. How is the RS485 bus direction set? Presume the GPIOD are changing LEDs, but no commentary.

    This is an STM32F407G-DISCO board?

    void SeplosBms_Write()
    {
    	uint8_t Tx1Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x34, 0x34, 0x45,
    				0x30, 0x30, 0x32, 0x30, 0x30, 0x46, 0x44, 0x33, 0x35, 0x0D}; // Get #0pack Telecommand Data.
    
    	uint8_t Tx2Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x30, 0x30, 0x31,
    					0x30, 0x34, 0x42, 0x30, 0x30, 0x46, 0x44, 0x33, 0x42, 0x0D}; // Get #0pack CID2 NORMAL Data.
    
    	uint8_t Tx3Data[] = {0x7E, 0x32, 0x30, 0x30, 0x30, 0x34, 0x36, 0x34, 0x32, 0x45,
    						0x30, 0x30, 0x32, 0x30, 0x30, 0x46, 0x44, 0x33, 0x37, 0x0D}; // Get #0pack telemetry Data.
    
    	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
    	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
    
    	HAL_UART_Transmit(&huart1, Tx1Data, sizeof(Tx1Data), 1000);
    	HAL_Delay(500);
    	HAL_UART_Transmit(&huart1, Tx2Data, sizeof(Tx2Data), 1000);
    	HAL_Delay(500);
    	HAL_UART_Transmit(&huart1, Tx3Data, sizeof(Tx3Data), 1000);
    	HAL_Delay(500);
    }
    
    void SeplosBms_Read()
    {
    	for(int i=0; i<=75; i++)
    	{
    
    		if(HAL_UART_Receive(&huart1, RxData, sizeof(RxData), 1000) == HAL_OK) // Bu kısım değişecek //
    		{
    
    			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
    			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
    		}
    
    
    		ReceiveData[a] = RxData[i];
    
    		uint8_t a =0;
    		uint8_t b =0;
    		flag = (uint8_t)(ReceiveData[a] << (b)); a+=1;
    		CmdGROUP = (uint8_t)(ReceiveData[a] << (b+8)); a+=1; b+=8;
    		NmbOfCells = (uint8_t)(ReceiveData[a] << (b+8)); a+=1; b+=8;
    
    	 VoltageCells1 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells2 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells3 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells4 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells5 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells6 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells7 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells8 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells9 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells10 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells11 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells12 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells13 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells14 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		VoltageCells15 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    		NmbOfTmp = (uint8_t)(ReceiveData[a] << (b+8)); a+=1;b+=8;
    
    		TemperatureCells1 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells2 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells3 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells4 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells5 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells6 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells7 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TemperatureCells8 = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    		ChargeDıschargeCurrent = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		TotalBatteryVoltage = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		ResidualCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		CustomNumber = (uint8_t)(ReceiveData[a] << (b+8)); a+=1;b+=8;
    		BatteryCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		SOC = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		RatedCapacity = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		NumberOfCycle = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		SOH = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    		PortVoltage = (uint16_t)((ReceiveData[a] << (b+16))| (ReceiveData[a+1] << (b+8))); a+=2; b+=16;
    
    
    		HAL_Delay(1000);
    		a=i++;
    
    	}
    
    }

     

    Graduate II
    June 21, 2024

    Data isn't buffered by the UART.

    Errors generated whilst not listening need to be cleared.

    Presumably RS485 is used half-duplex, not indication of hardware or software affecting that implementation.

    Loop implies 76 * 76 bytes (5776) received

    Perhaps you wanted to receiver 76 bytes, move them to a secondary buffer, and then process / separate them there?

    sezear07Author
    Explorer
    June 21, 2024

    What I want to do is send telemetry data from the datasheet with the STM32F407VGT6 board and then read the 75-byte long temperature and voltage data. I have no issues with the data transmission process; it is successful. However, I am unable to read the data during the receiving process. Are you suggesting that using DMA to read the necessary data when the line is idle?

    Graduate II
    June 22, 2024

    It is not mandatory to use DMA, you can use any mode to read the data. Basically read means send a command to

    CORRECT address as se the DIP switch. Make sure that you send the command bytes correctly, Check sum and Length etc. While sending keep DE/RE to  1 so that transmission happens and immediately switch over to 0 for the unit to respond. Receive till 0x0D

    eg of query command from the datasheet

    Techn_0-1719034206311.png

    if you prefer to read in your main loop keep reading till you get 0x0D or in interrupt you can receive one byte  each till you assemble all bytes till 0x0D. Then inform main loop to process the data. The response will happen if you send it to the correct address, else nil. At least one message you hand code carefully and test it.

    Timeout of 500ms can be implemented to avoid infinite waiting.

    sezear07Author
    Explorer
    June 22, 2024

    Do you know how to manually set the address? For example, I manually keep the address positions at zero and send the command based on the address value 00.

     

    As far as I understand, the STM sends commands based on the data in Table 7. For example, after sending the telemetry data at address 00 in Table 7, we should automatically receive the parameters such as cell voltages and cell temperatures listed in Table 8, right? My main question is, if I need to store the temperature and voltage parameters from Table 8 into specific arrays, those bits should correspond to the temperature and voltage values we need. However, it is not specified in Table 8 which bytes the temperature and voltage data should be stored in. In this case, do you think my void SeplosBms_Read(); function is written correctly? Do you see any other errors in the code?

    140.PNG

    142.PNG

    Graduate II
    June 22, 2024

    How many devices are there? you need to know the address. earlier you made a statement that transmit is success, does it mean that when you send data, any parameter gets changed in the target device?

    make sure that you connect A ->A and B->B  and GND

    I am not familiar with your system. There must be some way to set the address by some dip switches. You need to know the set address.

    you need to go step by step. Your first problem was how to get some response from the target device. Once you receive that you can start interpreting the data based on table 8,9 .

    Let us know once you are able to get response from the target device. 

    Table 8 seems clear in the sense that the how many bytes are needed for each parameters, you need to count it as per the table, first read the number of cells and based on that you can count from the start of the frame. Looks like if you read the document multiple times and  analyze you can do it.