Skip to main content
kkhli.1
Associate III
January 10, 2024
Solved

Uart receiver pb

  • January 10, 2024
  • 7 replies
  • 10344 views

 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);

 

 

  }

Best answer by kkhli.1

HELLO,I resolved the problem and I want to share the solution with you: the issue is with the RX is always pulled down by the BLDC,, just I changed the brushless controller and all is ok

7 replies

Tesla DeLorean
Guru
January 10, 2024

Perhaps you're looking at the wrong end of the problem?

Perhaps make the receive here accumulate data and output some kind of diagnostic.

Don't ignore error codes returned, and check the status of the USART and that's it's not holding some sticky failure status, like Noise, Framing, Overrun, or whatever.

Using the debugger, single stepping, and viewing the peripheral registers is unlikely to be a helpful approach.

Add more diagnostic output so you understand what the STM32 is doing / seeing.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Principal
January 10, 2024

You probably didn't enable the NVIC for the UART. 

You call HAL_UART_Receive_IT in two different places but 1 of them is set to interrupt on 1 byte instead of 10.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

yhe nvic was enabled. the uart transmit work well.but the uart recieve don't work.

Andrew Neil
Super User
January 11, 2024

@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.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Karl Yamashita
Principal
January 11, 2024

Hard to tell what you're doing unless you post a more relevant code. You haven't posted any code on readParameter function so don't know how you're checking for received data. Your code doesn't show any transmit either so contradicts you saying that the transmit works.. 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

@Karl Yamashita wrote:

Hard to tell what you're doing unless you post a more relevant code. You haven't posted any code on readParameter function so don't know how you're checking for received data. Your code doesn't show any transmit either so contradicts you saying that the transmit works.. 


i made an entry error .infact. readparameter() is  void sendParameter(uint8_t p

arameter) but even ithat  still not working

the transmit work well you can see the image below (frame to send) is the same data i have sent with uart transmit .uint8_t senddata[4] = {0x66, 0x42, 0x00, 0xA8};

Karl Yamashita
Principal
January 11, 2024

You say the receiver is not operating as expected but give no explanation. How are you checking for received data?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Karl Yamashita
Principal
January 11, 2024

When you call the first HAL_UART_Receive_IT you don't check the HAL status so how do you know if interrupt mode is enabled? Is this a custom board?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

No but i made a break point at the first HAL_UART_Recieve _IT , he didtn't even enter  the function

I also noticed if I remove the delay   HAL_Delay(100);  the transmitt will send a missing message 

void sendParameter(uint8_t parameter)

{

  HAL_UART_Transmit_IT(&huart1, senddata, 4);

HAL_Delay(100);

}

it send this 

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

Karl Yamashita
Principal
January 11, 2024

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 a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

i will verify again ,  thank you for answering

Karl Yamashita
Principal
January 11, 2024

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 a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

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

Karl Yamashita
Principal
January 11, 2024

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 a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
kkhli.1
kkhli.1Author
Associate III
January 11, 2024

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

Andrew Neil
Super User
January 11, 2024

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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.