Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2525|回復: 1
打印 上一主題 下一主題

SPI 傳輸寫法問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2013-11-21 23:51:29 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位大大好,我想請問一個關於要將指令寫入SPCR的小問題。
起因為在Ardinuo官網看到這一篇"Interfacing a serial EEprom using SPI",
http://arduino.cc/en/Tutorial/SPIEEPROM

裡面的一段程式碼為:
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);


它的目的是將01010000寫入SPCR裡,
使用的寫法為
(1<<SPE)|(1<<MSTR)
我想請問:
1. 在程式的開頭SPCR、SPE、MSTR、SPSR、SPDR、clr....etc 皆沒有被定義,
  若照結果來推測,SPE與MSTR應該是6與4,
  我的說法對嗎? 若是的話這些數值是預先被定義在哪呢?


2. 如果我想在SPCR裡寫入上述的指令,
我可以直接將程式碼改為 : SPCR=B01010000嗎?


先感謝各位大大的回答!
2#
發表於 2013-11-23 02:47:41 | 只看該作者
回復 1# AdamQ

>>我想請問:
>>1. 在程式的開頭SPCR、SPE、MSTR、SPSR、SPDR、clr....etc 皆沒有被定義,
  >>若照結果來推測,SPE與MSTR應該是6與4,
  >>我的說法對嗎? 若是的話這些數值是預先被定義在哪呢?
An SPI library is now included in the Arduino software.

The Arudiuno will not have SPI enabled unless I load a sketch / library which sets the SPRC register and enables SPI, correct?  If I load a sketch which uses SPI will those changes remain when the Arduino reboots. Lets say I change sketch to "Blink", will the SPCR still be set to enabled?

If I enable SPI by making the appropriate changes to the registers. What would I need to clear all of these SPI settings?


>>2. 如果我想在SPCR裡寫入上述的指令,
>>我可以直接將程式碼改為 : SPCR=B01010000嗎?
    你可以試試看,行就行,不行就不行,反正程式碼怎麼規格寫,都是隨創作者高興作的,
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-30 15:22 , Processed in 0.166319 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表