|
怎么在FireFrame编写spi应用程序
发表于 2016-1-31 15:36:38
浏览:8671
|
回复:8
打印
只看该作者
[复制链接]
楼主
想把RK3128的SPI作为master去读取从设备的数据。 我编写了下面一段代码,但是在spi的cs,clk,mosi和miso任何一个引脚上都没有检测到电平变化!
所用的引脚为
,7,8,9,10四个引脚。
有/dev/spi_misc_test设备存在!
代码如下
int
main(int argc, char **argv) {
int fd, ret;
char filename[] = "/dev/spi_misc_test";
uint32_t SPEED = 0;
uint8_t bits_per_word = 0, mode = 0, lsb = 0;
uint8_t command[2] = {0};
uint8_t recv [2] = {0};
spi_pin_mux();
int status;
fd = open(filename, O_RDWR);
if (fd < 0) {
printf("%s open failed!\n", filename);
}
//set settings
SPEED = 400000;
lsb = 0;
bits_per_word = DEFAULT_BITS_PER_WORD;//16;
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &SPEED);
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits_per_word);
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb);
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
msg.tx_buf = (unsigned long)txbuf;
// is it need to set rx_buf ?
msg.len = len;
msg.speed_hz = speed_hz;
msg.delay_usecs = delay_usecs;
msg.bits_per_word = bits_per_word;
msg.cs_change = (uint8_t)cs_change;
while(1)
{
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &msg);
}
}
请问,这段代码在RK3128上不适用么?
[img]file:///C:\Users\tt\AppData\Roaming\Tencent\Users\78477602\QQ\WinTemp\RichOle\AYA2[QEA]K3M}SU(]B`5%NA.png[/img]
|
|