Linux下SPI測試程式

2021-06-29 06:27:25 字數 2284 閱讀 6117

/*

* 說明:spi通訊實現

* 方式一: 同時傳送與接收實現函式: spi_transfer()

* 方式二:傳送與接收分開來實現

* spi_write() 只傳送

* spi_read() 只接收

* 兩種方式不同之處:方式一,在發的過程中也在接收,第二種方式,收與發單獨進行

* created on: 2013-5-28

* author: lzy

*/#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "debug.h"

#define spi_debug 0

static const char *device = "/dev/spidev0.0";

static uint8_t mode = 0; /* spi通訊使用全雙工,設定cpol=0,cpha=0。 */

static uint8_t bits = 8; /* 8bits讀寫,msb first。*/

static uint32_t speed = 12 * 1000 * 1000;/* 設定12m傳輸速度 */

static uint16_t delay = 0;

static int g_spi_fd = 0;

static void pabort(const char *s)

/*** 功 能:同步資料傳輸

* 入口引數 :

* txbuf -> 傳送資料首位址

* len -> 交換資料的長度

* 出口引數:

* rxbuf -> 接收資料緩衝區

* 返回值:0 成功

* 開發人員:lzy 2013-5-22

*/int spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)

;ret = ioctl(fd, spi_ioc_message(1), &tr);

if (ret < 1)

pr_err("can't send spi message");

else

printf("n");

pr_debug("spi receive [len:%d]:", len);

for (i = 0; i < len; i++)

printf("n");

#endif

}return ret;

}/**

* 功 能:傳送資料

* 入口引數 :

* txbuf -> 傳送資料首位址

*len -> 傳送與長度

*返回值:0 成功

* 開發人員:lzy 2013-5-22

*/int spi_write(uint8_t *txbuf, int len)

printf("n");

#endif

}return ret;

}/**

* 功 能:接收資料

* 出口引數:

* rxbuf -> 接收資料緩衝區

* rtn -> 接收到的長度

* 返回值:>=0 成功

* 開發人員:lzy 2013-5-22

*/int spi_read(uint8_t *rxbuf, int len)

printf("n");

#endif

}return ret;

}/**

* 功 能:開啟裝置 並初始化裝置

* 入口引數 :

* 出口引數:

* 返回值:0 表示已開啟 0xf1 表示spi已開啟 其它出錯

* 開發人員:lzy 2013-5-22

*/int spi_open(void)

/*** 功 能:關閉spi模組

*/int spi_close(void)

/*** 功 能:自發自收測試程式

* 接收到的資料與傳送的資料如果不一樣 ,則失敗

* 說明:

* 在硬體上需要把輸入與輸出引腳短跑

* 開發人員:lzy 2013-5-22

*/int spi_lookbacktest(void)

else

pr_debug("spi - lookback mode okn");

}return ret;

}

linux下spi驅動分析

核心版本 linux 2.6.29 主要的幾個結構platform device platform driver s3c24xx spi spi master spi bitbang spi device spi driver spidev data s3c spi info第一步 註冊platfo...

linux下串列埠程式測試

linux平台下的串列埠程式網上比比皆是,這裡是自己參考資料寫的。測試函式如下 另外那個標頭檔案是我經常使用的,現在還在不斷更新 修改中,也放到這裡吧 測試如下 虛擬機器fc9,使用物理串列埠 可以在vm中設定的 在tty1上執行該程式,在tty2上執行minicom,短接串列埠線2 3腳,可以看到...

Linux下SPI驅動分析 2

接上乙個繼續看spi.c。名詞解釋of openfirmware 呼叫層次spi match device of driver match device of match device of match node 用於驅動程式檢查platform device是否在其支援列表裡 80static i...