Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

help getting SPI interface to work



Having managed to get the I2C interface on a Banana pi  running a recent 
current snapshot [talking to at least one device correctly] I decided to  try 

/dev/spi0 is defined which is a good start::

[     1.000003] sun4ispi0 at simplebus1: SPI
[     1.000003] sun4ispi0: interrupting on GIC irq 42
[     1.000003] spi0 at sun4ispi0: SPI bus

The board has the SPI mos1/miso/clk together with cs0 and cs1. 

Looking at spi(4) there is no mention of a way to control cs0/1 to select 
devices so I guess this is down to using gpio commands to pull the appropriate 
pin low. As a temporary measure I tied the cs on the MAX31865 to 0v. This 
might not work if there are timing issues...
....
#include <dev/spi/spi_io.h>
int main()
{
    int spifd ;
    spi_ioctl_transfer_t spit ;
    uint8_t command, result ;
    
    if ((spifd = open("/dev/spi0", O_RDWR)) == -1) {
        printf("failed to open /dev/spi0 code=%d\n",errno) ;
        exit(1) ;
    }

    command = 0  ;  /*we are not sending anything */
    spit.sit_addr =  0x00 ;
    spit.sit_send = &command ;
    spit.sit_sendlen = 0 ;
    spit.sit_recv = &result ;
    spit.sit_recvlen = 1;
    if ((ioctl(spifd, SPI_IOCTL_TRANSFER, &spit)) !=0) {
        printf("control reg read failed %d\n",errno) ;
        exit(1) ;
    }

    printf("control reg = %X\n", result) ;
    close(spifd) ;
}

First stab at reading the control register (addr 0x00) fails with errno 22. 
kdump isn't helpful:

 CALL  ioctl(3,SPI_IOCTL_TRANSFER,0x7ff94658)
  1104   1104 pt100    GIO   fd 3 wrote 20 bytes
       "\0\0\0\0WF\M-y\^?\0\0\0\0VF\M-y\^?\^A\0\0\0"
  1104   1104 pt100    RET   ioctl -1 errno 22 Invalid argument

The device just needs the register address sending and should return a single 
byte with the contents. I assumed that the default spi clock/mode etc. would 
be OK but I am a bit clueless at present. Anyone got the spi interface working 
on an SOC board or similar?

 (I have a raspberry pi B/orange pi's as well as the banana pi)

Cheers,
Dave


Home | Main Index | Thread Index | Old Index