Also posted at: https://forum.arduino.cc/index.php?topic=549672.0
is there anyone who experienced similar problem or knows a solution to it?
The problem is that after uploading the code Arduino Pro Micro hangs (and RX led is constantly on).
The problem occurs instantly after turning on the microcontroller even if I put "delay(10000);" at the begining of the code trying to see at which point the error occurs.
The problem can be "fixed" by adding 'Serial.print("aa");' at random place within the code... Which results in the following output during upload:
Sketch uses 18318 bytes (63%) of program storage space. Maximum is 28672 bytes. Global variables use 1814 bytes (70%) of dynamic memory, leaving 746 bytes for local variables. Maximum is 2560 bytes.
Suprisingly, using 'Serial.print("a");" instead does not fix the problem. It results in the following output during upload:
Sketch uses 18314 bytes (63%) of program storage space. Maximum is 28672 bytes. Global variables use 1810 bytes (70%) of dynamic memory, leaving 750 bytes for local variables. Maximum is 2560 bytes.
It seems very weird to me that adding serial print instruction with certain length (at seemingly random place) can solve such problem...
Another circumstance which seems to be solving the problem is commenting out one of the 2 lines (does not matter which):
sprintf(at_cmd, "AT+NAME%s\0", bluetoothName); sprintf(at_pin_cmd, "AT+PIN%s\0", pin);
It's a spaghetti code so I doubt anyone will analyse it but just in case if anyone wanted to check it for some more or less obvious characteristic (e.g. F()/eeprom/memory extensive use or something...) then here it is: Hastebin - link
I'm using "Arduino Pro Micro 5V" and Arduino IDE 1.8.5 with "Arduino Leonardo" board setting