完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
Heloi正试图做一个PIC24到PIC24 SPI,我试图配置一个循环中的等待,直到字符到达SPI端口,然后将它们复制到一个数组中,然后信号主从完成,然后师父从Savavo中读取字符,我还没有成功,这是我的代码。将使用PX24HJ32表示感谢,包括“XC.H”定义CKKYPOLLACtiVEVION 0x010000定义SpxCKEYON 0x0100y定义S0aveEnable在0x080y上定义SpxMyDE8x在0xOMW/*通信是字节宽*/*定义MaskEnabeLayOff0xON/*从属模式*/*定义SLaveYeReal-LATB2Offic配置LaveeRead(){TysBi2=0;πPCFG4=1;//CN6PUE=1;} LATB2=1;}空隙构型SPI1(空隙){SPK1CONL1=CLKY-POLYActhVIVE高/ /普里亚PRECALE 4:1秒预刻度1:1的CLK POL活性高自旋SkaveEnabLeLonπMyLyMeDe8Li;P5Y-RP6R=7;//配置串行数据到RP6αSCK1R=7;/ /串行时钟从主机到RP7αSS1R=3;/ /从选择到RP3 CONTIONSLAVAVE Read();SLaveYeAdvay= 0;int SpIIF=0;(1);(b=0;b & lt;3255;b++);//y-delaysMs(1000);{LaTb15=0;}易失int u16i索引;空隙i ISRπSPI1中断(空隙){//字符到达,在缓冲区SZY1[U16Objult]=SP中的位置。标志} int main(空隙){CONTIONSPIL1();而(1){{ for(j=0;j<22;j++)sZY1[j]=SPI1BUF;}(j<22);(j(gt;22){doHealBead)()(j=0;j& lt;3255;j++);for(l=);(j=0;j& lt;22;j++);{SPI1BUF=SZY1[22-J];} L I1BUF;U16B索引+;πSPI1IF=0;/ /清除中断ATB2=1;} doHealBead();}
以上来自于百度翻译 以下为原文 Hello I am trying to do a PIC24 to PIC24 SPI I am trying to configure the slave to wait in a loop till characters arrive at the SPI port then copy them into an array afterwards signal master slave is done then master reads characters back from slave so far i havent been successful this is my code any insights will be great using PIC24HJ32 thanks #include "xc.h" #define CLK_POL_ACTIVE_HIGH 0x0000 #define SPI_CKE_ON 0x0100 #define SLAVE_ENABLE_ON 0x0080 #define SPI_MODE8_ON 0x0000 /* Communication is byte wide */ #define MASTER_ENABLE_OFF 0x0000 /* Slave Mode */ #define SLAVE_READY _LATB2 void config_slave_ready(){ _TRISB2 =0; _PCFG4 =1; // _CN6PUE =1; _LATB2=1; } void config_SPI1(void){ SPI1CON1 = CLK_POL_ACTIVE_HIGH | //pri_prescale 4:1 sec prescale 1:1 clk pol active high SPI_CKE_ON | SLAVE_ENABLE_ON | SPI_MODE8_ON | MASTER_ENABLE_OFF ; _SDI1R = 5; //config SDI to RP5 _RP6R =7; //config serial data out to RP6 _SCK1R= 7; //serial clock in from master to RP7 _SS1R = 3; //slave select in to RP3 config_slave_ready(); SLAVE_READY =0; int index =0; _SPI1IF =0; _SPI1IP =3; _SPI1IE =0; SPI1STATbits.SPIEN =1; } void doHeartBeat() { long b; _LATB15 = 1; for(b=0;b<3255;b++); // __delay_ms(1000); _LATB15 = 0; } volatile int u16_index; void _ISR _SPI1Interrupt (void) { //character arrived, place in buffer sz_1[u16_index] = SPI1BUF; u16_index++; _SPI1IF = 0; //clear interrupt flag } int main(void) { config_SPI1(); while(1){ do { for(j=0;j<22;j++) sz_1[j]= SPI1BUF; }while(j<22); if(j>22){ doHeartBeat(); for(j=0;j<3255;j++); _LATB2=0; for(j=0;j<22;j++); { SPI1BUF = sz_1[22-j]; } _LATB2=1; } } doHeartBeat(); } |
|
相关推荐
6个回答
|
|
SPI不是这样工作的。UART确实如此。因此,我建议使用UART来代替SPI在事务中的工作。主提供时钟(8或16脉冲)。在那个时钟期间,两个伙伴发送他们的数据。一旦时钟结束,它们都可以检索由伙伴发送的数据。因此,如果你想让奴隶发送一些序列,必须是:-从数据加载到SPBIFF -主负载数据到SPBIF(可能是虚拟数据)-一旦主负载SPBIF,时钟STATS滴答-主机等待结束。时钟-现在师父可以读取SPIBUFThis进程中的数据,为每个字节(或字)重复。使用从属选择线(SS)同步事物也是一个好主意。否则,时钟线上的一个杂散脉冲会把一切都搞砸。
以上来自于百度翻译 以下为原文 SPI doesn't work that way. UART does. So, I suggest using UART instead. SPI work in transactions. Master provides clock (8 or 16 pulses). During that clock, both partners send their data. Once the clock is over they both can retrieve the data sent by the partner. So, if you want the slave to send something the sequence must be: - slave loads data into SPIBUF - master loads data into SPIBUF (possibly dummy data) - Once master loads SPIBUF, the clock strats ticking - Master waits to the end of the clock - Now master can read the data from SPIBUF This process get repeated for every byte (or word). It is also a good idea to use slave select line (SS) to synchronize things. Otherwise, a single stray pulse on the clock line will screw up totally everything. |
|
|
|
您似乎同时拥有轮询和中断代码来读取SPI1BUF。您的轮询代码从不等待字符准备就绪,它只是快速地读取SPI1BUF。
以上来自于百度翻译 以下为原文 You seem to have both polling and interrupt code trying to read SPI1BUF. Your polling code is never waiting for a character to be ready, it just rapidly reads SPI1BUF as quickly as it can. |
|
|
|
谢谢大家对我的回答,我想知道从选择引脚(SS),它通常保持高的上拉电阻,并带来低,以断言奴隶?
以上来自于百度翻译 以下为原文 thanks guys for you kind replies I was wondering the slave select pin(SS) is it normally held high with a pullup resistor and brought low to assert the slave? |
|
|
|
正常情况下,它将由主机驱动高电平和低电平,因此不需要上拉电阻,除非这是通过可能断开的电缆。
以上来自于百度翻译 以下为原文 Normally it would be driven both high and low by the master, so there's no need for a pullup resistor unless this is via a cable that might be disconnected. |
|
|
|
暗示,一个论坛话题就像一个对话。如果你不参与对话,你就不可能得到更多有用的回应。
以上来自于百度翻译 以下为原文 Hint, a forum topic is like a conversation. You're unlikely to get any more useful responses if you don't participate in the conversation. |
|
|
|
请注意,这个话题已经被放弃了。OP已经开始了一个新的问题:
以上来自于百度翻译 以下为原文 Note to all. This topic has been abandoned. The OP has started a new question at http://www.microchip.com/forums/m989215.aspx |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
729浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
628浏览 0评论
526浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 12:03 , Processed in 1.211987 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号