spi是串行全双工同步通信,支持多从机模式,没有应答机制,可靠性方面存在劣势;
采用边沿采样,根据时钟极性和时钟相位,有四种数据传输方式(由时钟变化(极性,相位)决定;
因为是全双工,数据收发可以同时进行
每次传输的位数为8位或16位为单位,传输单位数不受限制

如图,奇数边沿采样是在第一个时钟周期采样(读写数据
偶数边沿采样,是在第二个时钟周期采样
主板线路连接了两个芯片,一个芯片用于控制数码管显示的数字,另一个用于控制哪个数码管显示。每个数码管有8位二进制表示(a,b,c,d....),4个数码管(G1,G2,G3,G4)用4位二进制数表示
引用spi节点,写在根节点外;参考st的spi设备树,用grep "spi" * -nR 查找字符所在的文件
4根线,statu=okay;传输速率设置10k

编译,拷贝到开发板 ~/tftpboot

#include
#include
#include
int m74hc595_probe(struct spi_device *spi)
{char buf[]={0xf,0x6d};//向spi总线设备写入spi_write(spi,buf,sizeof(buf));return 0;
}
int m74hc595_remove(struct spi_device *spi)
{char buf[]={0xf,0};spi_write(spi,buf,sizeof(buf)); //写0,关闭数码管显示return 0;
}
struct of_device_id of_table[]={{.compatible="hqyj,m74hc595"},{},
};
//热插拔
MODULE_DEVICE_TABLE(of,of_table);
//定义spi对象并初始化
struct spi_driver m74hc595={.probe=m74hc595_probe,.remove=m74hc595_remove,.driver={.name="m74hc595",.of_match_table=of_table,},
};
module_spi_driver(m74hc595);
MODULE_LICENSE("GPL");
