完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,
我尝试用I2C接口与一个传感器通信,我使用PSoC创建者2中的I2C主控(UDB)组件。复位连接到“0”和SDA,SCL连接到传感器(从属)上的上拉电阻。在I2C接口之前,我使用了很多时间,所以我非常熟悉。协议。问题是,这次我得到了一个完整的模块,其功能是从数据表中,我无法理解如何从从属寄存器中进行简单的读取: 我需要访问传感器的地址,然后使用另一个地址访问它的寄存器,然后读取数据并保存它。 传感器接口协议简单、规范: 硕士研究生学位论文 从属〔β〕K·ACK-κ-κ(Ⅰ) 如果有人可以给我一个简单的代码示例,说明如何使用组件的功能来实现这一切,我将非常感激… 谢谢, 米迦勒。 以上来自于百度翻译 以下为原文 Hi, I'm trying to communicate with a sensor using I2C interface and I use the I2C Master (UDB) component in the PSoC creator 2.0 to do so.The reset is connected to '0' and the SDA, SCL connected to the sensor (slave) with pull-ups resistors. I used many times before I2C interface so I very familiar with the protocol. the problem is that this time I get a complete module with functions that from the datasheet I just can't understand how to make a simple reading from the slave's registers: I need to access to the sensor's address and then access its registers using another address and then read the data and save it. The protocol of the sensor interface is simple and standard: Master|S|AD+W| |RA| |S|AD+R| | |NACK|P| Slave | | |ACK| |ACK| | |ACK|DATA| | | If someone can give me a simple code example for how to use the component's functions to make this all work I'll be very grateful... Thanks, Michael. |
|
相关推荐
19个回答
|
|
哦,我把读命令的东西实际上得到了I2C从已读。愚蠢的我(我太习惯SPI了……):(
但我仍然看到,有阅读后的0x00(和确认),I2C总线上发生了什么,但LA似乎没有注释。 我建议你)上传完整的项目,所以我们可以看看完整的源代码(可能是别的什么东西了),并链接到你与之通信的芯片datasheet(也许错误在协议…)。 以上来自于百度翻译 以下为原文 Oh, I mixed up the read command with something which actually got already read from the I2C slave. Silly me (I'm too used to SPI... :( But I still see, after the 0x00 got read (and ACKed) that something happens on the I2C bus, but the LA doesn't seem to annotate it. I suggest you a) upload the complete project, so we can look at the complete source code (maybe something else is off), and link to the datasheet of the chip you are communicating with (maybe the error is in the protocol...). |
|
|
|
错误的,抱歉的
应该阅读“我没有使用sEdTestSuffor”… 鲍勃 以上来自于百度翻译 以下为原文 Mis-typed, sorry Should read "I did NOT use SendStop() .... Bob |
|
|
|
呸…就是这样,它希望重新发送而不是发送。*FACEPALM *
谢谢你们两个,伙计们! 所以我的代码工作是: UIT1616MSB =(ReaveAdt & Gt;Gt;8); UIT1616LSB=RealAdvices; UIT8I; 挥发性UTIT8状态; Stase= DSPTI2CMASTESTESTART(SLaveCHIPSE,DSPJI2CX WrreWest-XFelx模式); 如果(状态= = dsp_i2c_mstr_no_error)/ *检查是否转移无误*结束 { *子寄存器的写入地址*/ 状态=DSPIII2CMASTEMWRITE字节(MSB); 如果(状态)!= DSPIII2CYMSTRYNNOX错误中断; Stase= DSP.I2CMistWrrestEnter字节(LSB); 如果(状态)!= DSPIII2CYMSTRYNNOX错误中断; } 状态= dsp_i2cmastersendrestart(slavechip,dsp_i2c_read_xfer_mode); 如果(状态= = dsp_i2c_mstr_no_error)/ *检查是否转移无误*结束 { /*读取2字节的数组*/ 对于(i=0;i&lt;CNT;i++) { 如果(我& lt;(碳))rddata [我] = dsp_i2cmasterreadbyte(dsp_i2c_ack_data); 否则RDATABAS[I]=DSPTI2CMASTATEDRADIONTELL(DSPIII2CY-NAKYDATA); } } DSPGI2cMistSeNestStor(;)/*发送停止*/ 以上来自于百度翻译 以下为原文 Bah....... that was it, it wanted resend instead of send.. *facepalm* Thank you both, guys! So my code working was: uint16 m*** = (regAddress >> 8); uint16 l*** = regAddress; uint8 i; volatile uint8 status; status = DSP_I2CMasterSendStart(slavechip, DSP_I2C_WRITE_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Write address of sub register */ status = DSP_I2CMasterWriteByte(m***); if(status != DSP_I2C_MSTR_NO_ERROR) break; status = DSP_I2CMasterWriteByte(l***); if(status != DSP_I2C_MSTR_NO_ERROR) break; } status = DSP_I2CMasterSendRestart(slavechip, DSP_I2C_READ_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Read array of 2 bytes */ for(i=0; i { if(i < (cnt-1))rdData = DSP_I2CMasterReadByte(DSP_I2C_ACK_DATA); else rdData = DSP_I2CMasterReadByte(DSP_I2C_NAK_DATA); } } DSP_I2CMasterSendStop(); /* Send Stop */ |
|
|
|
恭喜你把它解决了。欢迎来到PSOC的精彩世界!
以上来自于百度翻译 以下为原文 Congratulations to get it solved. Welcome to the wonderful world of PSoC! |
|
|
|
|
|
|
|
我手头没有一个代码示例,但是从您的协议中,我可以看到(AD-W,,Ad+R*),您可以尝试修改SLLVE的地址来指示读或写操作。这是在主软件中处理的,您只需指定从读取或写入到的从机的基本地址。
当您在示意图或组件目录中右键单击UN I2C模块时,您将很容易找到一个示例,然后单击“查找示例项目”,该对话框将产生一个对话框,在该对话框中选择您的设备(PSoC 5)。给出的例子是一个EZI2C从机,但这对于主母和寻址都不重要。 希望有所帮助 鲍勃 以上来自于百度翻译 以下为原文 I do not have a code-example at hand, but from your protocoll I can see (|AD-W| , |AD+R|) that you might try to modify the sllave's address to indicate a read or write operation. This is handled within the master-software, you just specify the slave's base address where you want to read from or write to. You'll easily find an example when you right-click un your I2C-module in the schematic or in the component catalog and then click on "Find example Project" which will bring up a dialog where you select your device (PSoC 5). The example given is for an EZI2c-slave, but that will not matter for the master and for the addressing. Hope that helps Bob |
|
|
|
谢谢鲍伯的回复,
我以前看过这个例子,但我不知道如何解决寄存器后,我的地址设备。与EZI2C不同的是,在我的例子中,我使用带有寄存器的设备…通过从头开始编写代码,我可以重新发明轮子,但我认为使用I2C组件功能是一个简单的方法,我从数据表或EZI2C示例中看不到/理解它们。 以上来自于百度翻译 以下为原文 Thanks Bob for the reply, I looked at that example before but I don't see how to address the registers after I address the device. Unlike the EzI2C In my case I use a device with registers... I'ts possible to invent the wheel all over again by writing the codes from scratch but I think that must be an easy way to do that using the I2C component functions which I just don't see/understand them from the datasheet or the EzI2C example... |
|
|
|
如果您能给我们提供从设备的零件号或规格,那会更好吗?
以上来自于百度翻译 以下为原文 It may be better if you can give us the part number or the specification of the slave devices? |
|
|
|
从属的数据表:HTTP://VunsNeSE.COM/MEMS/Roop/Dooptss/PS-MPU-60A.PDFSEE页36至39页
在我的例子中,奴隶的地址是:0x68。 从属寄存器映射:VuSENSESE.COM/MEMS/ROG/DICONTS/RMP-MPU-60A.PDF 我需要读写一个数据寄存器的代码示例。 谢谢, 米迦勒H 以上来自于百度翻译 以下为原文 The slave's datasheet: http://invensense.com/mems/gyro/documents/PS-MPU-6000A.pdf see pages 36 to 39 In my case the slave's address is: 0x68 The slave's register map: invensense.com/mems/gyro/documents/RM-MPU-6000A.pdf I need code example for reading/writing one of the data registers. Thanks, Michael H. |
|
|
|
我手头没有一个示例代码,但它是一个双行代码。
查看I2C主/多主/从模块的数据表,第19页。 使用 I2C.MaultRealDeBuf(SlaveAdr,DataBuffer,2,I2CYMODEAXORITEXXFER); 这就是全部。 鲍勃 I2CJMistRead Buf(SlaveAdr,and RealStCurthNo.,1,I2CyMoDENoNoY-STOP); 以上来自于百度翻译 以下为原文 I do not have an example-code right at hand, but it is a two-liner. Have a look at the datasheet of the I2C Master/Multimaster/Slave module, page 19. Use the I2C_MasterReadBuf(SlaveAdr,&DataBuffer,2, I2C_MODE_COMPLETE_XFER); That's all. Bob I2C_MasterWriteBuf(SlaveAdr,&RegisterNumber,1, I2C_MODE_NO_STOP); |
|
|
|
上面代码的行已经被弄错了,我想你可以再次正确地命令它们(先写,然后读)。
鲍勃 以上来自于百度翻译 以下为原文 The lines of the above code have gotten mangled, I suppose you can order them correctly again (Write first, then read). Bob |
|
|
|
感谢鲍伯的支持,
经过多次尝试(失败),下面的代码工作: It32Ⅰ; UIT8WRDATA〔1〕,RDATABASE〔2〕;//放入WrDATA(0)数组寄存器地址 挥发性UTIT8状态; I2C*START(); 状态=I2C.MaskestEngEnter(MPU6050IAd,I2CX Read EX-Felx模式); 如果(状态=I2CyMSTRyNoEnror)/*检查是否完成传输没有错误*/ { *发送1字节的数组*/ (i=0;i,lt;1;i++) { 状态=I2C.MistWrrestEngEnter字节(WRATDAT[I]); 如果(状态)!= I2CyMSTRyNOx错误中断; } } I2CyMasksEdTestCo();/*发送停止*/ 状态=I2C.MaskestEngEnter(MPU6050IAd,I2CX Read x Felx模式); 如果(状态=I2CyMSTRyNoEnror)/*检查是否完成传输没有错误*/ { /*读取2字节的数组*/ (i=0;i,lt;2;i++) { 如果(i,lt;1)rdDATa=i2c*MaultRead字节(I2CyAkxDATA); 否则RDDATA=I2C*MaultRead字节(I2CnNakl DATA); } } I2CyMasksEdTestCo();/*发送停止*/ I2C~(); 以上来自于百度翻译 以下为原文 Thanks Bob for the support, After alot of trying (and failing) the following code works: int32 i; uint8 wrData[1], rdData[2]; // Put in the wrData[0] array the register address volatile uint8 status; I2C_Start(); status = I2C_MasterSendStart(MPU6050_ADD, I2C_WRITE_XFER_MODE); if(status == I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Send array of 1 bytes */ for(i=0; i<1; i++) { status = I2C_MasterWriteByte(wrData); if(status != I2C_MSTR_NO_ERROR) break; } } I2C_MasterSendStop(); /* Send Stop */ status = I2C_MasterSendStart(MPU6050_ADD, I2C_READ_XFER_MODE); if(status == I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Read array of 2 bytes */ for(i=0; i<2; i++) { if(i < 1) rdData = I2C_MasterReadByte(I2C_ACK_DATA); else rdData = I2C_MasterReadByte(I2C_NAK_DATA); } } I2C_MasterSendStop(); /* Send Stop */ I2C_Stop(); |
|
|
|
嗯,看起来比我的两个…但很好,你已经收到了,谢谢你与我们分享你的代码!
鲍勃 以上来自于百度翻译 以下为原文 Well, looks a bit more than my twoliner... But fine that you've got it and thank you to share your code with us! Bob |
|
|
|
嗨,伙计们,我意识到这个帖子已经很老了,但是我希望你能帮助我。
我必须从16位的子地址读取I2C设备。不同的寄存器将有不同的长度,但是我尝试的寄存器应该有一个四字节的数组。 给你举个例子: 我会先写信给芯片: 8位芯片地址- 16子寄存器-数据 0x76- 0x00 0xBF-0x00 0xCa 0xDD 0xCF 当我读回逻辑分析器上看到的是第一个字节ACK,如附件中所示。 我只是稍微修改了您的代码,以适应16位子地址和四字节而不是2字节: UIT1616MSB =(ReaveAdt & Gt;Gt;8); UIT1616LSB=RealAdvices; It32Ⅰ; 挥发性UTIT8状态; Stase= DSPTI2CMASTESTESTART(SLaveCHIPSE,DSPJI2CX WrreWest-XFelx模式); 如果(状态=DSPGI2CYMSTRIGNONEAR错误)/*检查是否完成传输没有错误*/ { *发送1字节的数组*/ 对于(i=0;i & lt;1;i++){ 状态=DSPIII2CMASTEMWRITE字节(MSB); 如果(状态)!= DSPIII2CYMSTRYNNOX错误中断; Stase= DSP.I2CMistWrrestEnter字节(LSB); 如果(状态)!= DSPIII2CYMSTRYNNOX错误中断; } } DSPGI2cMistSeNestStor(;)/*发送停止*/ Stase= DSPTI2CMASTESTESTART(SLaveCHIPSE,DSPGI2C2Read xFelx模式); 如果(状态=DSPGI2CYMSTRIGNONEAR错误)/*检查是否完成传输没有错误*/ { /*读取2字节的数组*/ (i=0;i,lt;4;i++) { 如果(i和lt;3)rdDATa=dSP2I2cMistRead字节(DSPTI I2CYACKYDATA); 否则RDATABAS[I]=DSPTI2CMASTATEDRADIONTELL(DSPIII2CY-NAKYDATA); } } DSPGI2cMistSeNestStor(;)/*发送停止*/ 如有任何帮助,我们将不胜感激。 -凯特 屏幕截图2013-1218在110.3.03.PNG 32.3 K 以上来自于百度翻译 以下为原文 Hi guys, I realise this post is very old, but I am hoping you can help me out. I have to read from 16 bit sub address the I2C device. The different registers will be of different lengts, but the one i am attempting should have an array of four bytes. To give you an example: I will first write to the chip: 8bit chip address - 16 sub register - data 0x76 - 0x00 0xBF - 0x00 0xCA 0xDD 0xCF When i read back all i see on the logic analyzer is the first byte ack, as shown in the attachement I only tweaked your code slightly to accomedate for the 16 bit sub address and four bytes instead of 2: uint16 m*** = (regAddress >> 8); uint16 l*** = regAddress; int32 i; volatile uint8 status; status = DSP_I2CMasterSendStart(slavechip, DSP_I2C_WRITE_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Send array of 1 bytes */ for(i=0; i<1; i++){ status = DSP_I2CMasterWriteByte(m***); if(status != DSP_I2C_MSTR_NO_ERROR) break; status = DSP_I2CMasterWriteByte(l***); if(status != DSP_I2C_MSTR_NO_ERROR) break; } } DSP_I2CMasterSendStop(); /* Send Stop */ status = DSP_I2CMasterSendStart(slavechip, DSP_I2C_READ_XFER_MODE); if(status == DSP_I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */ { /* Read array of 2 bytes */ for(i=0; i<4; i++) { if(i < 3)rdData = DSP_I2CMasterReadByte(DSP_I2C_ACK_DATA); else rdData = DSP_I2CMasterReadByte(DSP_I2C_NAK_DATA); } } DSP_I2CMasterSendStop(); /* Send Stop */ Any help would be much appreciated. -Kat |
|
|
|
顺便说一下,我已经确认了第一个字节的读数是正确的,而不仅仅是0x00。
以上来自于百度翻译 以下为原文 Btw, I have confirmed that the first byte read back is correct and not just always 0x00 |
|
|
|
请不要用新问题劫持旧线程。这会隐藏你的问题,你会得到更少的答案。只需打开一个新线程。
谢谢, HLI 以上来自于百度翻译 以下为原文 Please, don't hijack old threads with new questions. This will hide your question, and you will get less answers. Just open a new thread. Thanks, hli |
|
|
|
你的问题是什么?你期望发生什么,而不是发生了什么?
LA截图显示您正在尝试读取寄存器0x00 8f,但是您的文本表示0x00 bf。LA还显示返回了三个字节。 也许你能说出你在说什么?通常,在读取寄存器时,在发送地址后不发送停止位,而是另一个启动条件。也许不需要帮助? 以上来自于百度翻译 以下为原文 What is the question you are having? What do you expect to happen, what what happens instead? The LA screenshot shows you are trying to read register 0x008f, but your text said 0x00bf. And the LA also shows that three bytes are returned. Maybe you can tell what you chip you are talking to? Typically, when reading a register, one doesn't send a stop bit after sending the address, but just another start condition. Maybe leaving out the SendStop() helps? |
|
|
|
你的问题是什么?你期望发生什么,而不是发生了什么?
LA截图显示您正在尝试读取寄存器0x00 8f,但是您的文本表示0x00 bf。LA还显示返回了三个字节。 也许你能说出你在说什么?通常,在读取寄存器时,在发送地址后不发送停止位,而是另一个启动条件。也许不需要帮助? 我的道歉,是我的印象迈克面临着与我一样的问题。这篇文章是一个打印错误,我试图从0x00 8F读取。我不知道你怎么说三字节返回。我从逻辑分析器屏幕截图中看到的是,我对芯片(0x76)写一个写入命令,到卷寄存器(0x00 8f)。然后我看到一个读开始到芯片(0x77)和第一个字节返回(0x00),但是我丢失了三个字节(例如0xCa 0xDD 0xCF)和一个停止位。如果我删除了发送停止()函数,正如你所建议的,我只看到写命令,没有读命令或返回-请参阅附加屏幕截图 屏幕截图2013-1218在16.41.32.pNG 18.8 K 以上来自于百度翻译 以下为原文 What is the question you are having? What do you expect to happen, what what happens instead? The LA screenshot shows you are trying to read register 0x008f, but your text said 0x00bf. And the LA also shows that three bytes are returned. Maybe you can tell what you chip you are talking to? Typically, when reading a register, one doesn't send a stop bit after sending the address, but just another start condition. Maybe leaving out the SendStop() helps? My apologies, it was my impression Mike was faced with the same problem as myself. The text was a typo, i was trying to read from 0x008F. I don't see how you say three bytes are returned. All i see from the logic analyzer screen shot is that i make a write command to chip (0x76), to the volume register (0x008F). I then see that a Read is initiated to the chip (0x77) and the first byte return (0x00), but that I am missing the remaing three bytes (e.g. 0xCA 0xDD 0xCF) and a stop bit. If i remove the Send Stop() function as you suggested I only see the write commands and no read command or returns - please see attached screen shot |
|
|
|
在读取时,我使用sEntStutter()在I2CeStand之间写入地址和数据(第二地址)。读完后,最后一个指令是sEntScript()。
鲍勃 以上来自于百度翻译 以下为原文 I used SendStop() between writing the address and data(secondary address) via the I2C instead I used a Restart() when reading. When reading is finished the last instruction is a SendStop(). Bob |
|
|
|
只有小组成员才能发言,加入小组>>
748个成员聚集在这个小组
加入小组2050 浏览 1 评论
1805 浏览 1 评论
3615 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1740 浏览 6 评论
1496 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
470浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
327浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
396浏览 2评论
337浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
713浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-10-31 20:09 , Processed in 1.204734 second(s), Total 115, Slave 98 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号