Dear All,
I'm trying to write the eeprom userspace test application,
when I run the below test app, I see the below messages
BusyBox v1.15.0 () built-in shell (ash)
Enter 'help' for a list of built-in commands.
root@freescale ~$ MY_TEST_APPLICATION_EEPROM
SUCCESS: open(3) passed
ERROR: ioctl(fd, I2C_SLAVE, 0x50) failed
root@freescale ~$
I even tried changing it to "status = ioctl(fd, I2C_SLAVE_FORCE, i2c_addr);" , but still the same issue, could you please let me know how to get rid of this issue, as am trying this from since 2 days, not able to succeed further
Any help would be greatly appreciated
Thanks in advance,
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
/* chmod 666 /dev/i2c-0 */
int main(void)
{
// Data to be written to eeprom
unsigned char wbuf[17] = { 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
unsigned char rbuf[16];
int i2c_addr = 0xa0;
int status;
unsigned short int i;
// OPENING I2C DEVICE
int fd = open("/dev/i2c-0", O_RDWR);
if (fd < 0) {
printf("ERROR: open(%d) failed\n", fd);
return -1;
}
printf("\nSUCCESS: open(%d) passed\n", fd);
// SETTING EEPROM ADDR
status = ioctl(fd, I2C_SLAVE, i2c_addr>>1);
if (status < 0)
{
printf("ERROR: ioctl(fd, I2C_SLAVE, 0x%02X) failed\n", i2c_addr);
close(fd);
return -1;
}
printf("\nSUCCESS: ioctl(fd, I2C_SLAVE, 0x%02X>>1) passed\n", i2c_addr);
// WRITING TO EEPROM
printf ("\nPerforming EEPROM Write operation\n");
write(fd,wbuf,16);
sleep(10); //till eeprom completes writes
if (write(fd,wbuf,16) != 16) {
printf("ERROR: write() failed\n");
close(fd);
return -1;
}
printf("\nSUCCESS: Data written to the EEPROM\n");
// READING FROM EEPROM
printf ("\nPerforming EEPROM Read operation\n");
wbuf[0]=0;
if(write(fd,wbuf,1)!=1){
printf("ERROR: buffer pointer initialization of read() failed\n");
}
if (read(fd,rbuf,16) != 16) {
printf("ERROR: read() failed\n");
close(fd);
return -1;
}
for(i = 0; i< 16; i++)
printf("ReadBuffer[%d] %d \r\n", i, rbuf[i]);
printf("\nSUCCESS: Data READ from the EEPROM\n");
printf("\neerprom test successfull \n");
close(fd);
}