完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这是我的第一个I2C项目。好像出了问题。从属者没有接收正确的数据。下面提供了主和从两个代码。任何人都可以调试
主代码 */ 包括: UIT8 8WRDATA〔2〕={0xAA,0xBB}; 外部UIT8标志; 空主程序() { *将初始化/启动代码放在此处(例如MyStimSistAd())*/ 囊状的; ISRYTXXSTART(); LCDX START(); I2C*START(); *取消注释此行以启用全局中断。*/ (;) { If(FLAG=1) { 旗=0; I2CJMistCurrStaseUs[/];/*清除任何先前状态*/ I2CJMistWrrestBuf(0x08,(Unt8*)WrDATA,2,I2CyMoDEi完全EXEXEXXFER); (;) { 如果(0U)!=(I2CJMistStaseUs)和(I2CYMSTATEA WRES-CMPLT) { *传输完成。检查主机状态以确保传输 无错误完成。*/ 断裂; } } LCDA- PrimtIn 8(WrDATA〔0〕); } *将您的应用程序代码放在这里。*/ } } /*[]文件结束*/ 从属码 包括: 空主程序() { UIT8I; UITN8 WRBUF〔10〕; UIT8用户阵列〔10〕; UIT8 8; 囊状的; *在调用i2c*Stc**之前初始化写入缓冲器 I2CySLaveInWruteBuf((Unt8*)WrBuf,10); LCDX START(); /*启动I2C从操作* I2C*START(); *等待I2C主控器完成写入*/ 对于(;;)/*循环永远** { *等待I2C主控器完成写入*/ 如果(0U)!=(I2CySavavestUsUs)和(I2CysStista WRES-CMPLT) { BytCNT= I2CySLaveGeWruteBuffsiz(); I2CySLaveCaveRealStestAtUsUs(); 对于(i=0;i&lt;BytCNT;I++) { 用户数组=WrBuf;/*传输数据*/ } I2CySLaveCaveRealeBuffe(); LCDA PrimtIn 8(USER数组〔0〕); } } } /*[]文件结束*/ 以上来自于百度翻译 以下为原文 This is my first I2C project. Seems like something going wrong. Slave is not receiving correct data. The code is provided below for both master and slave. Can anyone debug Master code */ #include uint8 wrData[2]={0xAA, 0xBB}; extern uint8 flag; void main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ CyGlobalIntEnable; isr_Tx_Start(); LCD_Start(); I2C_Start(); /* Uncomment this line to enable global interrupts. */ for(;;) { if(flag==1) { flag=0; I2C_MasterClearStatus(); /* Clear any previous status */ I2C_MasterWriteBuf(0x08, (uint8 *) wrData, 2, I2C_MODE_COMPLETE_XFER); for(;;) { if(0u != (I2C_MasterStatus() & I2C_MSTAT_WR_CMPLT)) { /* Transfer complete. Check Master status to make sure that transfer completed without errors. */ break; } } LCD_PrintInt8(wrData[0]); } /* Place your application code here. */ } } /* [] END OF FILE */ Slave code #include void main() { uint8 i; uint8 wrBuf[10]; uint8 userArray[10]; uint8 byteCnt; CyGlobalIntEnable; /* Initialize write buffer before call I2C_Start */ I2C_SlaveInitWriteBuf((uint8 *) wrBuf, 10); LCD_Start(); /* Start I2C Slave operation */ I2C_Start(); /* Wait for I2C master to complete a write */ for(;;) /* loop forever */ { /* Wait for I2C master to complete a write */ if(0u != (I2C_SlaveStatus() & I2C_SSTAT_WR_CMPLT)) { byteCnt = I2C_SlaveGetWriteBufSize(); I2C_SlaveClearWriteStatus(); for(i=0; i < byteCnt; i++) { userArray = wrBuf; /* Transfer data */ } I2C_SlaveClearWriteBuf(); LCD_PrintInt8(userArray[0]); } } } /* [] END OF FILE */ |
|
相关推荐
10个回答
|
|
你说的“正确”数据是什么意思?你收到什么了吗?主电压和从机运行的电压是什么,上拉电阻值是多少?
顺便说一下:初始化组件后,我会初始化缓冲区,这似乎不是错误,但听起来更符合逻辑。 鲍勃 以上来自于百度翻译 以下为原文 What do you mean with "correct" data? Are you receiving anything at all? What voltages are master and slave running with and what are the pull-up resistor values? By the way: I would initialize the buffers AFTER initializing the component which does not seem to be the error but sounds more logically. Bob |
|
|
|
我接收的唯一数据是FF。但实际上我在传播AA。我在3.3 V和5V测试主从双方,没有什么不同。电阻值UEDF是2.2K。我做了SCL和SDA线的探测,它们显示了某种传输,但我不确定。
代码与I2C组件数据表中的代码相同。 以上来自于百度翻译 以下为原文 The only data i receive is FF. But actiually I amtransmitting AA. I tested both master and Slave at 3.3 V and 5V. Nothing different. Resistor value usedf is 2.2k. I did probe both SCL and SDA line they show some sort of transmission but I am not sure with that. And the code is same as the one given in the data sheet of I2C component. |
|
|
|
我建议仔细检查传输频率和IO引脚连接。而且,你正在传输两个字节,你应该同时接收它们。
鲍勃 以上来自于百度翻译 以下为原文 I would suggest to double check the transfer frequency and the IO-pin connections. And: You are transmitting TWO bytes and you should receive both of them. Bob |
|
|
|
我想我应该把我的项目附加在这里,这样你们就可以很快地完成和调试问题了。
以上来自于百度翻译 以下为原文 I think i should be attaching my projects here, so that it will be easy for you guys to just quickly go through and debug the problem |
|
|
|
|
|
|
|
我想谷歌浏览器和赛普拉斯论坛之间有某种竞争……什么都没有得到……
救火是我的救赎 I2C.Cyrj.CaseV02.Zip 642.9 K 以上来自于百度翻译 以下为原文 I think so there is some sort of rivalry between Google chrome and Cypress forum...Nothing gets attached ........ Firefor is for my rescue
|
|
|
|
总是有机会使用MS IE Explorer。我想每一个功能至少都是通过浏览器的喜好和不喜欢来测试的。
鲍勃 以上来自于百度翻译 以下为原文 There is always the opportunity to use ms iinternet explorer. I suppose every function is at least tested with that browser independant of likes and dislikes. Bob |
|
|
|
我看不出有什么不对劲。
在完成传输后,您能检查(显示)主状态吗? 而不是 如果(0U)!=(I2CJMistStaseUs)和(I2CYMSTATEA WRES-CMPLT) 你可以写 UIT8状态; 如果((状态=I2CYMistStaseUs)); 然后打印VAR状态 鲍勃 以上来自于百度翻译 以下为原文 I cannot see anything wrong. Can you check (display) the master-status after a completed transfer. instead of if(0u != (I2C_MasterStatus() & I2C_MSTAT_WR_CMPLT)) you may write uint8 Status; if((Status= I2C_Masterstatus()) & I2C_MSTAT_WR_CMPLT) ... and later print the var Status Bob |
|
|
|
在使用下面的代码剪辑后,请确保主控器在调用MraveWrreBuffe()API之后写入数据:
做 { Timp=I2CM.MistMraveScript BUF(I2CySLaveEX地址,(UTI8*)WRBUF,SIZEOF(WRBUF),I2CMSMODEA完成EXEXEXXFER); }同时(温度!= I2CMYMSTRYNNORION错误; 如果您有任何协议分析器,请确保数据是从I2C主控器发送的。然后我们可以调试i2c从属。 以上来自于百度翻译 以下为原文 Make sure that Master is writing the data after you call the MasterWriteBuf() API by using the following code snipped: do { temp = I2CM_MasterWriteBuf(I2C_SLAVE_ADDRESS, (uint8 *)wrBuf, sizeof(wrBuf), I2CM_MODE_COMPLETE_XFER); }while (temp != I2CM_MSTR_NO_ERROR); If you have any Protocol analyzer, make sure that data is sent out of I2C Master. And then we can debug the I2C Slave. |
|
|
|
你能从奴隶点获得正确的数据吗????
以上来自于百度翻译 以下为原文 Were you able to obtain correct data at the slave point??? |
|
|
|
只有小组成员才能发言,加入小组>>
751个成员聚集在这个小组
加入小组2064 浏览 1 评论
1824 浏览 1 评论
3632 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1760 浏览 6 评论
1508 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
502浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
354浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
409浏览 2评论
354浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
851浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 00:43 , Processed in 1.071399 second(s), Total 96, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号