• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






Re: SPI的SCK跑不出CLOCK?
#5
版主
版主


查看用戶資訊
老問題,請注意一下 SPI 有四種 Mode,你必須確定你的加速規是在那種模式下工作的,30F4011 這裡也要跟著配合,還是相同的話請用示波器再次確認 SCK 的 Idle 電位?

發表於: 2010/2/23 10:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI的SCK跑不出CLOCK?
#4
高級會員
高級會員


查看用戶資訊
void Init_SPI(void)
{
TRISFbits.TRISF6=0;//SCLK輸出
TRISFbits.TRISF3=0;//SDO輸出
TRISFbits.TRISF2=1;//SDI輸入

MODE_SPI_CS = 1 ;
SPI_CS = 1 ;
DIR_SPI_CS = 0 ;

SPI1CON = 0x207c ; SPI1STAT = 0xa000 ;

ConfigIntSPI1(SPI_INT_DIS & SPI_INT_PRI_4) ;

}
//寫/讀動作程式//
unsigned char SPI_ByteWrite(unsigned char SPI_DATA )
{

SPI1BUF = SPI_DATA ;
while ( ! IFS0bits.SPI1IF ) ;
IFS0bits.SPI1IF = 0 ;

return (unsigned char) SPI1BUF ;

}

//WRITE//
int SPI_ADXL_WRITE(unsigned int SPI_MB,unsigned int SPI_Addr , unsigned char SPI_Data )
{

SPI_CS = 0 ;

SPI_ByteWrite ( SPI_SE_WRITE ) ; // Send Write Command
SPI_ByteWrite (SPI_MB);
SPI_ByteWrite ( (SPI_Addr >> 8) & 0x00ff );
SPI_ByteWrite ( SPI_Addr & 0x00ff ) ;
SPI_ByteWrite ( SPI_Data ) ;

SPI_CS = 1 ;

return 1 ; // Indicate Success

}

unsigned char SPI_ByteREAD( unsigned int SPI_MB,unsigned int SPI_Addr)
{

unsigned char DATA_Buffer;
SPI_CS=0;
SPI_ByteWrite ( SPI_SE_READ ) ; // Send Write Command
SPI_ByteWrite (SPI_MB);
SPI_ByteWrite ( (SPI_Addr >> 8) & 0x00ff );
SPI_ByteWrite ( SPI_Addr & 0x00ff ) ;
DATA_Buffer=ReadSPI1();
SPI_CS=1;
SPI_Delay();
return (unsigned char)DATA_Buffer;
}
//主程式//
int main()
{
Init_SPI();
SPI_ADXL_WRITE(0x00,0x1D,0x5A);
iData=SPI_ByteREAD(0x00,0xE5);
iData=SPI_ByteREAD(0x00,0x1D);

}

以上是我從MICROCHIP的範例
所改寫出來的部份程式

可是我放到示波器上面看
波形很奇怪

因為我是利用DSPIC30F4011使用SPI
去取得某塊晶片(ADXL345數位式加速規)所傳出的資料

但是就是無法取得那塊晶片所傳出的訊號
SCLK目前有CLOCK了
SDO的訊號總比雜訊慢但也有訊號
問題就出在 晶片所回送的SDI腳位 沒訊號

不知道哪個地方出了錯

感謝MICROCHIP所提供的範例 謝謝

發表於: 2010/2/22 23:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI的SCK跑不出CLOCK?
#3
新會員
新會員


查看用戶資訊
您程式中有SPI傳送DATA的部份嗎?
應只有在DATA放置SPI buffer後,SPI傳輸時SCK才有CLOCK產生~~

發表於: 2010/2/22 13:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI的SCK跑不出CLOCK?
#2
版主
版主


查看用戶資訊
你用那一顆 16-bit 的 PIC? 是不是有 PPS 的功能元件?
還是他有兩組 SPI 的介面元件?

發表於: 2010/2/22 9:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


SPI的SCK跑不出CLOCK?
#1
高級會員
高級會員


查看用戶資訊
各位先進你們好

小弟在測試SPI的每個接腳

發現SCLK這個接腳沒有訊號 都維持高準位(5V)

後來我把在這下載SPI的範例程式

把主要程式忽略

只保留SPI那部份

也就是只打開SPI

也跑不出CLOCK

不知道問題出現在哪?

發表於: 2010/2/20 18:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------