SHANTHI5555
Newbie level 3
- Joined
- Dec 24, 2014
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 44
hi
i am working on a real time project using I2C EEPROM AT24C512.
For EEPROM AT24C512 testing i wrote code in QuatusII - Nios.
and it is working fine when it is in sequence commands.
then i tried it as functions. and i wrote initialize,write, and read functions. And these functions are called in main functions. now i am not getting correct output.
the code is copied below
i don't know that what is the problem in that. please tell about this.
thank you...
i am working on a real time project using I2C EEPROM AT24C512.
For EEPROM AT24C512 testing i wrote code in QuatusII - Nios.
and it is working fine when it is in sequence commands.
then i tried it as functions. and i wrote initialize,write, and read functions. And these functions are called in main functions. now i am not getting correct output.
the code is copied below
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 #include "system.h" #include "stdio.h" #include "io.h" unsigned int initiate(); unsigned int i2c_write(unsigned int ,unsigned int ); unsigned int i2c_read(unsigned int ); void Delay(unsigned int,unsigned int); #define I2C_PRER0 0x00 #define I2C_PRER1 0x04 #define I2C_CTR 0x08 #define I2C_TXR 0x0C #define I2C_RXR 0x0C #define I2C_CR 0x10 #define I2C_SR 0x10 #define PRER_0 0x09 #define PRER_1 0x00 #define SLAVE_ADDR_WR 0XA0 #define SLAVE_ADDR_RD 0XA1 unsigned int TIP[8]; unsigned int out_data; unsigned int i; int main() { unsigned int i; unsigned int in_data=0XBB; unsigned int mem_addr=0x01; initiate(); for(i=0x00;i<=0X10;i++) { i2c_write(mem_addr,0xFF); i2c_write(mem_addr,in_data); i2c_read(mem_addr); in_data-in_data+0x01; } return 0; } unsigned int initiate() { IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_PRER0,0x09); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_PRER1,0x00); IOWR_32DIRECT(WB_CYC_I_BASE,I2C_CTR,0x01); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CTR,0x80); return 0; } unsigned int i2c_write(unsigned int mem_addr,unsigned int in_data) { IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,0XA0); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X90); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF)) ; while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,mem_addr); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X10); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF)); while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,in_data); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X10); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF)); printf("\n mem_addr %X , in_data %X",mem_addr,in_data); while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X50); return 0; } unsigned int i2c_read(unsigned int mem_addr) { IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,0XA0); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X90); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF)) ; while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,mem_addr); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X10); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF)); while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_TXR,0XA1); IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X90); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0XFF) ); while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X20); Delay(1,1); TIP[8]= (IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_SR)&(0xFF) ); printf("\n out_data = %X",IORD_32DIRECT(I2C_PIO_HW_0_BASE,I2C_RXR)); while(TIP[1] != 0) { ; } IOWR_32DIRECT(I2C_PIO_HW_0_BASE,I2C_CR,0X28); return 0; } void Delay(unsigned int a,unsigned int b) { unsigned int x,y; for(x=0;x<=a;x++) { for(y=0;y<=b;y++) { } } }
i don't know that what is the problem in that. please tell about this.
thank you...
Last edited by a moderator: