Mini2440 NRF24L01无线模块驱动
nrf24l01_release(struct inode *node, struct file *file)
{ free_irq(IRQ_EINT9,NULL);
open_count–;
printk(DEVICE_NAME ” released !n”);
return 0;
}
static struct file_operations nrf24l01_fops = {
.owner = THIS_MODULE,
.open = nrf24l01_open,
.write = nrf24l01_write,
.poll = nrf24l01_poll,
.read = nrf24l01_read,
.release = nrf24l01_release,
};
static struct miscdevice nrf24l01_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &nrf24l01_fops,
};
static int __init nrf24l01_init(void)
{ int ret;
printk(“Initial driver for NRF24L01.n”);
ret = misc_register(&nrf24l01_dev);
mdelay(10);
if (ret < 0) {
printk(DEVICE_NAME ” can’t register major numbern”);
return ret;
} else {
printk(DEVICE_NAME ” register successn”);
return 0;
}
}
static void __exit nrf24l01_exit(void)
{ misc_deregister(&nrf24l01_dev);
printk(“NRF24L01 unregister success n”);
}
module_init(nrf24l01_init);
module_exit(nrf24l01_exit);
MODULE_AUTHOR(“Issac”);
MODULE_DESCRIPTION(“NRF24L01 Driver”);
MODULE_LICENSE(“GPL”);备注:不同管脚的定义可以自行修改。
我添加了poll方法 和接收中断的处理
由于MSP的程序没有调好,这个驱动还没有进行测试。在内核中部署驱动:
将nrf24l01.c文件到源码下driver/misc/ 目录下
修改该目录下的Kconfig文件
在合适位置添加
config NRF24L01tristate "NRF24L01 Single Chip 2.4 GHz Radio Transceiver"helpDriver for NRF24L01
修改Makefile添加
obj-$(CONFIG_NRF24L01) += nrf24l01.o然后make menuconfig
选上NRF24L01 驱动即可
测试程序:仅测试了发送
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
unsigned char TxBuf[32] = {
0x01, 0x02, 0x03, 0x4, 0x05, 0x06, 0x07, 0x08,
0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24,
0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32,
};
int main(void)
{
int fd = -1;
int ret;
int count = 1;
fd = open(“/dev/NRF24L01”, O_RDWR);
if(fd < 0)
{
perror(“Can’t open /dev/nrf24l01 n”);
exit(1);
}
printf(“open /dev/nrf24l01 success n”);
while(count <= 5)
{
ret = write(fd, TxBuf , sizeof(TxBuf));
char *mesg = strerror(errno);
printf(“Sending %d time %d n”, count,ret);
printf(“Errno:%dn,Mesg:%sn”,errno,mesg);
usleep(100*1000);
count++;
}
close(fd);
}
Mini2440NRF24L01无线模块驱 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)