完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我花了好几个小时让我的SPI1工作。我用这个与一个移位寄存器接口,所以我现在不关心SDI和SS。我不能在我的示波器上获得SCLK或SDO信号。下面是我的代码。我知道我错过了一些小东西,但是为了我的生活,我找不到它。我真的很感激你的帮助!
以上来自于百度翻译 以下为原文 I have spent hours trying to get my SPI1 to work. I am using this to interface with a shift register and so I am unconcerned with SDI and SS for now. I simply cannot get an SCLK or SDO signal on my oscilloscope. Below is my code. I know Im missing something small but for the life of me, I cant find it. #include #define _XTAL_FREQ 64000000 // CONFIG1L #pragma config FEXTOSC = HS // External Oscillator mode Selection bits(HS (crystal oscillator) above 8 MHz; PFM set to high power) #pragma config RSTOSC = HFINTOSC_64MHZ // Power-up default value for COSC bits (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1) #pragma config WDTE = OFF // WDT operating mode (WDT Disabled) void main(void) { TRISC = 0x00; //Set PORTC as output SSP1CON1bits.SSPEN = 1; //Enables SPI1 SSP1CON1bits.SSPM = 0010; //Sets SCLK to FOSC/64 RC2PPS = 0x00; //Sets RC2 as the SDO pin //RC3 is SCLK1 by default while(1){ SSP1BUF = 0x05; //Test output __delay_us(200); SSP1BUF = 0x08; __delay_us(200); } } I really appreciate your help! |
|
相关推荐
7个回答
|
|
我在数据表中读取寄存器17-2的方式,您需要将RC2PPS设置为0x10以输出SDO1(您设置为0x00),我将明确地将RC3设置为SCLK1。(RC3PPS= 0x0F),可能应该将这些引脚设置为ANSELC寄存器中的数字,虽然我不认为这会引起您的问题。
以上来自于百度翻译 以下为原文 The way I read register 17-2 in the datasheet, you need to set RC2PPS to 0x10 to output SDO1 (you set to 0x00) Also, I would explicitly set RC3 to SCLK1. (RC3PPS = 0x0f) And probably should set these pins to digital in the ANSELC register, although I don't think this is causing your problem. |
|
|
|
除了M朗宁指出的差异之外,我看到了:嗯……问候,戴夫。
以上来自于百度翻译 以下为原文 In addition to discrepancies pointed out by mbrowning, I see this: Ummm... //Octal 0010 is decimal 8, binary 0b1000 so this // is not a valid SPI mode! SSP1CON1bits.SSPM = 0010; // Integer literals starting with 0 are octal (!) // On the other hand... SSP1CON1bits.SSPM = 0b0010; //Sets SCLK to FOSC/64 Regards, Dave |
|
|
|
|
|
|
|
非常感谢你们的帮助。现在效果不错!麦克布朗,我又从微芯片上下载了数据表,发现你在说什么。原来我一年前下载的那个已经过时了。如果我是从第三方网站或DaveKW7X得到的,这是一个很好的捕捉。我会留意前进的方向,再次感谢,保重!
以上来自于百度翻译 以下为原文 Thank you so much for your help guys. It works fine now! mbrowning, I downloaded the Datasheet from Microchip again and found what you were saying. Turns out the one I downloaded a year ago was obsolete. Cant remember if I got it from a third party website or something. davekw7x, that's an excellent catch. Ill keep an eye out for that moving forward. Thanks again and take care! |
|
|
|
非常感谢你们的帮助。现在效果不错!麦克布朗,我又从微芯片上下载了数据表,发现你在说什么。原来我一年前下载的那个已经过时了。如果我是从第三方网站或DaveKW7X得到的,这是一个很好的捕捉。我会留意前进的方向,再次感谢,保重!
以上来自于百度翻译 以下为原文 Thank you so much for your help guys. It works fine now! mbrowning, I downloaded the Datasheet from Microchip again and found what you were saying. Turns out the one I downloaded a year ago was obsolete. Cant remember if I got it from a third party website or something. davekw7x, that's an excellent catch. Ill keep an eye out for that moving forward. Thanks again and take care! |
|
|
|
|
|
|
|
因此,教训应该是明确的:每当你开始一个新项目(或重访一个旧项目)总是,总是,总是拉最新的数据表和勘误表。
以上来自于百度翻译 以下为原文 So the lesson should be clear: whenever you start a new project (or revisit an old one) always, always, always pull the latest Data Sheet and Errata. |
|
|
|
只有小组成员才能发言,加入小组>>
5223 浏览 9 评论
2024 浏览 8 评论
1949 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3198 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2252 浏览 5 评论
769浏览 1评论
655浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
583浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
667浏览 0评论
569浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-16 21:01 , Processed in 1.362091 second(s), Total 90, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号