完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,在我们的定制板上,我们使用PIC24F16KM204控制器。我们使用XC16作为工具链。我们使用Max 31725作为温度传感器,它与微控制器连接在I2C上。我使用默认控制器时钟频率(FoSC)为8MHZZ,因为它不工作,请查看COMI。配置和读取传感器数据。我附上了Max 31725的时序图。虚空CysI2C2()TrISBITS.TrISB3=0;//配置SCL作为输出三位字节。TrISB2=0;/ /配置SDA作为输出SSP2STATBITS。CKE=0;SSP2STATBITS。SMP=1;SSP2CON1位。SSPEN=1;SSP2CON1位。SSPM3=1;SSP2CON1位。SSPM=SSPM=1。SSPM=0;SSP2CONT1位;SSP2CON3BIT。SDAHT=1;SSP2ADAD= 0x9;//设置I2C时钟,FOSC为8MHZ UIT16 16读写器({UtiN 16读写数据)=0;UTIN 8*PSENSORDATA;PSENSORATDATA=(UTI8*)和读写数据;SSP2CON2BIT。AkStAT=1;SSP2CON2BIT。SEN=1;SSP2BUF=I2CySLaveWyw 0;SSP2RITEI ADDR;(SSP2CON2BITS AksSTAT)= 0);SSP2BUF=0x00;同时(SSP2CON2BITS AkStAT!=0);SSP2CON2BIT。RSEN=1;SSP2BUF=I2CySLaveEx Read AdDR;同时(SSP2CON2BIT.ACKSTAT!= 0);PsSoReDATA(1)=SSP2BUF;SSP2CON2BIT。AKEN=1;PSONSORATABATE(0)=SSP2BUF;SSP2CON2BITS;PEN=1;返回Re读SRoDATA;}
以上来自于百度翻译 以下为原文 Hi, in our custom board,we are using PIC24F16KM204 controller.We are using XC16 as tool chain. we are using MAX31725 as our temperature sensor which is connected with the Micro controller over I2C. I have used default controller clock frequency(FOSC) as 8MHZ Since its not working ,please review the configuration and reading of sensor data. I have attached the timing diagram of MAX31725 also. void ConfigI2C2() { TRISBbits.TRISB3=0;//configure SCL as output TRISBbits.TRISB2=0; //configure SDA as output SSP2STATbits.CKE=0; SSP2STATbits.SMP=1; SSP2CON1bits.SSPEN=1; SSP2CON1bits.SSPM3=1; SSP2CON1bits.SSPM=0; SSP2CON1bits.SSPM=0; SSP2CON1bits.SSPM=0; SSP2CON3bits.SDAHT=1; SSP2ADD=0x9; //Setting I2C clock as 400KHZ with FOSC as 8MHZ } UINT16 read_Temp() { UINT16 readSensordata=0; UINT8 *pSensordata; pSensordata=(UINT8 *)&readSensordata; SSP2CON2bits.ACKSTAT=1; SSP2CON2bits.SEN=1; SSP2BUF=I2C_slave_write_addr; while(SSP2CON2bits.ACKSTAT!=0); SSP2BUF=0x00; while(SSP2CON2bits.ACKSTAT!=0); SSP2CON2bits.RSEN=1; SSP2BUF=I2C_slave_read_addr; while(SSP2CON2bits.ACKSTAT!=0); pSensordata[1]=SSP2BUF; SSP2CON2bits.ACKEN=1; pSensordata[0]=SSP2BUF; SSP2CON2bits.PEN=1; return readSensordata; } Attached Image(s) |
|
相关推荐
19个回答
|
|
|
|
|
|
|
|
|
SSP2CON2BIT。SEN=1;而(SSP2CON2BIT,SEN=1);
以上来自于百度翻译 以下为原文 SSP2CON2bits.SEN=1; while(SSP2CON2bits.SEN==1;) |
|
|
|
|
|
如上所述,在发出下一个I2C操作之前,必须等待每个I2C操作完成。此外,在AkStAT位上等待是错误的。您必须等待ACK循环结束,然后读取ACKSTAT位一次(并且仅一次),以确定响应是ACK还是NACK。
以上来自于百度翻译 以下为原文 As above, you must wait for EACH I2C operation to complete before issuing the next one. Also, waiting on the ACKSTAT bit is incorrect. You must wait for the ACK cycle to finish, then read the ACKSTAT bit once (and only once) to determine if the response was an ACK or a NAK. |
|
|
|
|
|
正如你所说的,我必须等待每一个I2C操作完成之前发出下一个,所以在这种情况下,我需要提供一个延迟2MS发出第二命令或有任何标志,通知我完成命令?根据从时序图,在主数据发送到从属之后,它应该等待ACK,然后主控器发送下一个字节。因此,如果我不轮询ACKSTAT位,哪个寄存器位我应该从奴隶中查询ACK。问候,Biswajit。
以上来自于百度翻译 以下为原文 As you said i must wait for EACH I2C operation to complete before issuing the next one so in this case do i need to provide a delay of 2ms before issuing the 2nd command or is there any flag available which notify me the completion of command? As per the Slave Timing diagram,after master send data to slave ,it should wait for ACK then after master should send next byte. So if i will not poll for ACKSTAT bit, which register bit i should poll for ACK from slave. Regards, Biswajit |
|
|
|
|
|
不,它不是一个延迟。启动条件不是通过设置SEN位而产生的。您必须等到它复位。
以上来自于百度翻译 以下为原文 No its not a delay as such.Start condition is not generated by just setting SEN bit.You have to wait till it resets. |
|
|
|
|
|
将数据放入缓冲区。等到SSP1STATBITS。RYW重置,即读/写完成。之后检查。
以上来自于百度翻译 以下为原文 Put data in buffer.wait till SSP1STATbits.R_W resets i.e read/write done.After that check ackowledge. |
|
|
|
|
|
根据您的建议,我已经修改了Read Type函数。如果有错误,请告诉我:UTIN Read OpthType({Unt16 Read SoReloDATA=0);UTIN 8*PSeNoReDATA;pSimordDATA=(UTI8*)和Read SysReloDATA;SSP2CON2BITS。AkStAT=1;SSP2CON2BIT。SEN=1;而(SSP2CON2BITS.SEN=1);SSP2BUFF=1;SSP2BUFF=0x00;SSP2CON2BITS=1;而(SSP2CON2BITS,RSEN=1);SSP2BUF=I2CySLaveEx Read AdDR;而(SSP2STATBITS.BF=1);PSSONDATA数据[1 ]=SSP2BUF;SSP2CON2BATE.ACKEN=1;而(SSP2CON2BIT.ACKEN=1);PSSONDATA数据[0 ]=SS SSP2BUF=I2CySLaveWi Wrad EddR;2BUF;SSP2CON2BIT。笔=1;而(SSP2CON2BIT.PEN=1);返回读传感器数据;}
以上来自于百度翻译 以下为原文 As per your suggestion i have modified the read_Temp Function .please let me know if any mistakes are still there or not: UINT16 read_Temp() { UINT16 readSensordata=0; UINT8 *pSensordata; pSensordata=(UINT8 *)&readSensordata; SSP2CON2bits.ACKSTAT=1; SSP2CON2bits.SEN=1; while(SSP2CON2bits.SEN==1); SSP2BUF=I2C_slave_write_addr; while(SSP2STATbits.BF==1); SSP2BUF=0x00; while(SSP2STATbits.BF==1); SSP2CON2bits.RSEN=1; while(SSP2CON2bits.RSEN==1); SSP2BUF=I2C_slave_read_addr; while(SSP2STATbits.BF==1); pSensordata[1]=SSP2BUF; SSP2CON2bits.ACKEN=1; while(SSP2CON2bits.ACKEN==1); pSensordata[0]=SSP2BUF; SSP2CON2bits.PEN=1; while(SSP2CON2bits.PEN==1); return readSensordata; } |
|
|
|
|
|
嗨,我还在努力让i2c工作。我已经根据建议修改了。但是仍然不起作用。我的配置或阅读可能出错。SSP2ADAD= 0x9;//设置FOSC为8MHZi的I2C时钟没有配置DSSPXMSK寄存器。请让我知道如果FoSC=8MHz,也读取函数,Unt16 Read StimeTo({Unt16 Read SoReDATA=0);Unt8*PsSoRoDATA;pSimoReDATA=(Unt8*)和RealScReDATA;SS,配置所需的值。(SSP2CON2BITS.SEN=1);SSP2BUF=I2CySLaveWWRead EdDR;而(SSP2STATBITS.BF=1);SSP2BUFF=0x00;而(SSP2STATBITS.BF=1);SSP2CON2BIT。RSEN=1;而(SSP2CON2BITS,RSEN=1);SSP2BUF=I2CySLaveEi Read AdDR;而(SSP2STATBITS.BF=1);PSSONDATA数据[1 ]=SSP2BUF;2CON2BIT.ACKSTAT=1;SSP2CON2BIT。SEN=1;而SSP2CON2BATE.AKEN=1;而(SSP2CON2BATE.AKEN=1);PSONSORATABATE〔0〕=SSP2BUF;SSP2CON2BIT。笔=1;而(SSP2CON2BIT.PEN==1);返回Re读SrordDATA;},Biswajit。
以上来自于百度翻译 以下为原文 Hi , I am still struggling to make I2C working.I have modified as per suggestion.But still its not working. There could be wrong in my configuration or in reading. SSP2ADD=0x9; //Setting I2C clock as 400KHZ with FOSC as 8MHZ I have not configured SSPxMSK Register also.Please let me know the required value to configure if FOSC=8MHZ and also read function. UINT16 read_Temp() { UINT16 readSensordata=0; UINT8 *pSensordata; pSensordata=(UINT8 *)&readSensordata; SSP2CON2bits.ACKSTAT=1; SSP2CON2bits.SEN=1; while(SSP2CON2bits.SEN==1); SSP2BUF=I2C_slave_write_addr; while(SSP2STATbits.BF==1); SSP2BUF=0x00; while(SSP2STATbits.BF==1); SSP2CON2bits.RSEN=1; while(SSP2CON2bits.RSEN==1); SSP2BUF=I2C_slave_read_addr; while(SSP2STATbits.BF==1); pSensordata[1]=SSP2BUF; SSP2CON2bits.ACKEN=1; while(SSP2CON2bits.ACKEN==1); pSensordata[0]=SSP2BUF; SSP2CON2bits.PEN=1; while(SSP2CON2bits.PEN==1); return readSensordata; } Regards, Biswajit |
|
|
|
|
|
请注意这些。
以上来自于百度翻译 以下为原文 I2C_slave_write_addr I2C_slave_read_addr; Please mention these. |
|
|
|
|
|
|
|
|
|
|
|
由于A1,A2和A3连接到VDD,从地址是0x9e。对于细节,我已经附加了数据片断。I2CySavaEWRead EdDR=0x9e;I2CySavaEx Read AdDr=0x9F;问候,Biswajit。
以上来自于百度翻译 以下为原文 Since A1,A2 & A3 connection given to VDD, Slave address is 0x9E.For details i have attached the data sheet. I2C_slave_write_addr = 0x9E; I2C_slave_read_addr = 0x9F; Regards, Biswajit Attached Image(s) |
|
|
|
|
|
如果你的地址是0x3EI,那么I2CySavaEWWrdEnAdDDR =(从属地址& lt;& 1;)0x00,那么I2CySavaEx Read?AdDr=(从地址& lt;lt;1)0x01。
以上来自于百度翻译 以下为原文 Have you shifted address to right by one place. If slave address is 0x3E Then I2C_slave_write_addr=(slave address<<1)| 0x00 Then I2C_slave_read_addr=(slave address<<1)| 0x01 |
|
|
|
|
|
HiAkshayy,正如你在早先的对话中所说:把数据放在缓冲区中。等到SSP1STATBITS。RYW重置,即读/写完成。之后,检查AKOWEDGE。“当我浏览了页面:162的数据表,它说SRYSW(读/写信息位)只能在I2C从机的情况下使用,所以我没有使用。关于检查确认,请让我做我需要投票的FurkStAT Orkdt.问候,Biswajit
以上来自于百度翻译 以下为原文 Hi Akshayy, As you said in earlier conversation :Put data in buffer.wait till SSP1STATbits.R_W resets i.e read/write done.After that check ackowledge." When i have gone through the Page :162 of the data sheet, it says R_W(Read/Write Information bit) can be used only in case of I2C Slave so i didn't use that. And Regarding checking of acknowledge ,please let me do i need to poll for ACKSTAT OR ACKDT. Regards, Biswajit |
|
|
|
|
|
上7位是地址,最后一位是读/写。
以上来自于百度翻译 以下为原文 Upper 7 bit are of address and last bit is read/write |
|
|
|
|
|
嗨,在我把从地址变为7C的情况下,在写操作的情况下读和7d时,我可以看到SDA和AMP SCL上的数据,但直到奴隶没有响应。请让我知道,如果有任何问题,我的初始化配置或在读取功能?问候,Biswajit
以上来自于百度翻译 以下为原文 Hi , After i change the slave address to 7C in case of Read and 7D in case of write operation i could see the data on SDA & SCL but istill the slave is not responding. Please let me know if there is any issue with my initialization configuration or in Read function? Regards, Biswajit |
|
|
|
|
|
以前你使用了0x9e作为地址,现在你使用的是0x7c。为什么?
以上来自于百度翻译 以下为原文 Previously you have used 0x9E as address and now you are using 0x7C.Why? |
|
|
|
|
|
嗨,Akshay,正如前面的回答:“如果从地址是0x3e2I2ClSavaveWordRead EdDr=(从地址和lt;& lt;1))0x00,那么I2CySaveEx Read OpDRe=(从地址和lt;和1)0x01”,我从数据表中得到了从ID为9E,所以我分别使用9E和9F来写和读。但是我没有按照你们所说的去做。因此,在您的答复之后,我已经更改了代码asunSaleChansAdabess=0x9e;未签名的char I2cSlaveEx Read EndRe=(从地址和lt;& lt;1)*0x00;未签名的char I2cSlaveEx Read AdDr=(从地址和lt;lt;1)*0x01;因此计算的Value2ClSavaveWrad EdDr是“3c”ANDI2CySLaveEx Read AdDR将是“3D”。Biswajit
以上来自于百度翻译 以下为原文 Hi Akshay, as per earlier reply: "If slave address is 0x3E Then I2C_slave_write_addr=(slave address<<1)| 0x00 Then I2C_slave_read_addr=(slave address<<1)| 0x01" I have got slave id as 9E from data sheet so i was using 9E and 9F respectively for write and read. But I was not doing as you said. so after your reply i have changed the code as unsigned char slave address=0x9E; unsigned char I2C_slave_write_addr=(slave address<<1)| 0x00; unsigned char I2C_slave_read_addr=(slave address<<1)| 0x01; So the computed value I2C_slave_write_addr is "3C" and I2C_slave_read_addr will be "3D". Regards, Biswajit |
|
|
|
|
|
|
|
|
|
|
|
是的,A0,A1,A2连接到VDD。问候,Biswajit
以上来自于百度翻译 以下为原文 Yes , A0,A1,A2 are connected to VDD. Regards, Biswajit |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 19:50 , Processed in 1.295768 second(s), Total 113, Slave 95 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2938