Skip to main content
EPora.1
Associate III
August 25, 2021
Question

STM32 UART1 most significant part problem

  • August 25, 2021
  • 3 replies
  • 2006 views

Hi,

I'm trying to use uart1 in stm32f411ce and I have a weird problem. in my test I am sending data from the stm32 to an arduino and printing the received data on the serial monitor. In the stm32 I'm sending bytes with the most significant part counting from 0x02 to 0xF2. the list significant part always transmits well but the LSP has a weird behavior. I made a table that shows the transmitted bytes and the received bytes.

thanks0693W00000DqIsqQAF.jpg

    This topic has been closed for replies.

    3 replies

    Javier1
    Principal
    August 25, 2021

    What is your uart configuration?, maybe youre not matching what your arduino is expecting?

    (normally (Data length =8, Parity bit =1, Number of Stop Bits=None))

    hit me up in https://www.linkedin.com/in/javiermuñoz/
    EPora.1
    EPora.1Author
    Associate III
    August 25, 2021

    Thanks for your answer!

    my configuration is (Data length =8, Parity bit =0, Stop bits =1). I thought that that is the default. I'll test the configuration you wrote.

    Javier1
    Principal
    August 25, 2021

    You can also change it in your arduino, https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/

    Serial.begin(115200, SERIAL_8N1);
    /*
    SERIAL_5N1
    SERIAL_6N1
    SERIAL_7N1
    SERIAL_8N1 (the default)
    SERIAL_5N2
    SERIAL_6N2
    SERIAL_7N2
    SERIAL_8N2
    SERIAL_5E1: even parity
    SERIAL_6E1
    SERIAL_7E1
    SERIAL_8E1
    SERIAL_5E2
    SERIAL_6E2
    SERIAL_7E2
    SERIAL_8E2
    SERIAL_5O1: odd parity
    SERIAL_6O1
    SERIAL_7O1
    SERIAL_8O1
    SERIAL_5O2
    SERIAL_6O2
    SERIAL_7O2
    SERIAL_8O2
    */

    *You might be right (Data length =8, Parity bit =0, Stop bits =1) is the default, just try out things

    hit me up in https://www.linkedin.com/in/javiermuñoz/
    EPora.1
    EPora.1Author
    Associate III
    August 25, 2021

    I have wrote it myself. here is the arduino and the TX code.0693W00000DqLOPQA3.jpg0693W00000DqLOKQA3.jpg0693W00000DqLNlQAN.jpg

    Javier1
    Principal
    August 25, 2021

    whats wrong with USART_SendData()?

    also the while(!USART.... (active wait ) should be checked before the transmission attempt not after.

    hit me up in https://www.linkedin.com/in/javiermuñoz/
    EPora.1
    EPora.1Author
    Associate III
    August 25, 2021

    I am trying to not use the HAL lib. But I should try same thing with the HAL​ to see if it's hardware and also check the tx register empty bit before transmit

    EPora.1
    EPora.1Author
    Associate III
    August 26, 2021

    Problem solved. After a couple of days I have decided to check the uart with lower main clock frq and apparently it works under 86mhz

    Javier1
    Principal
    August 26, 2021

    Congrats!, clock issues are not the easyest to spot.

    Maybe your XTAL pcb traces have huge capacitance or you placed the sligtly bigger than needed capacitors?(or youre using one of those RC resonators instead of a xtal)

    You can figure out the real clock your chip is using by probing with an oscilloscope very fast PWMs or outputing master clock directly to a pin.

    0693W00000DqQp6QAF.png 

    hit me up in https://www.linkedin.com/in/javiermuñoz/
    EPora.1
    EPora.1Author
    Associate III
    August 26, 2021

    It may be the problem. My capacitors on the xtal lines are 30pF. I have chose this based on the load capacitance of my ​crystal.