I have struggled with this bug for a day now, and still can't figure out, I think I might missed something.
I'm using mega1281 in 5V and 16Mhz, and have 3 SPI slaves, a RF chip and two ADCs. I have included the bootloader code in my CPU and application code will do bootloader jmp if it rx a special RF command. In the start of application code and bootloader code, I have exactly the same code for initializing all 3 SPI devices. In all the application codes, this SPI interface work correctly. The problem is, when it's in application, and I send out that RF command, then it's correctly send back ACK and jumped to bootloader, but then if I send out any other RF packets, it (the bootloader code) just always got CRC error. And I found out that it's because the MISO pin of SPI always got lower voltage (it suppose to be 3.3V, but oscilloscope showed of < 2V, MISO is connected with three SO pins from RF chip and other 2 ADCs, RF chip should output 3.3V on MISO and ADCs should output 5V, and during bootloader, ADCs were never been selected, so they suppose to be high impedance then), so the SPI rx were never correct. And if the sensor PCB (whick has that 2 ADCs) was unconnected from CPU, then the whole bootloader works. But what I don't understand is this MISO pin
did work in application code, and I have the same initialization for 3 SPI devices in app and in BL. So how???
My feeling is that it must be a software bug, but I just have no clue!
So what's difference between running a SPI in app and in BL?
BTW, my bootloader code was done in another main code and add address to 0x1E000 in makefile. So in the start of bootloader, it will do the <__ctors_end>, <__do_copy_data> and <__do_clear_bss>.