This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FM24C256

Hello there,

Please help me, i am looking for a code using CodeVision on How to store and read data from FRAM(FM24C256)...im waiting for your reply.. Thanks in advance...........

Bryan

  • How would CodeVision affect the way that an FM24C256 works?

    Have you read the FM24C256 Datasheet?

  • This connects up as an I2C device. Look at the data sheet for the device, it explains what is required to communicate with the device.

    I have been using the SPI parts for years. Same protocol, difference interface.

  • an I2C device. ... the SPI parts for years. Same protocol, difference interface.

    NO WAY, the protocol is totally, absolutely, completely different.

    One added point: there are '51 derivatives galore ($1 up) that have harware IIC and/or SPI interfaces and the code for those (except for the SILabs f3x, f4x, f5x Deviates) is either ready when done with CodeArchitect, free from http://www.esacademy.com or can be modified to fit in 15 minutes or less.

    Bit-banging, while it does handle the protocol (code 'examples' all over), is very likely to cause other problems because it hangs the processor during the transfer.

    Erik

  • Sequence of outputing bytes is what I referred to as protocol. Transfering bytes to the device is the hardware layer, spi, i2c, etc.

  • I posted the code,there is a problem in writing and reading. it doesn't display to the hyperterminal the data on FM24C256..please check it if something problem with my code...thanks

    The Code:

    /* the I2C bus is connected to PORTB */
    /* the SDA signal is bit 3 */
    /* the SCL signal is bit 4 */

    #asm .equ __i2c_port=0x18 .equ __sda_bit=3 .equ __scl_bit=4
    #endasm

    /* now you can include the I2C Functions */
    #include <i2c.h>

    #include <mega16.h>
    #include <stdio.h>

    #define FRAM_BUS_ADDRESS 0xa0

    /* read a byte from the FRAM */
    unsigned char fram_read(unsigned char address)
    { unsigned char data;

    i2c_start(); i2c_write(FRAM_BUS_ADDRESS); //i2c_write((FRAM_BUS_ADDRESS|(int)&0xFE)); //i2c_write(address+1); i2c_write(address); i2c_start(); i2c_write(FRAM_BUS_ADDRESS|1); data=i2c_read(0); i2c_stop(); return data;

    }

    /* write a byte to the FRAM */
    void fram_write(unsigned char address, unsigned char data)
    { i2c_start(); i2c_write(FRAM_BUS_ADDRESS); //i2c_write((FRAM_BUS_ADDRESS|(int)0xFE)); //i2c_write(address+1); i2c_write(address); i2c_write(data); i2c_stop();
    }

    void main(void)
    { unsigned char i;

    PORTB = 0b00000000; DDRB = 0b00000000;

    /*-HW UART-*/ UCSRA = 0x00; UCSRB = 0x18; UCSRC = 0x86; UBRRH = 0x00; UBRRL = 0x17;

    /* initialize the I2C bus */ i2c_init();

    /* write the byte 55h at address AAh */ fram_write(0xaa,0x55);

    /* read the byte from address AAh */ i=fram_read(0xaa);

    /*--------------------------------------------*/ if (i=='\0'){ printf("\rFRAM is Empty...\r"); } else{ printf("\rData stored in FRAM : %c \r",i); } /*--------------------------------------------*/

    while (1); /* loop forever */
    }

  • Edited Code:

    /* the I2C bus is connected to PORTB */
    /* the SDA signal is bit 3 */
    /* the SCL signal is bit 4 */
    
    #asm
        .equ __i2c_port=0x18
        .equ __sda_bit=3
        .equ __scl_bit=4
    #endasm
    
    /* now you can include the I2C Functions */
    #include <i2c.h>
    
    #include <mega16.h>
    #include <stdio.h>
    
    #define FRAM_BUS_ADDRESS 0xa0
    
    /* read a byte from the FRAM */
    unsigned char fram_read(unsigned char address)
    {
      unsigned char data;
    
      i2c_start();
      i2c_write(FRAM_BUS_ADDRESS);
      //i2c_write((FRAM_BUS_ADDRESS|(int)&0xFE));
      //i2c_write(address+1);
      i2c_write(address);
      i2c_start();
      i2c_write(FRAM_BUS_ADDRESS|1);
      data=i2c_read(0);
      i2c_stop();
      return data;
    
    }
    
    /* write a byte to the FRAM */
    void fram_write(unsigned char address, unsigned char data)
    {
      i2c_start();
      i2c_write(FRAM_BUS_ADDRESS);
      //i2c_write((FRAM_BUS_ADDRESS|(int)0xFE));
      //i2c_write(address+1);
      i2c_write(address);
      i2c_write(data);
      i2c_stop();
    }
    
    void main(void)
    {
      unsigned char i;
    
      PORTB = 0b00000000;
      DDRB  = 0b00000000;
    
      /*-HW UART-*/
      UCSRA = 0x00;
      UCSRB = 0x18;
      UCSRC = 0x86;
      UBRRH = 0x00;
      UBRRL = 0x17;
    
      /* initialize the I2C bus */
      i2c_init();
    
      /* write the byte 55h at address AAh */
      fram_write(0xaa,0x55);
    
      /* read the byte from address AAh */
      i=fram_read(0xaa);
    
      /*--------------------------------------------*/
      if (i=='\0'){
           printf("\rFRAM is Empty...\r");
         }
      else{
           printf("\rData stored in FRAM : %c \r",i);
         }
      /*--------------------------------------------*/
    
      while (1); /* loop forever */
    }
    

  • "there is a problem in writing and reading. it doesn't display to the hyperterminal"

    How have you confirmed that the problem is due to writing and reading, and not due to your serial coms?

  • You said initially that you're using CodeVision - which is not a Keil product

    Your code looks like it's for an AVR:

    #include <mega16.h>
    

      PORTB = 0b00000000;
      DDRB  = 0b00000000;
    
      /*-HW UART-*/
      UCSRA = 0x00;
      UCSRB = 0x18;
      UCSRC = 0x86;
      UBRRH = 0x00;
      UBRRL = 0x17;
    

    Keil tools do not support the AVR.

    So why are you posting this in the Keil forum?
    http://www.keil.com/forum/

    The forum you need for the AVR is: http://www.avrfreaks.net/