树莓派spi接口c语言支持库,树莓派使用16位SPI模式及静态库编译连接

int wiringPiSPISetupMode (int channel, int speed, int mode)

{

int fd ;

mode    &= 3 ;// Mode is 0, 1, 2 or 3

channel &= 1 ;// Channel is 0 or 1

if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) 

return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;

spiSpeeds [channel] = speed ;

spiFds    [channel] = fd ;

// Set SPI parameters.

if (ioctl (fd, SPI_IOC_WR_MODE, &mode)            

return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;

if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) 

return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;

if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed)   

return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;

return fd ;

}How to install wiringPi

=======================

The easiest way is to use the supplied 'build' script:

./build

that should do a complete install or upgrade of wiringPi for you.

That will install a dynamic library.

cd wiringPi

make static

sudo make install-static

To un-install wiringPi:

./build uninstall

静态库的连接用法的确是 gcc -L libpath -llibname

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值