2024-06-20 11:53 AM
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.
thank you for answer
2024-06-21 08:54 AM
I followed your instructions step by step, but it didn't work.
2024-06-21 09:33 AM
Can you post your full code?
2024-06-21 09:53 AM
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.
2024-06-21 10:04 AM
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++;
}
}
2024-06-21 10:08 AM
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?
2024-06-21 11:12 AM
/* 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 */
2024-06-21 11:15 AM
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.
2024-06-21 11:22 AM
I have probably found where the two errors are, but I need to test it on the system. I think my first error is due to using the MAX485 TTL-RS485 because the DE/RE pins should be in the high position while performing the transmit operation, and in the low position while performing the receive operation. However, I want to send a command first with STM and then read temperature and voltage data, so this code only performs the transmit operation, and I need to find a solution for that. Another issue is that I think I need to read with DMA because it can listen when the line is idle and then perform a healthier read even if the byte length of the data is unknown.
2024-06-21 11:25 AM
Yes, I am using the STM32F407VGT6 board. I can show you the block diagram of the system as follows.
2024-06-21 11:30 AM
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?