- Sun May 10, 2015 6:41 am
#17074
Also interesting: Setting the baud rate. Apparently you need to set a clock divisor as "uart clock" (which via three defines equals 80 Mhz = CPU clock) divided by the request baud rate. On ATmel uart's you need to set 16 * the baudrate as divisor because for every bit, 16 samples are taken and four of them of weighed which improves the influence of noise.
I am curious how esp8266 does that then, if it really one takes one sample per bit. If that's the case, the uart could be set to any baud rate you like, up to 80 Mhz, as long it's divisible by 1,2,3,4, etc., not just the standard rates. But somehow I doubt it works that way, I think the value is divided by 16 internally.
Also interesting is that the base cpu frequency can't match standard baud rates exactly (if internal division by 16 is assumed). for instance for 460800 baud, you will actually get 454545 baud, which is 1.3% off, which is just barely acceptable (according to ATmel guidelines).
This is especially interesting, because this means you don't need to bother using "exact" crystals on your connected microcontroller (like the 11.059.200 Hz ones, that can give you *exact* standard baud rates) and just use whatever you have lying around or even use the internal rc oscillator, which in my case, gives 8 MHz and can produce a baud rate of up to 1 Mhz ("double speed mode", 8 samples instead of 16), which the esp8266's uart can match *exactly*. For reliable operation it may be wise to switch to something lower though
(1 MHz divided by 1,2,3,4,etc. which will match exactly on both sides).