Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C problem in MikroC example

Status
Not open for further replies.

kimsan

Newbie level 5
Joined
Oct 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,344
I m just learning MikroC with pic 16F887. I try to use MikroC example to simulate with proteus. but it doesn't work i don know why?
please help me. when i compile it succes but when i try to simulate with proteus it doen't show me any working. By using mikroc function how may clock oscilator should we used?

/* In this example, PIC MCU is connected to 24C02 EEPROM via SCL and SDA pins. The program
sends one byte of data to the EEPROM address 2. Then, it reads that data via I2C from
EEPROM and sends it to PORTB in order to check if the data was successfully written. */

void main(){
ANSEL = ANSELH = PORTB = TRISB = 0; // All pins are digital. PORTB pins are outputs.
I2C1_Init(100000); // Initialize I2C with desired clock
I2C1_Start(); // I2C start signal
I2C1_Wr(0xA2); // Send byte via I2C (device address + W)
I2C1_Wr(2); // Send byte (address of EEPROM location)
I2C1_Wr(0xF0); // Send data to be written
I2C1_Stop(); // I2C stop signal

Delay_100ms();

I2C1_Start(); // 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)
PORTB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // I2C stop signal
}
 

I m just learning MikroC with pic 16F887. I try to use MikroC example to simulate with proteus. but it doesn't work i don know why?
please help me. when i compile it succes but when i try to simulate with proteus it doen't show me any working. By using mikroc function how may clock oscilator should we used?

/* In this example, PIC MCU is connected to 24C02 EEPROM via SCL and SDA pins. The program
sends one byte of data to the EEPROM address 2. Then, it reads that data via I2C from
EEPROM and sends it to PORTB in order to check if the data was successfully written. */

void main(){
ANSEL = ANSELH = PORTB = TRISB = 0; // All pins are digital. PORTB pins are outputs.
I2C1_Init(100000); // Initialize I2C with desired clock
I2C1_Start(); // I2C start signal
I2C1_Wr(0xA2); // Send byte via I2C (device address + W)
I2C1_Wr(2); // Send byte (address of EEPROM location)
I2C1_Wr(0xF0); // Send data to be written
I2C1_Stop(); // I2C stop signal

Delay_100ms();

I2C1_Start(); // 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)
PORTB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // I2C stop signal
}


You need to set up the pull up resistors in proteus as digital and attached the I2C Analyzer on the bus =)
 

I have following you that set up pull up resistors already. but it still doesn't work. i don't know why?
 

Doesn't work - means nothing. Where is the project? In proteus you have a I2c debugger for example, internal cpu diagnostics messages. How I can check what exactly doesn't work?
I truly believe that MikroE's examples works.
 
  • Like
Reactions: kimsan

    kimsan

    Points: 2
    Helpful Answer Positive Rating
This is because, most of the time proteus will not give output to i2c standard. If we are using the same example in a real hardware situation, it will give output corresctly.. I had a similar problem with RTC(DS1037) and EEPROM(24c1024). Proteus simulation was a failure, but the pcb gave the output as I expected. Do it in a real board..
 

thank i will try on board test.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top