完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,伙计们,
我有一个奇怪的问题,这使我发疯了! 我已经创建了一个函数,它能够读取包含16位子地址的I2C。 在我的情况,我需要回读4个字节的子地址,第四字节的值将一个值0,1或2。 如果(睡眠计数器和GT;50){ 睡眠计数器=0; readdata = i2c_1_dsp_master_read(device_addr_ic_1,mod_audio_detect_detect_reg_readbackalgsigma2001_addr,4); 如果(Read DATA=2){ [做某事] 否则,(Read DATA==1){ [做某事] 否则,(Read DATA==0){ 做某事 } } 其中读取函数如下: i2c_1_dsp_master_read卡片(卡片slavechip,uint16 regaddress,uint8 CNT){ UIT1616MSB =(ReaveAdt & Gt;Gt;8); UIT1616LSB=RealAdvices; UIT8I; 挥发性UtiT8状态; UITN8 RDATA〔4〕; 状态= dsp_i2cmastersendstart(slavechip,dsp_i2c_write_xfer_mode); 如果(状态= = dsp_i2c_mstr_no_error)/ *检查是否转移无误*结束 { 发送寄存器地址 状态=DSPIII2CMASTEMWRITE字节(MSB); (状态)= DSPII2CYMSTRYNNORY错误);/ /中断; Stase= DSP.I2CMistWrrestEnter字节(LSB); (状态)= DSPIII2CYMSTRYNONOX错误; } 状态= dsp_i2cmastersendrestart(slavechip,dsp_i2c_read_xfer_mode); If(Stase= DSPGI2CYMSTRIGNONEAR错误){ /*读取的CNT字节数组*/ 对于(i=0;i&lt;CNT;i++) { 如果(我& lt;(CNT))rddata [我] = dsp_i2cmasterreadbyte(dsp_i2c_ack_data); 否则RDATABAS[I]=DSPTI2CMASTATEDRADIONTELL(DSPIII2CY-NAKYDATA); } } DSPGI2cMistSeNestStor(;)/*发送停止*/ DSP2I2CMASTReleRead BuffFor(); 返回rdDATA〔3〕; } 每次我看回我得到预期的4字节的登记,使用逻辑分析仪验证。然而,有两件奇怪的事情发生了。 1)即使数组的第四个字节是一样的,因此返回rddata [ 3 ]应始终返回相同的值,这是没有的情况下。第一次i2c_1_dsp_master_read()称为正确的返回值,每次经过它返回0 2)第一次i2c_1_dsp_master_read叫逻辑分析仪显示四字节返回应答,另外一个5字节0x00和NACK看到。每一次,只有4个字节返回,但4字节是现在伴随着一个NACK。请参阅附件。(请注意,即使我提高CNT 5,4字节总是承认,返回值是错误的第一次阅读后。 任何帮助都将非常感谢! 最好的, 卡特琳 屏幕截图2014-01-13在110.7.40.PNG 106.6 K 以上来自于百度翻译 以下为原文 Hi guys, I have a peculiar problem, which is driving me insane! I have created a function that is able to read back I2C which includes a 16 bit subaddress. In my case I need to read back 4 bytes of the subaddress where the value of the 4th byte will be a value of 0, 1 or 2. if(sleep_counter > 50){ sleep_counter = 0; readData = I2C_1_DSP_MASTER_READ(DEVICE_ADDR_IC_1, MOD_AUDIO_DETECT_DETECT_REG_READBACKALGSIGMA2001_ADDR, 4); if(readData == 2 ){ //Do something } else if(readData == 1 ){ //Do something } else if(readData == 0){ //Do something } } Where the read function is as follows: uint8 I2C_1_DSP_MASTER_READ(uint8 slavechip, uint16 regAddress, uint8 cnt ){ uint16 m*** = (regAddress >> 8); uint16 l*** = regAddress; uint8 i; volatile uint8 status; uint8 rdData[4]; status = DSP_I2CMasterSendStart(slavechip, DSP_I2C_WRITE_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { // Send register address status = DSP_I2CMasterWriteByte(m***); while(status != DSP_I2C_MSTR_NO_ERROR);// break; status = DSP_I2CMasterWriteByte(l***); while(status != DSP_I2C_MSTR_NO_ERROR); } status = DSP_I2CMasterSendRestart(slavechip, DSP_I2C_READ_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) { /* Read array of cnt bytes */ for(i=0; i { if(i < (cnt))rdData=DSP_I2CMasterReadByte(DSP_I2C_ACK_DATA); else rdData = DSP_I2CMasterReadByte(DSP_I2C_NAK_DATA); } } DSP_I2CMasterSendStop(); /* Send Stop */ DSP_I2CMasterClearReadBuf(); return rdData[3]; } Every time I read back from the register I get the expected four bytes, verified by using a logic analyzer. However, there are two strange things that happen. 1) Even when the 4th byte of the array stays the same, hence return rdData[3] should always return the same value, this is not the case. First time I2C_1_DSP_MASTER_READ()is called the correct value is returned, every time after that it returns 0 2) The first time I2C_1_DSP_MASTER_READ is called the logic analyzer shows the four bytes returned with ACK, in addition a 5 byte of 0x00 and NACK is seen. Everytime after that 4 bytes only are returned, but the 4 byte is now accompanied by a NACK. Please see attachment. (please note that even if I increase cnt to 5 so that the four bytes are always acknowledged, the return value is still wrong after the first read. Any help would be very much appreciated! All the Best, Katrine |
|
相关推荐
4个回答
|
|
|
|
|
|
是的,在前一个消息中稍加改动就解决了我所看到的问题。
以上来自于百度翻译 以下为原文 Yes, applying the slight change in the previous message solved the issue I was seeing. |
|
|
|
我经常使用
/*读取的CNT字节数组*/ 对于(i=0;i&lt;CNT;i++) { rdDAT=dSP2I2cMistRead字节(i&lt;(CNT-1))?DSPGI I2CYACKYDATA:DSPI2I2CNAKYA数据; } 虽然我不喜欢“?”接线员,但这是我最喜欢的。 希望福尔姆斯不会破坏线路 鲍勃 以上来自于百度翻译 以下为原文 I frequently use /* Read array of cnt bytes */ for(i=0; i { rdData = DSP_I2CMasterReadByte(i < (cnt-1))?DSP_I2C_ACK_DATA:DSP_I2C_NAK_DATA; } although I do not like the "?" operator, but here it is my favorite. Hoping that forumSW doesn't clobber the lines Bob |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
752个成员聚集在这个小组
加入小组2075 浏览 1 评论
1829 浏览 1 评论
3645 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1766 浏览 6 评论
1517 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
517浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
371浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
413浏览 2评论
360浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
868浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 15:06 , Processed in 0.939630 second(s), Total 55, Slave 46 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号