cancel
Showing results for 
Search instead for 
Did you mean: 

Uart receiver pb

kkhli.1
Associate III

 i have established communication with a BLDC (Brushless DC) controller. Initially, i send a message to the controller using the function void sendParameter(uint8_t parameter). Following this transmission, the BLDC controller is expected to respond with a frame. Although the transmission process appears to be functioning correctly, the receiver is not operating as expected. i have confirmed this issue using a logic analyzer. 

 

 

UART_HandleTypeDef huart1;

uint8_t buffer[10];

uint8_t senddata[4] = {0x66, 0x42, 0x00, 0xA8};

uint8_t transmitAllowed = 1;

-----------------------------------------------*/

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, buffer, 1);

}

 

void sendParameter(uint8_t parameter)

{

  HAL_UART_Transmit_IT(&huart1, senddata, 4);

HAL_Delay(100);

}

 

  */

int main(void)

{

 

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  MX_USART1_UART_Init();

 

  HAL_UART_Receive_IT(&huart1, buffer, 10);

  while (1)

  {

        readParameter(0x42);

 

 

  }

26 REPLIES 26
Karl Yamashita
Lead III

If it didn't enter the function then the interrupt is not enabled. If it did enter and returns, you'll get return status HAL_OK.

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.
Karl Yamashita
Lead III

Just upload the whole project so we can see the actual code and the ioc file. And let us know if you're using a custom board or a Nucleo/Discovery board.

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

i will verify again ,  thank you for answering

you find attached my project , I'm using Nucleo F446RE

Karl Yamashita
Lead III

You've changed the clock settings from the default board setup. I don't have that board so I can't test if those new settings are causing an issue. Just start a new project using the default settings it creates. 

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

@kkhli.1 "yhe nvic was enabled."

That's necessary - but not sufficient.

As well as having the NVIC correctly configured, you also need the UART to be correctly configured to generate interrupts.

"the uart transmit work well. but the uart recieve don't work."

Could mean that you don't have the receive interrupt enabled.

I have to recieve a frame from a bldc controller , this frame as follows 

START CMD LENGTH BAT CUROLD TSNS STATE USER VOL CUR

0x660x420x??1 byte1 byte2 bytes1 byte2 bytes2 bytes2 bytes

but i didn't receive anything , the problem with how to manage the lengh of every  values 's frame(byte ,2byte)could you help me please? i'm using nucleo F446RE

I thought you said you were abandoning this thread, and moving to your new one?

https://community.st.com/t5/stm32-mcus-products/uart-reciever/m-p/627367/highlight/true#M232225

 

That's 14 bytes but you're requesting 10 bytes. So even if you did get interrupt to work, you're going to have data out of sync.

Modify the UART1 for loopback mode and transmit to see if you receive, but in polling mode. This is to insure the rx input is not broken.

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

So reading the other posts you've created, your received data could be variable length and you're not sure how to receive the different lengths.

Use HAL_UARTEx_ReceiveToIdle_DMA or HAL_UARTEx_ReceiveToIdle_IT, and for the callback use HAL_UARTEx_RxEventCallback

 

Look at this project on my github which explains how to receive different lengths. 

https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki

 

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.