Raspberry PI Compute Module - SPI1

1k views Asked by At

I'm using Raspberry PI Compute Module, and i would like to use SPI1.

But there is a struggle.

Are there any drivers or do you have some idea how to use that? Because there are only drivers for SPI0 which is the only SPI accessible in Raspberry PI B+.

Thank you.

1

There are 1 answers

0
David Bensoussan On

I also didn't find any kernel suitable. But yes you can using this library which is well writen : http://abyz.co.uk/rpi/pigpio/index.html

To use the second SPI, use the example program in x_pigpio.c void tc(). Change the parameters in

h = spiOpen(1, 50000, 0);

In gpio.h, you can check what to put in the 3 parameters :

int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags);

spiChan: 0-1 (0-2 for A+/B+/Pi2 auxiliary device) baud: 32K-125M (values above 30M are unlikely to work) and spiFlags :

Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. spiFlags consists of the least significant 22 bits.

. . 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m . .

mm defines the SPI mode.

So now that you understood, you take the example, change the parameters or spiOpen like that and it's working.

spiChan = 1
spiFlags = PI_SPI_FLAGS_GET_AUX_SPI(1)

The best way to confirm it's working is to make a loop between your MISO and MOSI pins and checking with a logic analyzer your message is readable.