Home
Forums
New posts
Search forums
What's new
New posts
Latest activity
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
All Topics
Education
Physics
eeprom read problem on dsp33ep512mu810
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="bruce wayne" data-source="post: 739823"><p>When I try to read from eeprom it is working properly first time after that it is not working. It is stuck at [ICODE]while (!I2C2STATbits.RBF);[/ICODE]. Please suggest a solution for this problem.</p><p></p><p>[CODE]void I2CEMEMinit( I2CEMEM_DRV *i2cMem )</p><p>{</p><p> ODCFbits.ODCF4 = 0;</p><p> ODCFbits.ODCF5 = 0;</p><p>I2C1CONbits.I2CEN = 0;</p><p> I2C1CONbits.A10M = 0;</p><p> I2C1CONbits.SCLREL = 1;</p><p> I2C1BRG = 300;</p><p></p><p> I2C1ADD = 0;</p><p> I2C1MSK = 0;</p><p></p><p> I2C1CONbits.I2CEN = 1;</p><p> IEC1bits.MI2C1IE = 0;</p><p> IFS1bits.MI2C1IF = 0;</p><p>}</p><p></p><p>int eepRead(uint16_t addr, uint8_t *data, int numbytes)</p><p>{</p><p> // Start Condition</p><p> I2C2CONbits.ACKDT = 0;</p><p> I2C2CONbits.SEN = 1;</p><p> while (I2C2CONbits.SEN);</p><p></p><p> // Send Device Address with Write Flag (0xA0)</p><p> I2C2TRN = 0xA0;</p><p> while (I2C2STATbits.TBF);</p><p> while (I2C2STATbits.TRSTAT);</p><p></p><p> // Send Memory Address (High Byte and Low Byte)</p><p> I2C2TRN = (addr & 0xFF00) >> 8;</p><p> while (I2C2STATbits.TBF);</p><p> while (I2C2STATbits.TRSTAT);</p><p> </p><p> I2C2TRN = addr & 0x00FF;</p><p> while (I2C2STATbits.TBF);</p><p> while (I2C2STATbits.TRSTAT);</p><p></p><p> // Repeated Start Condition</p><p> I2C2CONbits.RSEN = 1;</p><p> while (I2C2CONbits.RSEN);</p><p></p><p> // Send Device Address with Read Flag (0xA1)</p><p> I2C2TRN = 0xA1;</p><p> while (I2C2STATbits.TBF);</p><p> while (I2C2STATbits.TRSTAT);</p><p></p><p> // Read Data</p><p> while (numbytes)</p><p> {</p><p> I2C2CONbits.RCEN = 1;</p><p> I2C2STATbits.I2COV = 0;</p><p> while (!I2C2STATbits.RBF);</p><p> *data++ = I2C2RCV;</p><p> numbytes--;</p><p></p><p> // Send ACK</p><p> if (numbytes)</p><p> {</p><p> I2C2CONbits.ACKDT = 0;</p><p> I2C2CONbits.ACKEN = 1;</p><p> while (I2C2CONbits.ACKEN);</p><p> }</p><p> }</p><p></p><p> // Send NACK</p><p> I2C2CONbits.ACKDT = 1;</p><p> I2C2CONbits.ACKEN = 1;</p><p> while (I2C2CONbits.ACKEN);</p><p></p><p> // Stop Condition</p><p> I2C2CONbits.PEN = 1;</p><p> while (I2C2CONbits.PEN);</p><p></p><p> return 0;</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="bruce wayne, post: 739823"] When I try to read from eeprom it is working properly first time after that it is not working. It is stuck at [ICODE]while (!I2C2STATbits.RBF);[/ICODE]. Please suggest a solution for this problem. [CODE]void I2CEMEMinit( I2CEMEM_DRV *i2cMem ) { ODCFbits.ODCF4 = 0; ODCFbits.ODCF5 = 0; I2C1CONbits.I2CEN = 0; I2C1CONbits.A10M = 0; I2C1CONbits.SCLREL = 1; I2C1BRG = 300; I2C1ADD = 0; I2C1MSK = 0; I2C1CONbits.I2CEN = 1; IEC1bits.MI2C1IE = 0; IFS1bits.MI2C1IF = 0; } int eepRead(uint16_t addr, uint8_t *data, int numbytes) { // Start Condition I2C2CONbits.ACKDT = 0; I2C2CONbits.SEN = 1; while (I2C2CONbits.SEN); // Send Device Address with Write Flag (0xA0) I2C2TRN = 0xA0; while (I2C2STATbits.TBF); while (I2C2STATbits.TRSTAT); // Send Memory Address (High Byte and Low Byte) I2C2TRN = (addr & 0xFF00) >> 8; while (I2C2STATbits.TBF); while (I2C2STATbits.TRSTAT); I2C2TRN = addr & 0x00FF; while (I2C2STATbits.TBF); while (I2C2STATbits.TRSTAT); // Repeated Start Condition I2C2CONbits.RSEN = 1; while (I2C2CONbits.RSEN); // Send Device Address with Read Flag (0xA1) I2C2TRN = 0xA1; while (I2C2STATbits.TBF); while (I2C2STATbits.TRSTAT); // Read Data while (numbytes) { I2C2CONbits.RCEN = 1; I2C2STATbits.I2COV = 0; while (!I2C2STATbits.RBF); *data++ = I2C2RCV; numbytes--; // Send ACK if (numbytes) { I2C2CONbits.ACKDT = 0; I2C2CONbits.ACKEN = 1; while (I2C2CONbits.ACKEN); } } // Send NACK I2C2CONbits.ACKDT = 1; I2C2CONbits.ACKEN = 1; while (I2C2CONbits.ACKEN); // Stop Condition I2C2CONbits.PEN = 1; while (I2C2CONbits.PEN); return 0; } [/CODE] [/QUOTE]
Name
Verification
Post reply
Home
Forums
All Topics
Education
Physics
eeprom read problem on dsp33ep512mu810
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top