[SOLVED] SPI trouble

Post here to get support
arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

[SOLVED] SPI trouble

Post by arashi » Mon Apr 10, 2017 5:52 pm

So... I just soldered an expansion header onto my Crazyradio PA and, for starters, am doing some basic SPI read tests and both the Infopage and the Mainblock always seem to come back empty! I've had the Crazyradio PA hooked up to both a Raspberry Pi and a Bus Pirate (though not at the same time...) and the result is the same. My Crazyradio PA has never been written to (by me) and I've verified with nrfdude that at least the Mainblock contains SOMETHING.

I'm pretty much an electronics n00b. Please forgive my n00bness. Does this sound like the result of a shoddy soldering job? How can I debug this problem?

The software that I've used:

https://github.com/RGassmann/nRF24LU1P_SPI_Flashing
https://github.com/zerog2k/nrfprog

Example session with my Crazyradio PA hooked up to a Bus Pirate:

Code: Select all

$ ./nrfprog /dev/ttyUSB7 output
Opening the Bus Pirate UART
Setting the Bus Pirate to Binary Mode
Configuring SPI mode
Backing up the info page
starting read operation
Reading from the device to output
starting read operation
Putting the Bus Pirate back in normal operating mode
Closing the Bus Pirate
$ ls -og
total 80
-rw-r--r-- 1   1396 feb 26 21:52 README.md
-rw-r--r-- 1  15331 feb 26 21:52 nrfprog.c
-rw-r--r-- 1    418 feb 26 21:52 nrf24le1.h
-rw-r--r-- 1   1731 feb 26 21:52 bp.h
-rw-r--r-- 1    194 apr 10 13:46 Makefile
-rwxr-xr-x 1  24888 apr 10 13:46 nrfprog
-rw-r--r-- 1    512 apr 10 16:18 info_page.dat
-rw-r--r-- 1  16384 apr 10 16:18 output
$ cat output
$ hd output
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004000
My Crazyradio PA says it's "Rev. C", if that's any help.
Last edited by arashi on Thu Apr 13, 2017 3:26 pm, edited 1 time in total.



arnaud
Bitcraze
Posts: 2082
Joined: Tue Feb 06, 2007 12:36 pm

Re: SPI trouble

Post by arnaud » Tue Apr 11, 2017 8:14 am

Hi,

A lot of my try of reprogramming the crazyradio with SPI has resulted in reading it blank like you are seeing right now.

One of my latest attempt was with the raspberry pi and it worked fine, maybe you can try it: https://github.com/bitcraze/crazyradio- ... r_raspi.py

This program will flash a "goto bootloader" instruction at the begining of the flash. It could easily be modify to only read the begining of the flash instead.

arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

Re: SPI trouble

Post by arashi » Tue Apr 11, 2017 10:53 am

Well, it seems that the Raspberry Pi script I tested with is actually a fork of your script, or the other way around.

Anyway, the pin numbering is different between the two scripts. In the NRF_SPI_Flash.py script it says:

Code: Select all

# Name   Pin on raspi     Pin on Crazyradio
#-------------------------------------------
GND   =   6              # 9
RESET =   18             # 3
PROG  =   22             # 2
SCK   =   23             # 4
MOSI  =   19             # 6
MISO  =   21             # 8
CS    =   24             # 10
In your fix_bootloader_raspi.py script it says:

Code: Select all

# Name   Pin on raspi     Pin on Crazyradio
#-------------------------------------------
GND   =   6              # 9
RESET =   3              # 3
PROG  =   5              # 2
SCK   =   7              # 4
MOSI  =   8              # 6
MISO  =   10             # 8
CS    =   12             # 10
I suspect the scripts use the same pins on the Raspberry Pi, though I wonder if this difference might explain why I'm not having any luck with the
NRF_SPI_Flash.py script?

So far, I've been testing with a Raspberry Pi 2, but I may be able to find a Raspberry Pi 1 if you think that will make a difference. Also, my Raspbian installation is from yesterday so should be new enough.

arnaud
Bitcraze
Posts: 2082
Joined: Tue Feb 06, 2007 12:36 pm

Re: SPI trouble

Post by arnaud » Tue Apr 11, 2017 11:26 am

Yes this is a fork of my script (I wrote it from scrash), not very nice not to not credit the original author but good if my script is useful to others.

Anyway, I got that to work on a Raspberry pi 3, so my pinout should work on a raspi 2 as well.

arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

Re: SPI trouble

Post by arashi » Tue Apr 11, 2017 1:05 pm

OK, so going by the terminology at https://pinout.xyz/, are your Raspberry Pi pin numbers BCM or physical or something else? I assumed the pin numbers in the NRF_SPI_Flash.py script were physical, but with your script I'm not so sure.

arnaud
Bitcraze
Posts: 2082
Joined: Tue Feb 06, 2007 12:36 pm

Re: SPI trouble

Post by arnaud » Tue Apr 11, 2017 2:31 pm

Because of this line https://github.com/bitcraze/crazyradio- ... spi.py#L35 I use the physical/board numbering.

On a side note, thanks for the pinout.xyz link, it is a useful site!

arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

Re: SPI trouble

Post by arashi » Tue Apr 11, 2017 3:06 pm

arnaud wrote:Because of this line https://github.com/bitcraze/crazyradio- ... spi.py#L35 I use the physical/board numbering.
Excellent. Makes sense. Stay tuned as I hook up my Crazyradio PA to my Raspberry Pi and try your script...
arnaud wrote:On a side note, thanks for the pinout.xyz link, it is a useful site!
It is and you're most welcome. :-)

arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

Re: SPI trouble

Post by arashi » Tue Apr 11, 2017 3:40 pm

I'm guessing that it didn't work and that flash content should have been "02 78 00":

Code: Select all

root@raspberrypi:/usr/local/bin# ./fix_bootloader_raspi.py 
./fix_bootloader_raspi.py:63: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup([SCK, MOSI], GPIO.OUT, initial=GPIO.LOW)
./fix_bootloader_raspi.py:65: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(MISO, GPIO.IN)
Erasing page 0...
Writing 'JL 0x7800' instruction...
Flash content:
00
00
00
Fix written to flash. Disconnect the PROG wire, reconnect Crazyradio
and the bootloader should start!
Maybe I need to find that soldering iron again...

arnaud
Bitcraze
Posts: 2082
Joined: Tue Feb 06, 2007 12:36 pm

Re: SPI trouble

Post by arnaud » Tue Apr 11, 2017 4:22 pm

The warnings you get are worrying. Are you running another software that uses the gpio? Maybe one problem is that the nrf is never switched in spi flash mode: this requires a sequencing of the reset and prog pin and if the gpio are not working properly it will be a problem.

arashi
Beginner
Posts: 12
Joined: Sun Dec 14, 2014 4:14 pm

Re: SPI trouble

Post by arashi » Tue Apr 11, 2017 5:28 pm

I'm running a completely vanilla Raspbian that I don't use for anything besides flashing my Crazyradio PA. If the GPIOs are already in use when running your script it is due to something in the default Raspbian installation.

Anyway, if I run the script a second time, I don't get the warnings:

Code: Select all

root@raspberrypi:/usr/local/bin# ./fix_bootloader_raspi.py 
Erasing page 0...
Writing 'JL 0x7800' instruction...
Flash content:
00
00
00
Fix written to flash. Disconnect the PROG wire, reconnect Crazyradio
and the bootloader should start!

Post Reply