Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

WiringPi SPI without Chip Select/Enable?

Status
Not open for further replies.

emaq

Member level 4
Member level 4
Joined
Sep 17, 2015
Messages
78
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Activity points
2,001
I am wondering how the WiringPi SPI works without using the chip select/enable in the following code.

Code:
int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
{
  struct spi_ioc_transfer spi ;

  channel &= 1 ;

  memset (&spi, 0, sizeof (spi)) ;

  spi.tx_buf        = (unsigned long)data ;
  spi.rx_buf        = (unsigned long)data ;
  spi.len           = len ;
  spi.delay_usecs   = spiDelay ;
  spi.speed_hz      = spiSpeeds [channel] ;
  spi.bits_per_word = spiBPW ;

  return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &spi) ;
}

It seems if I send two consecutive bytes (16-bit data) with WiringPi it will be transmitted as synchronized with clock and the corresponding 16-bit data will be received. But in that case do I have to pull down the CE pin of the device connected to raspberry pi SPI (spidev0.0) by manually connecting it to the ground permanently?

A similar following SPI code does not use chip select/enable.

Code:
int
SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len)
{
    if ((send == nullptr) && (recv == nullptr)) {
        return -EINVAL;
    }

    // set write mode of SPI
    int result = ::ioctl(_fd, SPI_IOC_WR_MODE, &_mode);

    if (result == -1) {
        PX4_ERR("can’t set spi mode");
        return PX4_ERROR;
    }

    spi_ioc_transfer spi_transfer{};

    spi_transfer.tx_buf = (uint64_t)send;
    spi_transfer.rx_buf = (uint64_t)recv;
    spi_transfer.len = len;
    spi_transfer.speed_hz = _frequency;
    spi_transfer.bits_per_word = 8;

    result = ::ioctl(_fd, SPI_IOC_MESSAGE(1), &spi_transfer);

    if (result != (int)len) {
        PX4_ERR("write failed. Reported %d bytes written (%s)", result, strerror(errno));
        return PX4_ERROR;
    }

    return PX4_OK;
}
Can someone please explain how this works?
 
Last edited:

In the above question, I mean how the WiringPi SPI works without using
Code:
spi.cs_change = true;
 

Not using the 'chip select' (or similarly named signals) is a bad idea as far as I am concerned.
It will work but if there is a single glitch on the clock signal then every exchange is out of sync after that.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top