Dineshpuppy
Newbie level 1
There is a issue regarding code in eeprom. while in debug mode it was showing issue at " if(I2C_transfer(i2cHandle, &i2cTransaction)) " it was not going inside i2c_transfer. I am sharing the code above. please give me a solution to fix it. I modified the i2ctmp007 example code and wrote eeprom by removing temp code.
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 /* * ======== eeprom.c ======== */ #include <stdint.h> #include <stddef.h> #include <unistd.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/I2C.h> /* Example/Board Header files */ #include "Board.h" #include "System.h" /* Slave Addresses */ //i2cTransaction.slaveAddress = 0xA0 >>1; //i2cTransaction.slaveAddress = 0xA1 >>1; //i2cTransaction.slaveAddress = 0x50; /* * ======== mainThread ======== */ void *mainThread(void *arg0) { uint8_t txBuffer[4]; uint8_t rxBuffer[4]; I2C_Handle i2cHandle; I2C_Params i2cParams; I2C_Transaction i2cTransaction; /* Call driver init functions */ GPIO_init(); I2C_init(); /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); /* Create I2C for usage */ I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_100kHz; i2cHandle = I2C_open(Board_I2C0, &i2cParams); if (i2cHandle) { /* buffer registers */ txBuffer[0] = 0x01; txBuffer[1] = 0x01; txBuffer[2] = 0x42; //write buffer i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 3; //read buffer i2cTransaction.readBuf = rxBuffer; i2cTransaction.readCount = 0; //slave address i2cTransaction.slaveAddress = (0x50); /* now i write 0x42 on memory address 0x1 | 0x1 << 8 */ if(I2C_transfer(i2cHandle, &i2cTransaction)) { System_printf("success"); i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 2; i2cTransaction.readBuf = rxBuffer; i2cTransaction.readCount = 1; //slave address i2cTransaction.slaveAddress = (0x50); /* now i read on memory address 0x1 | 0x1 << 8 */ if(I2C_transfer(i2cHandle, &i2cTransaction)) { //success } else { System_printf("ERROR read"); } } else { System_printf("ERROR write"); } } /* Deinitialized I2C */ I2C_close(i2cHandle); //Turn OFF EEPROM return (NULL); }
Last edited by a moderator: