spi linux驱动

ywh_hlp 2009-11-28 08:53:52
在/sys/bus/spi/drivers目录下,能看到spidev,在/sys/bus/spi/devices目录下,能看到spi1.0(我使用的是spi1在2440芯片下),自己编写了一个测试文件
#include <stdio.h> // printf
#include <fcntl.h> // open
#include <stdlib.h> // exit
#include <unistd.h>
#include <sys/ioctl.h> // ioctl

//*************************Test*********************************
int main(int argc, char *argv[])
{
int fd;
char str = '0';

fd = open("/dev/spidev1.0",O_RDWR);

if(fd<0)
printf("can not open\n");
while(1)
{
write(fd,&str,1);
printf("write successful\n");
}
close(fd);
return 0;

}

我配置SPI1为poll模式时,发现printf("write successful\n");并无执行,就是卡死在write函数上,我并无利用spidev对外连接任何引脚,只是直接把2440的spi1引脚导出来而已,但是打开spidev是成功的。运行上述代码后利用示波器测试了SPICLK1引脚,本身2440设置为主模式,时钟为1M,但是示波器上还是无时钟输出,SPIMOSI1一直为高电平,SPIMOSO1一直为低电平?何解?谢谢了
...全文
383 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
confidence321 2010-12-31
  • 打赏
  • 举报
回复
寄存器需要加volatile关键字,加了么?
ywh_hlp 2009-12-12
  • 打赏
  • 举报
回复
这几天看了SPI内核源码,总算分析了,时钟方面的设置
#define SPCON_DEFAULT (S3C2410_SPCON_MSTR | S3C2410_SPCON_SMOD_POLL| S3C2410_SPCON_ENSCK | S3C2410_SPCON_CPHA_FMTB)
#define SPPIN_DEFAULT (S3C2410_SPPIN_KEEP)
写入clkcon、spcon、sppin及波特率都是写入成功的,因为之后我有读出寄存器里头的值,但是老是不出时钟信号,很郁闷很郁闷!

ywh_hlp 2009-12-02
  • 打赏
  • 举报
回复
thanks! 继续分析内核源码,希望能找出问题所在!
xhy_851221 2009-12-01
  • 打赏
  • 举报
回复
bangding

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧