Spi begin failed with Rpi 3B+

440 views
Skip to first unread message

Chhour Vongchivorn

unread,
Jun 8, 2018, 11:44:35 AM6/8/18
to bcm2835
Dear bcm2835

Before I used Rpi 3 B work with mcp3008 it works very well. but now I change to Rpi B+ but it fails with function bcm2835_spi_begin() . could you have any idea? 
thank you.

Christian Kevin Alvarado Rimas

unread,
Jun 9, 2018, 7:22:27 PM6/9/18
to bcm2835
Did you enable SPI interface in the raspi-config? if you didnt, follow this (for RPi 2,  i think it is pretty much the same for RPi B+)
$ sudo raspi-config
choose 
Interfacing Options
then
P4 SPI
that is it.
if the issue continues. Are you using Rasbian Stretch or Jessie or something Older? cause far far away, at the beginning of the times, in order to enable the SPI, you had to edit somefiles

Regards :¬D

July Jim

unread,
Jun 9, 2018, 10:02:39 PM6/9/18
to bcm...@googlegroups.com
I am "porting" this "library" into C++,
During doing so I was wondering if setting GPIO to SPI pins ALT0 mode is really necessary if SPI is also "configured" in RPi.
So what does "raspi_config" actually do for SPI?
bcm2835_spi_begin as fas as I can tell only knows RPi2 and RPI1 , it has #define switch in the code to do so, no "B"  option.  Rpi2 is 2 and "higher".



--
You received this message because you are subscribed to the Google Groups "bcm2835" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+unsubscribe@googlegroups.com.
To post to this group, send email to bcm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bcm2835/e9ddae9b-5233-445f-81e6-92ecdd223472%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arjan van Vught

unread,
Jun 10, 2018, 4:36:54 AM6/10/18
to bcm...@googlegroups.com


Op 10 jun. 2018, om 01:22 heeft Christian Kevin Alvarado Rimas <cke...@gmail.com> het volgende geschreven:

Did you enable SPI interface in the raspi-config?

For al my Rasberry Pi models with all versions of Raspbian, I have always disabled I2C and SPI. This in order to prevent that the kernel module is interfering with the library.

- Arjan

Arjan van Vught

unread,
Jun 10, 2018, 4:48:08 AM6/10/18
to bcm...@googlegroups.com


Op 10 jun. 2018, om 04:02 heeft July Jim <tccio...@gmail.com> het volgende geschreven:

During doing so I was wondering if setting GPIO to SPI pins ALT0 mode is really necessary if SPI is also "configured" in RPi. 
So what does "raspi_config" actually do for SPI?

It always best not to rely on what is being provided by the environment (in this case Raspbian). Hence it is best to set the GPIO pins to the alternate function in our code. Hence we have full awareness and control of our environment.

The raspi-config can be used to activate the SPI/I2C kernel modules. Or for this library , enable the device tree.

- Arjan

Arjan van Vught

unread,
Jun 10, 2018, 5:10:34 AM6/10/18
to bcm...@googlegroups.com
Op 10 jun. 2018, om 04:02 heeft July Jim <tccio...@gmail.com> het volgende geschreven:

I am "porting" this "library" into C++,

We can use the same in C++. It is no difference. I call all in the ‘init’ functions in a the constructor. For example -> https://github.com/vanvught/rpidmx512/blob/master/lib-l6470/src/slushboard.cpp#L73

- Arjan

Chhour Vongchivorn

unread,
Jun 10, 2018, 10:37:35 AM6/10/18
to bcm2835
in my case, I used the Rasbian stretch. follow your instructions I already open Spi configure. but I still the same problem. 
Screen Shot 2018-06-10 at 23.36.22.png
Screen Shot 2018-06-10 at 23.36.43.png

Arjan van Vught

unread,
Jun 10, 2018, 11:36:29 AM6/10/18
to bcm...@googlegroups.com
Op 10-6-2018 om 16:37 schreef Chhour Vongchivorn:
in my case, I used the Rasbian stretch. follow your instructions I already open Spi configure. but I still the same problem. 

bcm2835_spi_begin returns 0 when  bcm2835_spi0 == MAP_FAILED  --> bcm2835_spi0 is set in bcm2835_init when bcm2835_init returns 1 (OK).

if (bcm2835_spi1 == MAP_FAILED)
      return 0; /* bcm2835_init() failed, or not root */

So we can expect that bcm2835_spi_begin fails when bcm2835_init failed before or is not called with root.

Please be aware that you must call bcm2835_init in each thread where you are using the library functions.

- Arjan

http://www.raspberrypi-dmx.org/

Chhour Vongchivorn

unread,
Jun 11, 2018, 3:54:10 AM6/11/18
to bcm2835
Thank everyone. Finally, I can solve it. 
have a good day !!!

Arjan van Vught

unread,
Jun 11, 2018, 3:55:37 AM6/11/18
to bcm...@googlegroups.com


Op 11 jun. 2018, om 09:54 heeft Chhour Vongchivorn <chho...@gmail.com> het volgende geschreven:

 Finally, I can solve it. 
Please share the solution. Thanks.
Reply all
Reply to author
Forward
0 new messages