UART communication problem between Raspberry Pi 4 and STM32F767ZI
Hello everyone,
I'm trying to debug a problem with the UART communication between the raspberry pi 4 and an STM32.
Indeed, I try to send the number 1 from the raspberry pi to the stm32 but I can't get the right result.
Here is the code I implemented on the raspberry pi 4 :
import serial
from time import sleep
ser = serial.Serial(
port = "/dev/ttyS0",
baudrate = 9600,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 1
)
data = 1
while True:
data_str_list = [str(data)]
send_string = ','.join(data_str_list)
ser.write(send_string.encode())
sleep(1)Here is the STM32 code :
char data_sign[1];
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_USART3_UART_Init();
MX_DAC_Init();
MX_UART4_Init();
MX_TIM6_Init();
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_UART_Receive(&huart4, data_sign, sizeof(data_sign), 1000);
}
/* USER CODE END 3 */
}
static void MX_UART4_Init(void)
{
huart4.Instance = UART4;
huart4.Init.BaudRate = 9600;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
}When I send 1, I get this with the STM32 debug:
Sometimes, the value is 241 but I don't know how to interpret this data. Can you please help me please? I think it's a problem with the data types but I tried to change them but I still can't find the right result.
I also changed the clock frequency of the STM32 but nothing changes. The function HAL_UART returns 0.