完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好福美使用DSPIC33 EP与24LC256 EEPROM存储器…我的问题是当我想同时写一个或多个字节的时候…它似乎不写第二次尝试。我使用的是C30的代码示例,该微芯片被建议,在SCL和SDA上具有2K2的上拉电阻,40MHz的ANDI2CBRG= 0x2F((FCY/FCL-FCY/10 000 0.000)- 1)的振荡器,它应该给我400千赫的时钟,而不是OF2CBRG=0x2F I PUti2CBRG=50。000然后我可以同时写多个页面或字节,但是它太慢了,绝对不能在我的项目中使用它。
以上来自于百度翻译 以下为原文 Hi forum i am using dspic33Ep with 24lc256 eeprom memory... my problem is when i want to write more than one pages or more than one byte at the same time... it seems that does not write the second attempts. i am using the code example of c30 that microchip is suggested, with pullup resistore of 2k2 on SCL and SDA, oscillator of 40MHZ and I2CBRG=0x2f ((FCY/FCL - FCY/10.000.000)-1 ) that should give me 400khz of clock if instead of I2CBRG=0x2f i put I2CBRG=50000 then i can write more than one pages or bytes at the same time, but it is too slow and absolutely can not use it in my project. |
|
相关推荐
19个回答
|
|
您的问题表明您没有正确地等待写入完成,因此显示您正在使用的实际代码将是一个好主意。
以上来自于百度翻译 以下为原文 Your problem indicates that you are not correctly waiting for the write to complete, so it would be a good idea to show the actual code you are using. |
|
|
|
你的意思是什么?I2C代码或写入EEPROM代码?我可以用什么函数来等待写入完成?延迟函数不适用。
以上来自于百度翻译 以下为原文 which code do you mean?I2C code or writing into the eeprom code? which function can i use for waiting for the write to be complete?delay function is not suitable. |
|
|
|
高级别EEPROM编写代码。我怀疑您在发送一个页面之后没有做任何事情,然后发送下一个。
以上来自于百度翻译 以下为原文 The high level eeprom writing code. I suspect you're not doing anything after sending a page to write, before sending the next one. |
|
|
|
数据表:HTTP//WW1.MICCHIPC.COM/DIXBOSS/En/DeVICECD/2000 033U.PDF.章“7确认轮询”
以上来自于百度翻译 以下为原文 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/20001203U.pdf Chapter "7.0 ACKNOWLEDGE POLLING" |
|
|
|
下面的代码是我的测试代码。就像这样:我也附上了我的I2C代码。我在这里还有一个问题,在我的函数下面没有返回,可以吗?
以上来自于百度翻译 以下为原文 exactly. the below code is my test code. it is like that: #define PAGESIZE 32 #define controlByte 0xA0 unsigned char PageString[32]; //Array to hold page data to/from EPROM unsigned char PageString1[32]; //Array to hold page data to/from EPROM unsigned char PageStr[32]; //Array to hold page data to/from EPROM unsigned char PageStr2[32]; //Array to hold page data to/from EPROM int main(void) { TRISA = 0xE3EC; TRISB = 0xC21C; TRISC = 0x5BC4; TRISD = 0x3FFF; TRISE = 0xFCFC; TRISG = 0x81FC; TRISF = 0xDB3C; ANSELA = 0; ANSELB = 0; ANSELC = 0; ANSELD = 0; ANSELE = 0; ANSELF = 0; ANSELG = 0; INTCON2bits.GIE = 1; INTCON1bits.NSTDIS = 0; TRISGbits.TRISG7 = 1; //scl TRISGbits.TRISG8 = 1; //SDA InitI2C1(); //HDSequentialReadI2C(ControlByte, HighAdd, LowAdd, PageStr, PAGESIZE); //HDSequentialReadI2C(ControlByte, HighAdd, LowAdd, PageStr2, PAGESIZE); for(n = 0; n < PAGESIZE; n++) { PageString[n] = n; } for(n = 0; n < PAGESIZE; n++) { PageString1[n] = n; } while(1) { if(!Ok){ // i put this control to write once my data is changing HDPageWriteI2C(controlByte, 0x00, 0x00, PageString); HDPageWriteI2C(controlByte, 0x21, 0x00, PageString1); //i thought that i have to also change low address when i want to write in new address but when i change it it does not write correctly ok=1; } } i attached my i2c code also.i have a question here also in my function below there is no return, is that ok? unsigned int WriteI2C1(unsigned char byte) { //This function transmits the byte passed to the function // while (I2C1STATbits.TRSTAT); //Wait for bus to be idle I2C1TRN = byte; //Load byte to I2C1 Transmit buffer while (I2C1STATbits.TBF); //wait for data transmission } Attachment(s) i2c1.txt (17.92 KB) - downloaded 85 times |
|
|
|
数据表:HTTP:/WW1.MicroChIP.COM/DeLoSs/En/DeViceOCD/2000 120 3UPDF章“7确认轮询”我在页面写代码中没有这个功能,这正是微芯片在AN1079中所写的…这是问题吗?我可以看到,在HDByTeWiRe2C1函数中,我有AkpLink,但是在页面上写不。你能看看我的附件在我以前的帖子吗??
以上来自于百度翻译 以下为原文 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/20001203U.pdf Chapter "7.0 ACKNOWLEDGE POLLING" i donot have this function in my page write code, it is exactly what microchip wrote in An1079... is that the problem? i can see that in the HDByteWriteI2C1 function i have ackpolling but in the page write no. can you please take a look on my attachment in my previuose post?? |
|
|
|
写一个字节或一个页面到EEPROM需要时间,通常是最大的4或5毫秒。在EEPROM数据表中查找“写周期时间”。&编辑,因此,您可以等待最大的写周期时间或从EEPROM中进行确认。
以上来自于百度翻译 以下为原文 Writing either a byte or a page to EEPROM takes time, usually 4 or 5 ms maximum. Look up "write cycle time" in your EEPROM datasheet. |
|
|
|
如何简单地等待最大写入周期而不使用ACKPORL?
以上来自于百度翻译 以下为原文 how can simply wait for maximum write cycle without using ackpoll? |
|
|
|
在两个写之间插入一个5毫秒的延迟。
以上来自于百度翻译 以下为原文 By inserting a delay for 5 milliseconds between your two writes. |
|
|
|
正如我所说,写EEPROM需要时间。确认轮询可用于确定先前写入是否已完成。如果你等待最大的写周期时间,写就完成了,对吗?
以上来自于百度翻译 以下为原文 As I said, writing to EEPROM takes time. Acknowledge polling can be used to determine if the previous write has completed or not. If you wait the maximum write cycle time, the write is complete, right? |
|
|
|
延迟函数可能是最后的选择,但是如果我想使用AkpLink,我怎么能在代码中使用它呢?我能把它写在我的两篇文章之间吗?还是应该修改PayWrad函数?
以上来自于百度翻译 以下为原文 delay function maybe will be last choice but if i want to use ackpolling how can i used it in my code?can i putted it between my two writes?or should i modify pagewrite function? |
|
|
|
ACK轮询允许更快的操作。你可以在两个写之间插入它,或者我更喜欢在写之前做它。
以上来自于百度翻译 以下为原文 Ack polling allows faster operation. You can either insert it between your two writes, or I'd prefer to do it before a write. |
|
|
|
不,这是不好的,这是一个暗示,你正在使用的微芯片代码写得很差。这个例程应该检查返回的ACK位,这可能是为什么它被写回一个值,但它不做检查,并且没有一个例程调用它无论如何检查返回值。一些更高级的例程是在以后做自己的ACK/NAK测试,但是它们只是保存状态,当一个字节已经是NAKd之后继续错误。“ACK轮询”仅仅意味着你开始发送一个数据包,如果没有准备好,设备将把它关闭。
以上来自于百度翻译 以下为原文 No it is not ok, and it is a hint that the Microchip code you are using is poorly written. That routine should check the returned ACK bit, which is probably why it has been written to return a value, but it doesn't do the check, and none of the routines calling it ever check the return value anyway. Some of the higher level routines are doing their own ack/nak test later, but they just save the status, when it is wrong to continue after a byte has been NAKd. "ACK polling" simply means you start to send a packet, and the device will NAK it if not ready. |
|
|
|
不,这是不好的,这是一个暗示,你正在使用的微芯片代码写得很差。这个例程应该检查返回的ACK位,这可能是为什么它被写回一个值,但它不做检查,并且没有一个例程调用它无论如何检查返回值。一些更高级的例程是在以后做自己的ACK/NAK测试,但是它们只是保存状态,当一个字节是NAKd之后继续错误。“ACK轮询”仅仅意味着你开始发送一个数据包,并且如果没有准备,设备会把它压缩。但是这个函数似乎存在于我的代码中。不是吗?我应该改变什么吗?我看到它在HDByTeWiReII2C1和HDpAgErrIII2C1(它HasputStruxC2C1功能,检查ACK STATUS),这是我的I2C:
以上来自于百度翻译 以下为原文 No it is not ok, and it is a hint that the Microchip code you are using is poorly written. That routine should check the returned ACK bit, which is probably why it has been written to return a value, but it doesn't do the check, and none of the routines calling it ever check the return value anyway. Some of the higher level routines are doing their own ack/nak test later, but they just save the status, when it is wrong to continue after a byte has been NAKd. "ACK polling" simply means you start to send a packet, and the device will NAK it if not ready. but it seems this function exist in my code,isn't it? should i change any thing?i saw it in HDByteWriteI2C1 and HDPageWriteI2C1(it has putstringI2C1 functin that check the ack statuse),... this is my i2c: /********************************************************************* * Function: InitI2C() * * Input: None. * * Output: None. * * Overview: Initialises the I2C(2) peripheral * * Note: Sets up Master mode, No slew rate control, 100Khz ********************************************************************/ void InitI2C1(void) { I2C1CON = 0; I2C1BRG = 0x002f; //0xF3;//0x37 40000 I2C1CON = 0x1200; I2C1RCV = 0x0000; I2C1TRN = 0x0000; //Now we can enable the peripheral // I2C1CONbits.ON = 1; I2C1CON = 0x9200; } /********************************************************************* * Function: StartI2C() * * Input: None. * * Output: None. * * Overview: Generates an I2C Start Condition * * Note: None ********************************************************************/ void StartI2C1(void) { //This function generates an I2C start condition and returns status //of the Start. I2C1CONbits.SEN = 1; //Generate Start COndition while (I2C1CONbits.SEN); //Wait for Start COndition //return(I2C1STATbits.S); //Optionally return status } /********************************************************************* * Function: RestartI2C() * * Input: None. * * Output: None. * * Overview: Generates a restart condition and optionally returns status * * Note: None ********************************************************************/ void RestartI2C1(void) { //This function generates an I2C Restart condition and returns status //of the Restart. I2C1CONbits.RSEN = 1; //Generate Restart while (I2C1CONbits.RSEN); //Wait for restart //return(I2C1STATbits.S); //Optional - return status } /********************************************************************* * Function: StopI2C() * * Input: None. * * Output: None. * * Overview: Generates a bus stop condition * * Note: None ********************************************************************/ void StopI2C1(void) { //This function generates an I2C stop condition and returns status //of the Stop. I2C1CONbits.PEN = 1; //Generate Stop Condition while (I2C1CONbits.PEN); //Wait for Stop //return(I2C1STATbits.P); //Optional - return status } /********************************************************************* * Function: WriteI2C() * * Input: Byte to write. * * Output: None. * * Overview: Writes a byte out to the bus * * Note: None ********************************************************************/ unsigned int WriteI2C1(unsigned char byte) { //This function transmits the byte passed to the function // while (I2C1STATbits.TRSTAT); //Wait for bus to be idle I2C1TRN = byte; //Load byte to I2C1 Transmit buffer while (I2C1STATbits.TBF); //wait for data transmission } /********************************************************************* * Function: IdleI2C() * * Input: None. * * Output: None. * * Overview: Waits for bus to become Idle * * Note: None ********************************************************************/ void IdleI2C1(void) { while (I2C1STATbits.TRSTAT); //Wait for bus Idle } /********************************************************************* * Function: LDByteWriteI2C() * * Input: Control Byte, 8 - bit address, data. * * Output: None. * * Overview: Write a byte to low density device at address LowAdd * * Note: None ********************************************************************/ unsigned int LDByteWriteI2C1(unsigned char ControlByte, unsigned char LowAdd, unsigned char data) { unsigned int ErrorCode; IdleI2C1(); //Ensure Module is Idle StartI2C1(); //Generate Start COndition WriteI2C1(ControlByte); //Write Control byte IdleI2C1(); ErrorCode = ACKStatus(); //Return ACK Status WriteI2C1(LowAdd); //Write Low Address IdleI2C1(); ErrorCode = ACKStatus(); //Return ACK Status ---> check ack WriteI2C1(data); //Write Data IdleI2C1(); StopI2C1(); //Initiate Stop Condition EEAckPolling(ControlByte); //Perform ACK polling return(ErrorCode); } /********************************************************************* * Function: LDByteReadI2C() * * Input: Control Byte, Address, *Data, Length. * * Output: None. * * Overview: Performs a low density read of Length bytes and stores in *Data array * starting at Address. * * Note: None ********************************************************************/ unsigned int LDByteReadI2C1(unsigned char ControlByte, unsigned char Address, unsigned char *Data, unsigned char Length) { IdleI2C1(); //wait for bus Idle StartI2C1(); //Generate Start Condition WriteI2C1(ControlByte); //Write Control Byte IdleI2C1(); //wait for bus Idle WriteI2C1(Address); //Write start address IdleI2C1(); //wait for bus Idle RestartI2C1(); //Generate restart condition WriteI2C1(ControlByte | 0x01); //Write control byte for read IdleI2C1(); //wait for bus Idle getsI2C1(Data, Length); //read Length number of bytes NotAckI2C1(); //Send Not Ack StopI2C1(); //Generate Stop // return(I2C1RCV); } /********************************************************************* * Function: HDByteWriteI2C() * * Input: ControlByte, HighAddr, LowAddr, Data. * * Output: None. * * Overview: perform a high density byte write of data byte, Data. * starting at the address formed from HighAdd and LowAdd * * Note: None ********************************************************************/ unsigned int HDByteWriteI2C1(unsigned char ControlByte, unsigned char HighAdd, unsigned char LowAdd, unsigned char data) { unsigned int ErrorCode; IdleI2C1(); //Ensure Module is Idle StartI2C1(); //Generate Start COndition WriteI2C1(ControlByte); //Write Control byte IdleI2C1(); ErrorCode = ACKStatus(); //Return ACK Status WriteI2C1(HighAdd); IdleI2C1(); //Write High Address WriteI2C1(LowAdd); //Write Low Address IdleI2C1(); ErrorCode = ACKStatus(); //Return ACK Status---> check ack WriteI2C1(data); //Write Data IdleI2C1(); StopI2C1(); //Initiate Stop Condition EEAckPolling(ControlByte); //perform Ack Polling return(ErrorCode); } /********************************************************************* * Function: HDByteReadI2C() * * Input: Control Byte, HighAdd, LowAdd, *Data, Length. * * Output: None. * * Overview: Performs a low density read of Length bytes and stores in *Data array * starting at Address formed from HighAdd and LowAdd. * * Note: None ********************************************************************/ unsigned int HDByteReadI2C1(unsigned char ControlByte, unsigned char HighAdd, unsigned char LowAdd, unsigned char *Data, unsigned char Length) { IdleI2C1(); //Wait for bus Idle StartI2C1(); //Generate Start condition WriteI2C1(ControlByte); //send control byte for write IdleI2C1(); //Wait for bus Idle WriteI2C1(HighAdd); //Send High Address IdleI2C1(); //Wait for bus Idle WriteI2C1(LowAdd); //Send Low Address IdleI2C1(); //Wait for bus Idle RestartI2C1(); //Generate Restart WriteI2C1(ControlByte | 0x01); //send control byte for Read IdleI2C1(); //Wait for bus Idle getsI2C1(Data, Length); //Read Length number of bytes to Data NotAckI2C1(); //send Not Ack StopI2C1(); //Send Stop Condition return(0); } /********************************************************************* * Function: LDPageWriteI2C() * * Input: ControlByte, LowAdd, *wrptr. * * Output: None. * * Overview: Write a page of data from array pointed to be wrptr * starting at LowAdd * * Note: LowAdd must start on a page boundary ********************************************************************/ unsigned int LDPageWriteI2C1(unsigned char ControlByte, unsigned char LowAdd, unsigned char *wrptr) { IdleI2C1(); //wait for bus Idle StartI2C1(); //Generate Start condition WriteI2C1(ControlByte); //send controlbyte for a write IdleI2C1(); //wait for bus Idle WriteI2C1(LowAdd); //send low address IdleI2C1(); //wait for bus Idle putstringI2C1(wrptr); //send data IdleI2C1(); //wait for bus Idle StopI2C1(); //Generate Stop return(0); } /********************************************************************* * Function: HDPageWriteI2C() * * Input: ControlByte, HighAdd, LowAdd, *wrptr. * * Output: None. * * Overview: Write a page of data from array pointed to be wrptr * starting at address from HighAdd and LowAdd * * Note: Address must start on a page boundary ********************************************************************/ unsigned int HDPageWriteI2C1(unsigned char ControlByte, unsigned char HighAdd, unsigned char LowAdd, unsigned char *wrptr) { IdleI2C1(); //wait for bus Idle StartI2C1(); //Generate Start condition WriteI2C1(ControlByte); //send controlbyte for a write IdleI2C1(); //wait for bus Idle WriteI2C1(HighAdd); //send High Address IdleI2C1(); //wait for bus Idle WriteI2C1(LowAdd); //send Low Address IdleI2C1(); //wait for bus Idle putstringI2C1(wrptr); //Send data---> ack will be cheked in this function IdleI2C1(); //wait for bus Idle StopI2C1(); //Generate a stop return(0); } /********************************************************************* * Function: LDSequentialReadI2C() * * Input: ControlByte, address, *rdptr, length. * * Output: None. * * Overview: Performs a sequential read of length bytes starting at address * and places data in array pointed to by *rdptr * * Note: None ********************************************************************/ unsigned int LDSequentialReadI2C1(unsigned char ControlByte, unsigned char address, unsigned char *rdptr, unsigned char length) { IdleI2C1(); //Ensure Module is Idle StartI2C1(); //Initiate start condition WriteI2C1(ControlByte); //write 1 byte IdleI2C1(); //Ensure module is Idle WriteI2C1(address); //Write word address IdleI2C1(); //Ensure module is idle RestartI2C1(); //Generate I2C Restart Condition WriteI2C1(ControlByte | 0x01); //Write 1 byte - R/W bit should be 1 for read IdleI2C1(); //Ensure bus is idle getsI2C1(rdptr, length); //Read in multiple bytes NotAckI2C1(); //Send Not Ack StopI2C1(); //Send stop condition // return(I2C1RCV); //Return data in buffer return(0); } /********************************************************************* * Function: HDSequentialReadI2C() * * Input: ControlByte, HighAdd, LowAdd, *rdptr, length. * * Output: None. * * Overview: Performs a sequential read of length bytes starting at address * and places data in array pointed to by *rdptr * * Note: None ********************************************************************/ unsigned int HDSequentialReadI2C1(unsigned char ControlByte, unsigned char HighAdd, unsigned char LowAdd, unsigned char *rdptr, unsigned char length) { IdleI2C1(); //Ensure Module is Idle StartI2C1(); //Initiate start condition WriteI2C1(ControlByte); //write 1 byte IdleI2C1(); //Ensure module is Idle WriteI2C1(HighAdd); //Write High word address IdleI2C1(); //Ensure module is idle WriteI2C1(LowAdd); //Write Low word address IdleI2C1(); //Ensure module is idle RestartI2C1(); //Generate I2C Restart Condition WriteI2C1(ControlByte | 0x01); //Write 1 byte - R/W bit should be 1 for read IdleI2C1(); //Ensure bus is idle getsI2C1(rdptr, length); //Read in multiple bytes NotAckI2C1(); //Send Not Ack StopI2C1(); //Send stop condition // return(I2C1RCV); return(0); } /********************************************************************* * Function: ACKStatus() * * Input: None. * * Output: Acknowledge Status. * * Overview: Return the Acknowledge status on the bus * * Note: None ********************************************************************/ unsigned int ACKStatus(void) { return (!I2C1STATbits.ACKSTAT); //Return Ack Status } /********************************************************************* * Function: NotAckI2C() * * Input: None. * * Output: None. * * Overview: Generates a NO Acknowledge on the Bus * * Note: None ********************************************************************/ void NotAckI2C1(void) { I2C1CONbits.ACKDT = 1; //Set for NotACk I2C1CONbits.ACKEN = 1; while(I2C1CONbits.ACKEN); //wait for ACK to complete I2C1CONbits.ACKDT = 0; //Set for NotACk } /********************************************************************* * Function: AckI2C() * * Input: None. * * Output: None. * * Overview: Generates an Acknowledge. * * Note: None ********************************************************************/ void AckI2C1(void) { I2C1CONbits.ACKDT = 0; //Set for ACk I2C1CONbits.ACKEN = 1; while(I2C1CONbits.ACKEN); //wait for ACK to complete } /********************************************************************* * Function: getsI2C() * * Input: array pointer, Length. * * Output: None. * * Overview: read Length number of Bytes into array * * Note: None ********************************************************************/ unsigned int getsI2C1(unsigned char *rdptr, unsigned char Length) { while (Length --) { *rdptr++ = getI2C1(); //get a single byte if(I2C1STATbits.BCL) //Test for Bus collision { return(-1); } if(Length) { AckI2C1(); //Acknowledge until all read } } return(0); } /********************************************************************* * Function: getI2C() * * Input: None. * * Output: contents of I2C1 receive buffer. * * Overview: Read a single byte from Bus * * Note: None ********************************************************************/ unsigned int getI2C1(void) { // while (I2C1STATbits.TRSTAT); //Wait for bus Idle I2C1CONbits.RCEN = 1; //Enable Master receive Nop(); while(!I2C1STATbits.RBF); //Wait for receive bufer to be full return(I2C1RCV); //Return data in buffer } /********************************************************************* * Function: EEAckPolling() * * Input: Control byte. * * Output: error state. * * Overview: polls the bus for an Acknowledge from device * * Note: None ********************************************************************/ unsigned int EEAckPolling(unsigned char control) { IdleI2C1(); //wait for bus Idle StartI2C1(); //Generate Start condition if(I2C1STATbits.BCL) { return(-1); //Bus collision, return } else { if(WriteI2C1(control)) { return(-3); //error return } IdleI2C1(); //wait for bus idle if(I2C1STATbits.BCL) { return(-1); //error return } while(ACKStatus()) { RestartI2C1(); //generate restart if(I2C1STATbits.BCL) { return(-1); //error return } if(WriteI2C1(control)) { return(-3); } IdleI2C1(); } } StopI2C1(); //send stop condition if(I2C1STATbits.BCL) { return(-1); } return(0); } /********************************************************************* * Function: putstringI2C() * * Input: pointer to array. * * Output: None. * * Overview: writes a string of data upto PAGESIZE from array * * Note: None ********************************************************************/ unsigned int putstringI2C1(unsigned char *wrptr) { unsigned char x; for(x = 0; x < PAGESIZE; x++) //Transmit Data Until Pagesize { if(WriteI2C1(*wrptr)) //Write 1 byte { return(-3); //Return with Write Collision } IdleI2C1(); //Wait for Idle bus if(I2C1STATbits.ACKSTAT) { return(-2); //Bus responded with Not ACK } wrptr++; } return(0); } |
|
|
|
对。你有一个函数,它说它返回一个整数,但是它没有。正如我所说的,是的,他们读了状态,但是不管它是什么,他们只是把它保存到一个叫做“Error Cal码”的变量中,然后继续前进。我看到在那里有一个叫做EEKOPPRIN()的函数,它可以做你需要的。EEPS发送重新启动直到接收到ACK。除了零以外的任何返回值意味着其他错误。
以上来自于百度翻译 以下为原文 Yes. You have the function, which says it returns an integer, but it doesn't. As I said, yes, they read the status, but regardless of what it was, they just save it into a variable called "ErrorCode", and keep going. I see there is a function in there called EEAckPolling() which does do what you need. It keeps sending restarts until it receives an ACK. Any return value other than zero means something else went wrong. |
|
|
|
那么在这种情况下我该怎么办呢?您的意思是函数ReII2C1应该返回ACSTATUSE?和WiTrRoCal码我该怎么办?这是我等待写作所需要的知识,我说的对吗?
以上来自于百度翻译 以下为原文 so in this case what should i do?you mean the function writeI2C1 should return ackstatuse?and with ErrorCode what should i do? it is the acknowladge pulling that i need for waiting to write be completed, am i right? |
|
|
|
那么在这种情况下我该怎么办呢?您的意思是函数ReII2C1应该返回ACSTATUSE?和WiTrRoCal码我该怎么办?我认为整件事都写得不好,但我没有时间或倾向重写它。这是我等待写作所需要的知识,我说的对吗?是的,我想是的。给它一个尝试。也就是说,在写一个页面之后调用它。如果它返回零,写就完成了,写下一个就可以了。如果它返回的不是0以外的东西,就出了问题,你需要研究为什么。
以上来自于百度翻译 以下为原文 so in this case what should i do?you mean the function writeI2C1 should return ackstatuse?and with ErrorCode what should i do? I think the whole thing is shoddily written, but I don't have the time or inclination to rewrite it all. it is the acknowladge pulling that i need for waiting to write be completed, am i right? Yes indeed, I think it is. Give it a try. i.e. call it after writing a page to the chip. If it returns zero, the write has finished and you are ok to write the next one. If it returns something other than zero, something has gone wrong and you need to investigate why. |
|
|
|
为什么在这个函数中使用“!”为什么它不返回ACK状态?然后,例如在ActheDeg牵引中使用它。如果函数ABOVIE2C1STATBATS.ACKSTAT=0,意味着从从属发送ACK,它返回1,对于下面的函数是否正确???????
以上来自于百度翻译 以下为原文 why in this function it is used "!"?why it return not of ack statuse? unsigned int ACKStatus(void) { return (!I2C1STATbits.ACKSTAT); //----> is it right that ???? } and then for example in acknowedg pulling it is used. if with the function above I2C1STATbits.ACKSTAT=0 that means slave sent ack , it returns 1 and is it correct for function below????? unsigned int EEAckPolling(unsigned char control) { IdleI2C1(); StartI2C1(); if(I2C1STATbits.BCL) { return(-1); } else { if(WriteI2C1(control)) { return(-3); } IdleI2C1(); if(I2C1STATbits.BCL) { return(-1); } while(ACKStatus())//---------------->**** here ***** { RestartI2C1(); if(I2C1STATbits.BCL) { return(-1); } if(WriteI2C1(control)) { return(-3); } IdleI2C1(); } } StopI2C1(); if(I2C1STATbits.BCL) { return(-1); } return(0); } |
|
|
|
你看过PIC的数据表了吗?特别是在I2C1STAT寄存器中记录比特的I2C章节。当接收到ACK时,AkStAT位为零,因此当该位为低时,函数返回true。
以上来自于百度翻译 以下为原文 Have you read the PIC18F Have you read the datasheet for your PIC? Particularly the I2C chapter which documents the bits in the I2C1STAT register. The ACKSTAT bit is zero when an ACK has been received, so that function is returning TRUE when that bit is low. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 09:58 , Processed in 1.665932 second(s), Total 114, Slave 98 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号