匿名
尚未登入
登入
flip the world
搜尋
檢視Application - LPC1768, SPI communication的原始碼
出自flip the world
命名空間
頁面
討論
更多
更多
頁面操作
閱讀
檢視原始碼
歷史
←
Application - LPC1768, SPI communication
您沒有權限執行編輯此頁面,由於以下原因:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
[[File:PRi_SPI_LPC1768.jpg|border|350px|SPI communication between RPi and LPC1768]] == Hardware == [[File:GPIOs.png|thumb|RPi GPIO]] [[File:LPC1768_pinout.png|thumb|NXP LPC1768 pinout]] [[File:spi_timing.png|thumb|SPI timing]] <pre width=100> RPi2 NXP LPC1768 MOSI(GPIO10) -- MOSI(p5) MISO(GPIO09) -- MISO(p6) SCLK(GPIO11) -- SCLK(p7) CE0(GPIO08) -- (p8) </pre> == Software == * RPi using libbcm2835 ** gcc -o spi spi.c -lbcm2835 ** unknown why BCM2835_SPI_MODE1 is more stable?? <pre> #include <bcm2835.h> #include <stdio.h> int main(int argc, char **argv) { if (!bcm2835_init()) return 1; bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE1); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default // Send a byte to the slave and simultaneously read a byte back from the slave // If you tie MISO to MOSI, you should read back what was sent uint8_t data = bcm2835_spi_transfer(0x12); printf("Read from SPI: %02X\n", data); bcm2835_spi_end(); bcm2835_close(); return 0; } </pre> *NXP LPC1768 <pre> #include "mbed.h" SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel Serial pc(USBTX, USBRX); int main() { device.reply(0x00); // Prime SPI with first reply while(1) { if(device.receive()) { int v = device.read(); // Read byte from master device.reply(v); // Make this the next reply pc.printf("reply: %02x\n", v); } } } </pre> == Reference == * [https://developer.mbed.org/questions/1331/How-to-Delay-SPI-Slave-to-Master-Respons/, How to Delay SPI Slave to Master Response?] * [http://www.mathworks.com/help/supportpkg/raspberrypiio/ug/use-the-spi-interface-on-the-raspberry-pi-hardware.html, Use the Raspberry Pi SPI Interface to Connect to a Device] * [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus, wiki, Serial Peripheral Interface Bus] * [http://www.airspayce.com/mikem/bcm2835/group__spi.html#gad623657d9513faa89d22ae1dc87eec38, libbcm2835] * [http://www.petervis.com/Raspberry_PI/SPI_Seria, Raspberry Pi SPI]
返回到「
Application - LPC1768, SPI communication
」。
導覽
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
wiki工具
wiki工具
特殊頁面
頁面工具
頁面工具
使用者頁面工具
更多
連結至此的頁面
相關變更
頁面資訊
頁面日誌