A very strange problem for my bootloader code

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

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?

Help please!!!

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>.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

maybe the pin´s internal pullup is not set to the same. Or the CS of one device is actvated in one mode and therfore it pulls the signal from highimpedance to a true logic state. Timing is another thing that can influence operation.
High impedance inputs may change voltage in unpredictable time....

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Klaus,

The MISO in both app and BL are set as normal input, so there is no internal pull-up problem.

I also carefully checked CS in both code, it's no problem.

I run the SPI clk at 8Mhz (fosc/2) in both code. Since in the application it works, so I assume there is no hardware problem at SPI interface.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I would set it to input with pullup - in both cases, then you allways have defined voltage levels.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

YES!! exactly, it's the pullup
Now everything is working, thanks, Klaus.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just found out if sensor PCB is connected and it's in bootloader code (with pullup enabled), then MISO is merely 2.1V, not the 5V it suppose to be. and if sensor PCB is not connected, then it's 5V. So it must be ADCs are sinking the current. But how?? In the bootloader initialization, I pulled up two ADC CSn pins, and I checked two CSn pins, they are 5V in bootloader code, so their SO pin should be high-z then.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And if I enabled MISO pullup in application code, then I can get 5V MISO with sensor connected!!

So it's must be the initialization code problem, but I just can't find the difference.