pic16f84 with 24c256 on i2c - simulation ok, real not working. oshonsoft pic ide

Status
Not open for further replies.

hitch

New Member
hi.

I am using the very old 16f84, supported by the old picstart i was donated. i am using a 4mhz crystal with 22pf caps. 5volts supplied via the 7805L.
i am trying to read write to the 24c256 to store bigger "files". I have followed both examples in the tutorial section but i get "nothing". I have no way of reading/writing to the 24c other than with the pic so i cannot verify either process. I have a serout routine to which works as it sends me text strings but not the data "read" back from the 24c.
pls help.
maybe clarify the read write statements. on how to read write multiple bytes?
thanks
 

Attachments

  • 16f84-24lc256.JPG
    19.1 KB · Views: 714
  • memtut.bas
    1.6 KB · Views: 432

hi,
Ref your PM, I assume you are using Oshonsoft.??
I will try your program
 
hi,
The program runs OK in simulation.
I will check out your delays.

EDIT:
The waits are too short, I will rewrite your program using the Basic I2C external EEprom commands. it will be easier for you to modify it.
 

Attachments

  • AAesp03.gif
    41.1 KB · Views: 528
Last edited:
hi,
I have modified the program, it works OK in sim.
I will try it in a PIC tomorrow and post the results.

Try this version.

EDIT:
Can you confirm that if you have the PIC serial output connected to the serial input of your PC, there is a line driver/inverter in the TXD serial data line to the PC.????
example: a MAX232 or equivalent.
 

Attachments

  • RSACPT1.bas
    1.1 KB · Views: 263
  • AAesp04.gif
    36.4 KB · Views: 434
Last edited:
hi,
The modified Basic program I posted yesterday works OK in a PIC, see image of PIC output on my PC.

Do you have the 2k2 pull up resistors on the sda and scl pins.??
Also the TXD line inverter.??
 

Attachments

  • RS232test1.gif
    13 KB · Views: 476
Hi thanks for the replies -

1. i am using a max232 on the tx and have "reliable" comms from the pic.
2. i am using a 10k on the sda / scl as it is in the spec sheet.

i am going to try your code now ! it is a beautiful sunny day here in SA and i know its gonna work!
 

hi,
Sunny SA, Port Elizabeth is my second home
Its running here fine as I type, I use 2k2 pu's

EDIT:

I assume you have the 25LC256 address pins all to 0V, for address 0.??


EDIT2:
Added image
 

Attachments

  • AAesp06.gif
    2.6 KB · Views: 373
Last edited:
I had initially tried the i2cread and i2cwrite commands but suspected that maybe they were not working, also i have made an error - the eeprom is the 24 "LC" 256 - the diff in the spec sheets show and extra A-address and the 24"C"256 has a NC. Also in your code (which i am about to try) does not change the control byte to 1010 0000 - A0 and the write 1010 0001 - A1. which is why i then tried the low level example.
thanks for the reply - i am off to try he code.
 

hi,
The pinout is like this image, the Basic should address the 24C256 OK, the A0,1,2 is in case you have more than one EEProm on the sda/scl lines.
 

Attachments

  • AAesp06.gif
    2.6 KB · Views: 378
Last edited:
Hi
the 24 lc 256 have all the A pins tied to gnd. - i read somewhere that i should not use portb.6 / portb.7, but if you say it is running then mi guess that is not a problem.
 
Hi
the 24 lc 256 have all the A pins tied to gnd. - i read somewhere that i should not use portb.6 / portb.7, but if you say it is running then mi guess that is not a problem.

hi,
In the basic command this is the EEProm IC address
I2CRead sda, scl, 0xa0, addr, data(addr)
so if A0,1,2 are grounded thats IC address 0xa0 for a second EEprom with A0 high it would be 0xa2

Where did you read about PB.6/7 pins.???


EDIT:
I think you are confusing the hardware address wiring with the Basic commands.
For only one EEprom connect A0,1,2 to 0V and use I2CRead sda, scl, 0xa0, addr, data(addr)

EDIT2:
Corrected the EEProm address for the 2nd EEprom from 0xa1 to 0xa2, the D0 bit of the address is the R/W bit.
Thanks for thr head up Mike.
 
Last edited:
so just to clarify:

if i have only 1 eeprom chip with a0-2 tied to gnd then the address will be 0xA0 for both read and write operations?
if you run this on the sim you will notice that when you use 0xA0 it say receiving... and then use the 0xA1 then it says transmitting...
that is what happens when i run the code i posted in the 1st post of this thread.

pin6 / 7 i read somewhere on the few hundred posts i have read, so i might be mistaken / have misread.

another sunny cape town morning - and back to the drawing board. will keep u posted.
 
hi,
Your links to 0V of A0,1,2 are correct for EEprom address '000'.

The EEprom I2C string "I2CWrite sda, scl, 0xa0, addr, data"
0xa0 is the address, in bit format it is: '1010,d3,d2,d1,R/W
So the 0xa is followed by 3 address bits,d3,d2,d1 [able to address up to 8 EEproms] and the least significant bit is the Read/Write bit.,,, Read is '1' and Write is '0'.

I have checked the datasheets for the B.6 & B.7 and I cannot see any reference to not using them for I2C, perhaps other members may know.???

Are you saying the Basic test program I posted is working in a PIC.??? its still connected up here and it works every time.

BTW: Dont use the word 'data' as a standard variable in your programs, MPLAB and OS get confused.
Use 'dta' or 'dat'
 
Last edited:
hi

the code you posted gets to the "beep" stage but i get no output on the comms. not even "nulls". I am busy double checking all my connections as the code looks perfect.

i just realised that i still had the 10k pull-ups on sda and scl - gonna swap them out now.
gonna burn the code to a fresh pic aswell.
 

hi,
If that rework dosn't fix the serial output problem, I suggest you write a simple serial output only test program.

For reference only this is a clip from the OS manual.
For example, for EEPROMs from 24C family (with device address inputs connected to ground) the value 0xA0 should be used for slave address parameter.
Both statements will take control over bit 0 of slave address during communication.
This means use 0xa0 for write and read in a OS basic program. the Basic will set the R/W bit correctly.

This image defines the normal addressing.
 

Attachments

  • AAesp01.gif
    35.6 KB · Views: 361
Hi eric
I have rebuild the circuit - using a fresh pic and eeprom

the pull-ups are 2k2

problem on the comms was a broken wire on the pc side of the db9. ;-) I checked that when the simple serout did not work.

also i changed the sda pin to Portb.4- that is the only thing i changed in your code.
I made the change because i use pin7 as the logic high for the switches on porta 0,1, 4
Rx = porta.2 and Tx = porta.3

However i am only running the code as you gave me - which should be fine.

alas still no output - now i can see the linefeeds but nothing comes up. in hyperterminal i can see the cursor move down but i get no other chars.

i would love to use another pic like the 628 or 88 but i cannot prg them on my picstart. and the 17c44 that i need to upgrade will only arrive in about 2weeks.

but i am not one to give up so easily just because i am hitting a brickwall. there must be an explanation why it is not working. here is a diagram of my connection again - i am using a 4mhz crystal with 22p caps. I do have (newly bought) 3pin resonators, would that make a diff?
 

Attachments

  • 16f84 - 24LC256 - Rework.JPG
    28.4 KB · Views: 808
just a note on the output of the prog. you gave me, when i set the baud to 1200 the output pattern looks correct, so i can safely say that the serout is working. I know the baud is 2400 but on 2400 i can only "see" the CRLF's. I have again double checked the wiring of my circuit. and i am going to "half" your program and burn the WRITE on one chip and the READ on another. Then swap between the two and see what that does. I am trying everything to find this problem. It would have been cool if i could read the eeprom without the pic, then we would know if the eeprom is atleast being written to which would narrow down the problem.
 

hi hitch,
Post the program you are now trying, I will run it here.

EDIT:

Unzip this zip, its an avi file showing your program running in a 16F84A, with the B7 to B.4 change.
 

Attachments

  • lighty1.zip
    38.5 KB · Views: 239
Last edited:
here is the code...

hi,
Compiled that basic, programmed a 16F84A, plug into project board, works OK.

Have you a new PIC and EEProm to try in your board.
I assume that you have pin4 connected to +5V via resistor and your PCB has decoupling caps.???
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…