If the timing is always exactly 27 seconds, then there is one likely cause: the watchdog. You do not say which microcontroller you're using, but check if it's got a watchdog and confirm that the watchdog is doing what you expect it to do.
Another option, less likely but also possible, is some demo versions of development software builds a time limit into any source code that you compile. So you can test anything you like, but it will set the watchdog to reset the CPU after a certain time. This prevents you from creating a commercial product with demo software tools.