cancel
Showing results for 
Search instead for 
Did you mean: 

uart

kkhli.1
Associate III

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 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

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

View solution in original post

3 REPLIES 3
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
kkhli.1
Associate III
my protoclol say that the maximum value can be recieved is in format 2 byte , so there is some value in format 1 byte , others in 2 byte (you can see the capture )but the frame contain 10 value so that why i defined rx buff[10]
 
 

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

 

TDK
Guru

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.

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