完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
阅读DS7000,195F,第20页。注意:我不是试图控制EEPROM,而是一个线性威廉希尔官方网站
电源IC LTC945(PIC Mrd/LTC945从机)线路3。等待和验证从奴隶的确认。我如何使SDA高阻抗/输入使奴隶能够确认地址?当做。
以上来自于百度翻译 以下为原文 Reading DS70000195F, page 20. I'm trying to follow the steps. Note: I'm not trying to control an EEPROM but a Liner Tech Power IC LTC2945 (PIC master / LTC2945 Slave) Line 3. Wait for and verify acknowledge from slave. void i2cSendAddress (td_operation select) { // Address is 7 bits long: 110 a3 a2 a1 a0 // With Adr1 & Adr0 NC (OC): address: 1101 010x (x Read = 1 & Write = 0) switch(select) { case read: while(I2C1STATbits.TBF == 1); I2C1TRN = 0b11010101; break; case write: while(I2C1STATbits.TBF == 1); I2C1TRN = 0b11010100; break; default: break; } // I2C1RCV Rx reg // I2C1TRN Tx reg // I2C1STATbits.RBF Rx buffer full = 1 } void i2cSendStartBit (void) { // SCL = 1 and SDA falling edge I2CSCL = 1; I2CSDA = 1; delay1ms(1); I2CSDA = 0; delay1ms(1); } How do i make the SDA high impedance / an input to enable the Slave to acknowledge address? Regards. |
|
相关推荐
11个回答
|
|
来自HTP://www. MigCHIP.COM/FUMMS/M99 64 35.ASPXAND HTTP//www. MICCHIP.COM/FUMMS/M99 645 1.ASPX
以上来自于百度翻译 以下为原文 comes from http://www.microchip.com/forums/m996435.aspx and http://www.microchip.com/forums/m996451.aspx |
|
|
|
HI,家庭参考手册文件,描述硬件I2C外围设备的工作,描述硬件所执行的动作,以及固件所需动作的描述。当启用I2C硬件时,您不控制SDA或SCL引脚输入或输出的状态,HAR。DWORD做到这一点。当将地址或数据传输到从机时,您将写入I2CXTRN寄存器,然后等待(I2CXSTATBITS。TSTAT==1)硬件完成从接收设备接收ACK/NACK信号的传输。当传输完成时,硬件将使TrSTAT位返回到0,AN。D使ACK信号的值在I2CXSTAT寄存器的ACKSTAT位中可用。硬件还将设置I2CXMIF中断标志。如果你想检查它。不要依赖TBF位,在传输完成之前它会返回到0。当传输完成硬件时,检查AkStAT位的值。同时检查BCL位和IWCOL位的值。当所有这些都好时,您的程序已准备好进行下一次传输。代码片段IN消息1是硬件外设操作的混合,以及类似于BITBUG的尝试。这两种方法不能同时进行。Mysil,
以上来自于百度翻译 以下为原文 Hi, The Family Reference Manual document, describe the working of the hardware I2C peripheral, and describe actions performed by the hardware, together with descriptions of actions needed by the firmware. When the I2C hardware is enabled, you do not control state of SDA or SCL pins input or output, hardware do that. When transferring address or data to slave, you write to I2CxTRN register, and then wait while (I2CxSTATbits.TRSTAT == 1) Hardware will complete the transfer including receiving ACK/NACK signal from slave device. When transfer is completed, hardware will make TRSTAT bit go back to 0, and make value of ACK signal available in ACKSTAT bit of I2CxSTAT register. hardware will also set I2CxMIF interrupt flag. if you want to check that. Do Not depend upon TBF bit, it will go back to 0 before transfer is completed. When Transfer is completed by hardware, check value of ACKSTAT bit. Also check value of BCL bit and IWCOL bit. When all of these are good, your program is ready for the next transfer. Code snippet in message #1 is a mixup of hardware peripheral operations, and something that seem like attempts of bitbanging. Those two methods will not go together at the same time. Regards, Mysil |
|
|
|
Mysil,我需要先发送STARTBIT吗?我只是想了解什么是自动的和什么不是。一旦我发送了一个数据字节:那么我需要检查I2C1STATBES.ACKSTAT,以确保奴隶已经承认转移?我想试着在模拟器中运行这个程序,有没有已知的关于I2C的手表窗口的DUG?非常感谢你的回复。
以上来自于百度翻译 以下为原文 Mysil, Do I need to send StartBit first? void i2cSendStartBit (void) { I2C1CONbits.SEN = 0x01; while (I2C1CONbits.SEN); Nop(); } I'm just trying to understand what's automatic and what's not. Once i've sent a data byte: I2C1TRN = 0b11010101; while(I2C1STATbits.TRSTAT == 1); I then need to check I2C1STATbits.ACKSTAT, to ensure slave has acknowledge the transfer? I'm gooing to try and run this in the simulator, are there any known dugs with the watches windows regarding I2C? Many thanks for your reply. Regards. |
|
|
|
嗨,是的,在消息4中的代码将成功地完成,条件是总线是免费的,并且任何先前的信令都已经完成。如果代码在I2C总线上使用,我们的MCU是唯一的主机,那么所有总线使用的函数等待每个操作完成,并且没有错误。如果已经发生了,那么I2CSEnDistBIT()将工作。如果这些条件中的任何一个条件不满足,则需要更多的测试。是的,测试AkStAT位以确保I2C从设备被连接、存活和响应。注意,AkStAT位与总线上的ACK信号具有相同的值,它是“逆逻辑”,意思是:0是“好”,1是“不回答”,我不知道有什么特殊的把戏与监视窗口,但有一个常见的混乱与16位PIC CPU集结在断点,所以有断点停止你想要的地方,有:NOP();语句需要。我不相信模拟器,我更愿意在真实的硬件上运行测试。你的消息的页脚,告诉你你有3和EPMC806,它们对于这样的测试来说是完美的。如果你没有外部的上拉电阻和实际的I2C从机连接,你可以激活内部弱的上拉。对于I2C信号引脚:CNPUGBITS.CNPUG2=1;CNPUGITS.CNPUG3=1;问候,Mysil
以上来自于百度翻译 以下为原文 Hi, Yes, and code in message #4 will do that successfully, on condition that the bus is free, and that any previous signaling have been completed. If the code is used on a I2C bus where our MCU is the only master, all functions using the bus wait for each operation to complete, and there is not an error happened already, then i2cSendStartBit(); function will work. If any of those conditions are not satisfied, more tests will be needed. Yes, test the ACKSTAT bit to ensure that I2C Slave device is connected, alive and responding. Note, that ACKSTAT bit have the same value as ACK signal on the bus, it is 'Inverse logic', meaning: 0 is 'good', and 1 is 'no answer' if (I2C1STATbits.ACKSTAT == 1) { i2cSendStopBit(); // Back to square one. } I do not know any special tricks with the watch window, but there is the usual confusion with 16-bit PIC cpu skidding on breakpoints, so to have breakpoints that stop where you want, there are: Nop(); statements needed. I do not trust the simulator, I would prefer to run the test on real hardware. The footer of your messages, tell that you have PICkit 3 and EP_MC806, they are perfect for such a test. If you do not have external pull up resistors and an actual I2C slave connected, you may activate internal weak pull-up for I2C signal pins: CNPUGbits.CNPUG2 = 1; and CNPUGbits.CNPUG3 = 1; Regards, Mysil |
|
|
|
MysIL,谢谢你们的帮助。我现在有一个关于SDL和SCL和监视:StistBoT地址(写)ACK命令(寄存器地址)ACKStutt StistBoad地址(Read)ACK//启用主I2C1CONTITS。RCEN= 1等待RxBuffer满标志,然后存储I2C1RCV波形看起来像他们应该,分开FRO。我是从数据。我确实得到了一些数据,但是它是随机的(我还不能确定和分组)试图确定最好的方法来解决这个问题并解决这个问题。
以上来自于百度翻译 以下为原文 Mysil, Thanks for your help. I now have a scope on SDL and SCL and monitoring: StartBit Address (write) Ack Command (address of a register) Ack Repeat StartBit Address (read) Ack // Enable master I2C1CONbits.RCEN = 1 wait for RxBuffer full flag and then store I2C1RCV The waveforms look as they should, apart from the slave data. I do get some data, but it's random (well I can not determine and partern as yet) Trying to determine the best way to break this down and resolve the issue... Regards, |
|
|
|
如果你不展示你正在阅读的什么样的记录,你希望得到什么样的价值,你又得到了什么样的价值,那么你就只有自己了。
以上来自于百度翻译 以下为原文 You're on your own if you don't reveal what register you are reading, what value you expected to get back, and what value you did get back. |
|
|
|
等待RxBuffer满标志,然后存储I2C1RCV取决于什么注册我请求的内容(0xFF或0x05),我得到什么可以是任何东西
以上来自于百度翻译 以下为原文 wait for RxBuffer full flag and then store I2C1RCV Depending on what what register i request the contents of (0xff or 0x05), what I get back can be anything |
|
|
|
对于它的价值,它所代表的代码…和其他:问候。
以上来自于百度翻译 以下为原文 For what it's worth, the code as it stands... void deBug (void) { unsigned int i2cData; i2cData = 0xaaaa; i2cControl(on); I2C1RCV = 0x00; while(1) { i2cCheckIdle(); i2cSendStartBit(); i2cSendAddress(write); //while(!i2cGetACKStatus()); delay5us(2); while(I2C1STATbits.ACKSTAT); i2cSendCommand(minPower); delay5us(2); while(I2C1STATbits.ACKSTAT); i2cCheckIdle(); i2cSendRepeatStartBit(); // or use repeat send option? i2cSendAddress(read); //while(!i2cGetACKStatus()); i2cCheckIdle(); // don't need delay5us(2); while(I2C1STATbits.ACKSTAT); i2cCheckIdle(); I2C1CONbits.RCEN = 0x01; while(!I2C1CONbits.RCEN); Nop(); Nop(); i2cCheckIdle(); while(!I2C1STATbits.RBF); i2cData = I2C1RCV; Nop(); } } And the rest: void i2cControl (td_operation select) { // All I2C routines are as per LTC2945 switch (select) { case on: I2C1CONbits.I2CSIDL = 0x00; // Operate in idle mode I2C1CONbits.SCLREL = 0x01; // Slave - holds clock low // Release clock I2C1CONbits.IPMIEN = 0x00; // IPMI support disabled I2C1CONbits.A10M = 0x00; // 7 bit salve address (not 10bit) I2C1CONbits.DISSLW = 0x00; // Slew rate control disabled // I2C1CONbits.SMEN = 0x00; // SMBus disabled I2C1CONbits.GCEN = 0x00; // General call disabled I2C1CONbits.STREN = 0x00; // Clock stretch disabled I2C1CONbits.ACKDT = 0x00; // Send nACK during acknowledge I2C1CONbits.ACKEN = 0x00; // ACK sequence not in progress I2C1CONbits.RCEN = 0x00; // Receive not in progress I2C1CONbits.PEN = 0x00; // Stop operation not in progress I2C1CONbits.RSEN = 0x00; // Repeat start not in progress I2C1CONbits.SEN = 0x00; // Start condition not in progress // I2C1STAT status register I2C1MSK = 0x00; // Disable mask //I2C1BRG = (((1/I2CBAUD) - I2CDELAY) * FP) - 2; // Compiler error (warning) with the // above line. Overflow I2C1BRG = (((I2CCLKPERIOD) - I2CDELAY) * FP) - 2; I2C1CONbits.I2CEN = 0x01; // Enable break; case off: I2C1CONbits.I2CEN = 0x00; break; default: break; } } void i2cSendAddress (td_operation select) { // Address is 7 bits long: 110 a3 a2 a1 a0 // With Adr1 & Adr0 NC (OC): address: 1101 010x (x Read = 1 & Write = 0) switch(select) { case read: while(I2C1STATbits.TBF); I2C1TRN = 0b11010101; while(I2C1STATbits.TRSTAT); break; case write: while(I2C1STATbits.TBF); I2C1TRN = 0b11010100; while(I2C1STATbits.TRSTAT); break; default: break; } } void i2cSendStartBit (void) { I2C1CONbits.SEN = 0x01; Nop(); Nop(); while (I2C1CONbits.SEN); Nop(); } void i2cSendRepeatStartBit(void) { I2C1CONbits.RSEN = 0x01; Nop(); Nop(); while (I2C1CONbits.RSEN); Nop(); } void i2cSendStopBit (void) { I2C1CONbits.SEN = 0x01; while (I2C1CONbits.SEN); Nop(); } void i2cCheckIdle (void) { while(I2C1STATbits.TRSTAT); } void i2cSendCommand (td_i2cRegisters i2cReg) { switch(i2cReg) { case cntrl: // 0x00 address I2C1TRN = 0b00000000; while(I2C1STATbits.TRSTAT == 1); break; case fault: // 0x02 break; case minPower: // 0x0b I2C1TRN = 0b00001011; while(I2C1STATbits.TRSTAT == 1); break; default: break; } Nop(); Nop(); //return(-1); } Regards. |
|
|
|
|
|
|
|
Mysil,这就是我正在做的,读寄存器“控制”和“Min Adin”(0x05和0xFF)。我现在得到正确的结果。
以上来自于百度翻译 以下为原文 Mysil, That's what i'm doing, reading Register "control" and "MIN ADIN" (0x05 & 0xff respectively). I get the correct results sometimes now.... |
|
|
|
让它全部工作。如果有人想要的话,有代码吗?
以上来自于百度翻译 以下为原文 Got it all working. Code available if anyone wants it? |
|
|
|
只有小组成员才能发言,加入小组>>
5377 浏览 9 评论
2102 浏览 8 评论
2006 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3280 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2314 浏览 5 评论
883浏览 1评论
771浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
708浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
766浏览 0评论
655浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-3-8 11:36 , Processed in 1.209178 second(s), Total 64, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191