Hardware Reference
In-Depth Information
Bits per Word
The SPI driver also needs to know how many bits per I/O word are to be transmitted.
While the driver will likely default to 8 bits, it is best not to depend on that. This can be
configured with the following ioctl(2) call:
uint8_t bits = 8;
int rc;
rc = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD,&bits);
if ( rc < 0 ) {
perror ("Can't set bits per SPI word.");
Note
the SpI driver in the raspbian wheezy release supports only 8-bit transfers.
The currently configured value can be fetched with ioctl(2) as follows:
uint8_t bits;
int rc;
rc = ioctl(fd,SPI_IOC_RD_BITS_PER_WORD,&bits);
if ( rc == −1 ) {
perror("Can't get bits per SPI word.");
When the number of bits is not an even multiple of eight, the bits are assumed to be
right-justified. For example, if the word length is set to 4 bits, the least significant 4 bits are
transmitted. The higher-order bits are ignored.
Likewise, when receiving data, the least significant bits contain the data. All of this is
academic on the Pi, however, since the driver supports only byte-wide transfers.
Clock Rate
To configure the data transmission rate, you can set the clock rate with ioctl(2) as follows:
uint32_t speed = 500000; /
Hz
/
int rc;
rc = ioctl(fd,SPI_IOC_WR_MAX_SPEED_HZ,&speed);
if ( rc < 0 ) {
perror("Can't configure SPI clock rate.");
 
 
Search WWH ::




Custom Search