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

 

 

  }

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

26 REPLIES 26

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Lead III

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.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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

Karl Yamashita
Lead III

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

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

@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};

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

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

the reciver have to  revieve a frame ( the image frame to revieve took with logic analyzer) but the uart recieve it () dont fired.. i cheked that with live expression.look at the image(recieve pb)

Karl Yamashita
Lead III

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?

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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