Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 03:45:58 15:45


Login with username, password and session length


Pages: [1]
Print
Author Topic: Please help me for VERY SIMPLE problem Proteus/Mikrobasic (or MikroC)  (Read 7637 times)
0 Members and 1 Guest are viewing this topic.
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« on: November 25, 2010, 09:50:29 21:50 »

Hi all

I try a very simple test to verify I2C on proteus 7.7


You can download proteus file here: http://rapidshare.com/files/433119788/PIC16F877A.DSN

Now here is the code I'm trying

Code:
program PIC16F877A


  dim ValeurLue as byte
  
sub function LireEeprom as byte
  I2C1_Start() '              // issue I2C start signal
  I2C1_Wr($A2) '              // send byte via I2C  (device address + W)
  I2C1_Wr(2) '                // send byte (data address)
  I2C1_Repeated_Start() '     // issue I2C signal repeated start
  I2C1_Wr($A3) '              // send byte (device address + R)
  delay_ms(30)
  Result = I2C1_Rd(0) '       // Read the data (NO acknowledge)
  I2C1_Stop() '               // issue I2C stop signal
end sub

sub procedure EcrireEeprom (dim Valeur as byte)
  I2C1_Start()'               // issue I2C start signal
  I2C1_Wr($A2) '               // send byte via I2C  (device address + W)
  I2C1_Wr(2) '                 // send byte (address of EEPROM location)
  I2C1_Wr(Valeur) '               // send data (data to be written)
  I2C1_Stop() '                // issue I2C stop signal
end sub

sub procedure Clignoter(dim Nbre as byte)
  dim x as byte

  for x=1 to Nbre
    portB.0=1
    delay_ms(500)
    PortB.0=0
    delay_ms(500)
  next x
end sub

main:

  TRISA = 0
  TRISB = 0 ' configure PORTB as output
  TRISD=0
  
  I2C1_Init(100000) '          // initialize I2C communication

  Delay_100ms() '

  ValeurLue=0
  EcrireEeprom(5)
  ValeurLue=LireEeprom
  while true
    Clignoter(5)
    delay_ms(2000)
  wend
end.

The problem is that it didn't work !

If I'm trying this, it's because I unable to use ("hard", with mikrobasic or mikroC) I2C . I have no problem when I use soft I2C (!!??) with PIC18F4553

So could someone try this so and tell me about errors I'm doing ?

Here, on this small test, I set HS mode and 8Mhz crystal.
On the real application I use PIC18F4523 and 20Mhz crystal (any many other devices). Both of them doesn't work, they freeze as soon I ask for I2C.


THANKS A LOT FOR HELPING ME

Logged
odsk
Junior Member
**
Offline Offline

Posts: 53

Thank You
-Given: 13
-Receive: 12


« Reply #1 on: November 25, 2010, 11:12:23 23:12 »

I found what is wrong,
under properties of the pull up resistor change their properties to DIGITAL instead of Analog.
second thing I have done is to chang the write time delay of the eeprom to 1n instead of 1m.

Logged
mario2000
Active Member
***
Offline Offline

Posts: 162

Thank You
-Given: 330
-Receive: 515


« Reply #2 on: November 25, 2010, 11:21:45 23:21 »

a0 pin must connect to gnd.



Code:
     I2C_Init(100000);
// How To write example
   i2c_start();
   i2c_wr(0b10100000);  // we started directing the eeprom
   i2c_wr(0x00);  // address to write
   i2c_wr(0x22);  // data
   i2c_stop();

//How to read example
short dato;
   i2c1_start();
   i2c1_wr(0b10100000);  // we started directing the eeprom
   i2c1_wr(addres);  // address to write
   I2C1_Repeated_Start();  // Issue I2C signal repeated start
   i2c1_wr(0b10100001);  //
   dato = I2C1_Rd(0);    // Read the data (NO acknowledge)
   i2c1_stop();
Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #3 on: November 25, 2010, 11:23:10 23:23 »

ODSK write:
"I found what is wrong,
under properties of the pull up resistor change their properties to DIGITAL instead of Analog.
second thing I have done is to chang the write time delay of the eeprom to 1n instead of 1m."


THANKS A LOT

So, if I understand correctly, it's because soft I2C is slow comparing with real hard I2C and, when I'm asking for I2C devices, I must have a short timing to see good "answer".

But what is the reason for "digital" resistors ?

Thanks again. I was very unable to find a solution for this and was planning to use soft I2C


Logged
odsk
Junior Member
**
Offline Offline

Posts: 53

Thank You
-Given: 13
-Receive: 12


« Reply #4 on: November 25, 2010, 11:28:40 23:28 »

Mario,
I don't think using a diffrent address for the eeprom is the issue here. you have a lot of possible addresses with a system with multiple eeproms. His cirsuit is good except the minor changes I mentioned in my post above.

Regards,
ODSK

Posted on: November 26, 2010, 12:26:02 00:26 - Automerged

It did happen to me ones. with proteus.
I had a circuit pic and DS1307 I was not able to do the simulation without including the I2c debugger and I remove it the debugger the whole ssytem will hang...etc.
after several tries when I did change the resistor type to digital and the simualtion could work as expected without having the debugger. In real live of course it will work.
Did you try my recommendations?
ODSK
ODSK write:
"I found what is wrong,
under properties of the pull up resistor change their properties to DIGITAL instead of Analog.
second thing I have done is to chang the write time delay of the eeprom to 1n instead of 1m."


THANKS A LOT

So, if I understand correctly, it's because soft I2C is slow comparing with real hard I2C and, when I'm asking for I2C devices, I must have a short timing to see good "answer".

But what is the reason for "digital" resistors ?

Thanks again. I was very unable to find a solution for this and was planning to use soft I2C



Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #5 on: November 26, 2010, 12:22:03 00:22 »

ODSK

Posted on: November 26, 2010, 12:26:02 00:26 - Automerged

It did happen to me ones. with proteus.
I had a circuit pic and DS1307 I was not able to do the simulation without including the I2c debugger and I remove it the debugger the whole ssytem will hang...etc.
after several tries when I did change the resistor type to digital and the simualtion could work as expected without having the debugger. In real live of course it will work.
Did you try my recommendations?
ODSK

Of course I did !  Wink that's why I'm so happy.
I was thinking my schematics would run in real configuration but it will be to risked ordering PCB without a good simulation control.

Thanks again
MOD EDIT:Start to use the Thankyou Button
« Last Edit: November 26, 2010, 12:53:40 00:53 by Wizpic » Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #6 on: November 26, 2010, 02:06:58 02:06 »

Sorry for "thank you" button. Done.
Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #7 on: November 26, 2010, 02:34:19 14:34 »

Hem ....  Embarrassed can I ?

Why my complete soft it doesn't work correctly with I2C, even with "digital" resistors on I2C
I put an I2C debugger and I have this :



If someone want to test (with proteus/Mikrobasic)

« Last Edit: November 27, 2010, 01:18:14 13:18 by orpheedulogis » Logged
odsk
Junior Member
**
Offline Offline

Posts: 53

Thank You
-Given: 13
-Receive: 12


« Reply #8 on: November 27, 2010, 01:55:04 01:55 »

Check the RS line it is connected to SCL.
After removing the wrong wire you will have your circuit simlation running.
Not 100% as after a while it start to malfunction (maybe something in the code...etc)

The wire that I removed was instead of the red line.
ODSK
Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #9 on: November 27, 2010, 01:17:38 13:17 »

Grr .....  Angry

Stupid I am !!!
This is because I changed PIC4553 to PIC4523 and (soft)I2C where at the other side so I had to deplace wires (and doesn't verify correctly)
Lost many hours ... but thanks a lot  ODSK Cool  I had to modify Eeprom acces time and resistors too.
« Last Edit: November 27, 2010, 01:20:08 13:20 by orpheedulogis » Logged
mario2000
Active Member
***
Offline Offline

Posts: 162

Thank You
-Given: 330
-Receive: 515


« Reply #10 on: November 28, 2010, 03:32:54 15:32 »

Please can someone tell me how to set the digital resistance, it can not find where.
Logged
odsk
Junior Member
**
Offline Offline

Posts: 53

Thank You
-Given: 13
-Receive: 12


« Reply #11 on: November 28, 2010, 05:00:03 17:00 »

Mario,
I am using 7.7 (but even in 7.6 it has the same feature).
right click/ select edit properties and you have the same a below

Logged
mario2000
Active Member
***
Offline Offline

Posts: 162

Thank You
-Given: 330
-Receive: 515


« Reply #12 on: November 28, 2010, 05:51:19 17:51 »

ok, I understanding, but you must use a generic resistor, as not all models have this property, then so is that I can remove the debugger I2c  Wink
Logged
shibuv
Newbie
*
Offline Offline

Posts: 30

Thank You
-Given: 0
-Receive: 7


WWW
« Reply #13 on: December 05, 2010, 06:41:46 18:41 »

see this Link

Real time Clock Interface with ccs C
http://www.keralalinux.com/2010/12/05/real-time-clock-ds1307-using-pic16f877a-and-ccs-c.html
Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #14 on: December 05, 2010, 07:53:18 19:53 »

Thanks shibuv but problems has been found:

1) must use "digital" résistors for I2C with proteus
2) configure port C so Sda and Scl pins are inputs
3) stupid wire connection error (RS connected to scl)

Actually all I2C components works perfectly . For soft, may have some errors but they just come from PIC18F4553 to PIC18F4523 adaptation (clock, Eeprom ... were OK).

Here a capture: soft works perfectly with no delay


Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC