I have a problem getting started with the TTGO LoRa v1.0 board. I use the ESP32 dev board and UART communication doesn't work well. The XTAL is 26MHz obviously and the software thinks it's 40MHz. So the 115200 baudrate is actually 26/40 * 115200 = 74880. How can I correct the XTAL frequency of ESP32 dev board to 26MHz?
This code:
Freq = getXtalFrequencyMhz();
Serial.print("XTAL Freq = ");
Gives this result:
XTAL Freq = 40 MHz
Thanks in advance for your help. I would like to try to connect to the TTN next. Links are welcome.
And when you loaded that program that you included just a snippet of, what baud rate did you have in Serial.begin() and what baud rate did you have set in the Serial monitor ?
It works with a 26MHz crystal apperently. Normally it the ESP32 works with a 40MHz crystal. But how can I change the MHz of the crystal?
That would be great. So I can normally use Serial.begin(115200); for 115200.
This also works with 240MHz. I don't know exactly how this is done, but most of the time they use a crystal of 40MHz and a internal PLL in the ESP32 transforms 40MHz to 240MHz. UARTs are derived from the crystal frequency. So at 40MHz it's 115200. With 26MHz the 240MHz PLL frequency becomes 26/40 * 240=156MHz and the Baudrate is also mulitplied with the same factor. 26/40 * 115200=74880.
So I am looking for a way to tell Arduino that it is a 26MHz crystal. It will reconfigure the PLL (for 26MHz) and the system will run at 240MHz again.
I am a hardware engineer, so that's why I know a little bit what is happening.
Thanks for that; I seem to have a vage memory that that is how it might work. High frequency stuff was never my strong point and did not have my interest.
Probably that it the board is running at 156MHz instead of 240MHz.
If you want to tell the IDE (and compiler) that the code should be compiled for a different frequency the following will be the basics that might do the trick.
Search for the exact board that you're compiling for. I did search for ttgo and found ttgo-lora32.name=TTGO LoRa32-OLED as that seems to be the closest to what you have and you still did not tell us for which exact board you are compiling.
Scroll down till you find the line ttgo-lora32.build.f_cpu=240000000L.
Adjust to needs (156000000L I guess).
Save the file.
Start the IDE.
Notes:
This if for an installation of IDE 2.x or a normal IDE 1.x installation. For a portable installation of IDE 1.x it will be different.
Be aware that this change will be wiped if the board package is upgraded/downgraded.
thanks for your answer. I was compiling with the standard ESP32 dev board. Didn't know that this crystal configuration was part of the board, but that only seems logical. I see that you warn for upgrades. I hope I can add my 'own' board, so I know that if the boards are upgraded that it doesn't effect the board I added.