We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
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 */ }