2024-01-09 02:38 AM - edited 2024-01-09 07:07 AM
I'm trying to do uart stm23F7xx communication with a bldc controller, based on the blds controller protocol, I did communication but using an arduino and the labrarry #include <SoftwareSerial.h>,
I found it hard with stm32 the problem I have to send some data to start a communication using sendParameter()and to receive a frame in a table of size 10 (see image protocol in touche), the problem I only receive two values tab[0] and tab[1 ]the first correct value and the second value is incorrect: here is my code:
uint8_t rx_buff[10];
uint8_t tx_buff[]={0x66,0x02,0x00,0X68}; //MESSAG SENT TO BLDC CONTROLLER
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart1, rx_buff,sizeof(rx_buff)); //You need to toggle a breakpoint on this line!
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, rx_buff, sizeof(rx_buff))
while (1)
{
HAL_UART_Transmit_IT(&huart1, tx_buff, 4);
HAL_Delay(1000);
}
/* USER CODE END 3 */
}
Solved! Go to Solution.
2024-01-09 06:42 AM
You're sending 4 bytes and receiving 2. Your protocol says there are 10 bytes. Why not receive 10 instead of 2?
> the first correct value and the second value which is incorrect:
Let's do a little better than correct and incorrect. What are the values? If they are not what you want, what values are you expecting?
A logic analyzer would be useful here. It's possible whatever you're talking to isn't sending what you think it is.
2024-01-09 06:42 AM
You're sending 4 bytes and receiving 2. Your protocol says there are 10 bytes. Why not receive 10 instead of 2?
> the first correct value and the second value which is incorrect:
Let's do a little better than correct and incorrect. What are the values? If they are not what you want, what values are you expecting?
A logic analyzer would be useful here. It's possible whatever you're talking to isn't sending what you think it is.
2024-01-09 07:15 AM
i expect those value :
rx_buff[0]=102
rx_buff[1]= 66
rx_buff[2]=6
rx_buff[3]=2
rx_buff[4]=52
rx_buff[5]=0
rx_buff[6]=0
rx_buff[7]=0
rx_buff[8]=0
rx_buff[9]=228
2024-01-11 06:35 AM - edited 2024-01-11 06:36 AM
Your code has changed, so it's difficult to know the current state of this problem.
I'll ask again: with your current code, what values are you receiving when the HAL_UART_RxCpltCallback callback happens? Not what you want to receive, but the literal values that are in the buffer when that callback happens. You say they're wrong, but let's be more precise.