No announcement yet.

Baud rate calculation

  • Filter
  • Time
  • Show
Clear All
new posts

  • slomobile
    started a topic Baud rate calculation

    Baud rate calculation

    I want to be sure I understand the datasheet baud rate equation correctly. Could we get some clarification, perhaps add some parentheses in the right places. The sheet says:
    Baud rate = 14.7456MHz / 2 x (2nd Divider + 1) / 2 x (1st Divider + 1)
    but plugging known working values into my calculator(without added parenthesis) did not result in a true equation.
    Does that mean Baud rate = (14745600 / (2 x (2nd Divider + 1))) /( 2 x (1st Divider + 1))
    or Baud rate = (7372800 x (2nd Divider + 1) / 2) x (1st Divider + 1)
    or something else entirely?

    It is typical for micro controllers to not exactly produce all the common baud rates due to their choice of main clock frequency. My uC runs a similar function called myCpuPctError(baudRate) which returns how far the actual baud rate will be from the desired baud rate. I wanted to automatically choose optimum dividers for the uCam that best matched the actual rate delivered by my microcontrollers so I wrote these functions:

    int32_t negotiateFastestBaudRate(){ uint8_t dividerA; uint8_t dividerB;int32_t baudRate = 1228800; // start at the highest known baudrate that might work.while (abs(myCpuPctError(baudRate) - setBaudOptimized(baudRate , &dividerA, &dividerB)) > 2)// greater than 2 percent total error between sender and receiver, unacceptable{baudRate -= 300; // step down from the maximum possible rate 300Baud at a time until a mutually acceptable rate is found. That rate is then set and returned.}send(AA, 07, dividerA, dividerB, 00, 00); receiveACK();Uart.begin(baudrate);return baudrate;} int32_t setBaudOptimized(int32_t desiredBaudRate, uint8_t * dividerA, uint8_t * dividerB){ //select integer dividers such that//desiredBaudRate = 14745600 / 2 x (bestDividerA + 1) / 2 x (bestDividerB + 1)uint8_t currentDividerA, currentDividerB, bestDividerA, bestDividerB = 0;int32_t actualBaudRate, currentErrorPct, bestErrorPct = INT32_MAX;for(currentDividerB = UINT8_MIN; currentDividerB

  • ESPsupport

    Yes, sorry, the correct forumula is

    Baud rate = 14.7456MHz / (2 x (2nd Divider + 1)) / (2 x (1st Divider + 1) )

    Leave a comment: