problems working with 24C512


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Posts
    29

    Exclamation problems working with 24C512

    Dear fellows

    Im facing problems working with 24C512 eeprom. Im posting here my coding. IN simulation, it seems to work fine on proteus but in the real it doesnt. Herez my coding.

    Include "Modedefs.Bas"

    ' ** Setup the Crystal Frequency, in Mhz **

    Define OSC 4 ' Set Xtal Frequency

    ' ** Setup the I2C configuration **

    Define I2C_SCLOUT 1 ' No need for the pullup resistor on the SCL pin


    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 25

    ' Set LCD Data port
    DEFINE LCD_DREG PORTB
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 0
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTC
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 0
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTC
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 1
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 8
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50

    ' ** Declare the Variables **

    SCL Var PortD.0 ' I2C data pin
    SDA Var PortD.1 ' I2C clock pin
    Addr Var Word ' 16-bit memory address within the Eeprom
    E_ByteOut Var Byte ' Data byte to be written to the Eeprom
    E_ByteIn Var Byte ' Data byte read from the Eeprom
    x var byte
    ' ** The main program starts here **

    ' Write the string, "HELLO WORLD" into the first 11 address's of the Eeprom

    For Addr=0 To 10 ' Create a loop of 11
    Lookup Addr,[1,255,222,134,10,1,13,19,10,99,219],E_ByteOut' Build up the string
    Gosub EWrite ' Write the byte to the Eeprom
    Next ' Close the Loop

    ' Read the first 11 address's within the Eeprom,
    ' and display them on the LCD

    Again:
    lcdout $FE,1, "starting"
    Pause 1000 ' Clear the LCD
    Pause 500 ' Pause for drama
    For Addr=0 To 10 ' Create a loop of 11
    Gosub ERead ' Read the byte from the Eeprom
    hserout [dec e_bytein,13,10]
    pause 100
    lcdout $FE,1,#E_bytein
    ' Print the characters read in from the eeprom
    Pause 2000 ' Pause inbetween displays, for drama
    Next ' Close the loop
    Goto Again ' Do it forever

    ' ** SUBROUTINES **


    EWrite:
    I2CWRITE SDA,SCL,%10100000,Addr,[E_ByteOut] ' Write out the byte
    Pause 10 ' Delay 10ms after each write
    Return

    ERead:
    I2CREAD SDA,SCL,%10100001,Addr,[E_ByteIn] ' Read in the byte
    Return

    The problem im facing is this that the LCD displays "starting" and then instead of displaying the values it read from the eeprom, it displays just 2.

    PLease help me what to do here. I have tried addr.highbyte addr.lowbyte, took control as a byte variable. But nothing seems to work here.
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Maybe you're missing pull-ups on SDA and SCL?

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    ' ** Setup the I2C configuration **
    
    Define I2C_SCLOUT 1 ' No need for the pullup resistor on the SCL pin
    Not sure if it works without pull-up with this define...

    BUT if you receive always 2, maybe you reverted your SDA, SCL line as well.. who knows?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Dear jerson and mister e

    i have rechecked my connections, they are correct. I dont know where is the problem. I have even grounded WP which i havent done before. One more technical aspect that i want to tell you that i have connect WP and A0 and A1 directly to ground i.e. no pull down resistors. IS this making the problem. If any one of you have a working circuit of 24C512 with PIC, please send it so that i can rechecked my connections. Please send me coding as well.
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shaiqbashir View Post
    no pull down resistors
    Pull DOWN resistors? Don't remember anything about Pull DOWN resistors.

    If any one of you have a working circuit of 24C512 with PIC, please send it so that i can rechecked my connections
    The '512 datasheet I've got has a fairly good schematic. What's your datasheet say?

    Please send me coding as well.
    ???????????????????????????????????????????????
    Not asking for much eh?
    Last edited by skimask; - 28th May 2008 at 18:04.

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Are you sure your PIC is working? Any test pins that you can blink / toggle to make sure ? I think you have all the coding right including the pin config. I doubt your watchdog / brownout is killing the code execution. This can be ruled out if you can blink a test pin every time you read

Similar Threads

  1. PIC30f4012 Problems
    By Insane in forum mel PIC BASIC
    Replies: 4
    Last Post: - 18th June 2010, 07:16
  2. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  3. lcd menu problems
    By xxxxxx in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd April 2009, 19:00
  4. 2 PWM in 16F690 problems
    By ciendavila in forum mel PIC BASIC
    Replies: 9
    Last Post: - 27th April 2008, 09:03
  5. Why is this so hard? HSEROUT problems.
    By groston in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th November 2006, 13:01

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts