Hello
I have tried to get i2c communication work with EEPROM. I have Easy PIC development board with 18f45k22 PIC installed
I have tried both the transmit and transaction components, but it doesnt work. In transmit mode I get ACK messages after every command, but the data from EEPROM in not valid, i get 255 in every case.( I dont know if its transfering at all), I think the PIC cant read the EEPROM now
I have also same problem with Modtronix SBC83IL board, the data doesnt transfer. I have tried many methods and also checked the EEPROM address is correct.
Here is mikroC Pro c code which works fine: ( when I made similar program with flowcode, it doesnt work.)
void main(){
ANSELB = 0; // Configure PORTB pins as digital
ANSELC = 0; // Configure PORTC pins as digital
TRISB = 0; // Configure PORTB as output
LATB = 0; // Clear PORTB
I2C1_Init(100000); // initialize I2C communication
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (address of EEPROM location)
I2C1_Wr(0xAA); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_100ms();
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA3); // send byte (device address + R)
LATB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
}
I2C communication problems with EEPROM
Moderator: Benj
-
- Posts: 31
- Joined: Wed May 02, 2012 5:49 pm
- Has thanked: 3 times
- Been thanked: 7 times
- Contact:
I2C communication problems with EEPROM
- Attachments
-
- Simple_i2c_flowcode.fcf
- (12.82 KiB) Downloaded 296 times
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: I2C communication problems with EEPROM
Hi,
Have you tried the attached example? Here mode is determining read or write..so if you can use switch to move between read and write..or you can simply read first and display in LCD and write then and display in LCD and read back again see whether it's written fine or not..
Have you tried the attached example? Here mode is determining read or write..so if you can use switch to move between read and write..or you can simply read first and display in LCD and write then and display in LCD and read back again see whether it's written fine or not..
- Attachments
-
- 3. EEPROM read and write.fcf
- (18.33 KiB) Downloaded 318 times
-
- Posts: 31
- Joined: Wed May 02, 2012 5:49 pm
- Has thanked: 3 times
- Been thanked: 7 times
- Contact:
Re: I2C communication problems with EEPROM
Hello,Enamul wrote:Hi,
Have you tried the attached example? Here mode is determining read or write..so if you can use switch to move between read and write..or you can simply read first and display in LCD and write then and display in LCD and read back again see whether it's written fine or not..
Yes I have also tried that method, but it doesnt work Strange thing is that I get ACK (0) return values OK, but the data seems not to transfer.
I dont understand why the simple C code is working OK, but when i make same on Flowcode it doesnt work. Is there some kind of a configuration issues? I have exactly same PIC config values with MikroC and Flowcode.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: I2C communication problems with EEPROM
Hi,
Your program has some problem and I have changed the configuration as well. It should work now..Data is what return..If you are receiving only one Byte 1 should be in last byte..
Your program has some problem and I have changed the configuration as well. It should work now..Data is what return..If you are receiving only one Byte 1 should be in last byte..
- Attachments
-
- Simple_i2c_flowcode.fcf
- (9 KiB) Downloaded 344 times
-
- Posts: 31
- Joined: Wed May 02, 2012 5:49 pm
- Has thanked: 3 times
- Been thanked: 7 times
- Contact:
Re: I2C communication problems with EEPROM
Thanks, Enamul
I didint notice the problem with Receive_byte component. I dont still understand meaning of "last" in that component.
I will check it tomorrow how it works.
I didint notice the problem with Receive_byte component. I dont still understand meaning of "last" in that component.
I will check it tomorrow how it works.
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
- Contact:
Re: I2C communication problems with EEPROM
That is basically the ack byte that the master sends, if it's 0, the transmission will continue, but if it's 1 the slave device knows that it was last byte of the transmission..zadah wrote:Thanks, Enamul
I dont still understand meaning of "last" in that component.
I will check it tomorrow how it works.
Mika