i2c4: line1 : syntax error: unexpected word (expecting " )" )
Hi This is SrikanthPilli, hey sorry about my bad English. i am using pandaboard (ARM9-cortex - A9) board with my own operating system( i was used open source kernel 3.0.4 for making my OS and include i2c-tools to the kernel using buildroot-2011.08).
In the pandaboard,the j3 expansion connector supports I2C4 at 23 & 24 pines for SDA & SCL lines. For writing and Reading data , i was used EEPROM through I2C4 lines.
i wrote the following code with i2c4.c
/* Read input line for args of offset and bytes to read from IIC device.
Do read and dump contents.
Modified to have EEPROM_ADDR as parameter
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
int main(int argc, char** argv)
{
unsigned offsetAddr;
unsigned SlaveAddr;
int count, bytesToRead;
unsigned char *i2c_buffer;
unsigned char i2c_ptr[3];
unsigned argRead, bytesRead;
int dev_i2c;
int adapter_nr;
char i2c_name[40];
int ret;
char buff[10]={0};
int i;
while(1)
{
adapter_nr=4;/* i2c4 initialisation*/
sprintf(i2c_name,"/dev/i2c-%d",adapter_nr);
printf("device opened at: %d\n",adapter_nr);
if ((dev_i2c = open(i2c_name, O_RDWR)) < 0)
{
printf("Cannot Open I2C4 Master Device\n");
exit(1);
}
else {
printf("device open successfull\n");
}
SlaveAddr=0x50;//Generally this is eeprom address, later mention actual slave address
if(ioctl(dev_i2c, I2C_SLAVE, SlaveAddr) < 0)
{
printf("Cannot set I2C4 address\n");
exit(1);
}
//i2c_smbus_write_word_data(dev_i2c,0x50,0x6543);
// Set address using 16 or 8 bit address, default to 8 bit address
i2c_ptr[0] = 0x10;//This is importent send data for i2c register selection
i2c_ptr[1] = 0x43;
i2c_ptr[2] = 0x65;
printf("i2c_ptr = %d\n",*i2c_ptr);
/************** writing data to I2C4*************************/
if(write(dev_i2c,i2c_ptr,3) != 3)
{
// write(dev_i2c,i2c_ptr,3);
// ret = write(dev_i2c,i2c_ptr,3);
// printf("ret = %d\n",ret);
printf("I2C4 writing failed\n");
}
/*Reading data from slave device***********************/
bytesToRead=1;
bytesRead = read(dev_i2c, buff, bytesToRead);
printf("I2C4 bytesRead. Return code = %d\n", bytesRead);
printf("I2C4 bytesToRead. Return code = %d\n", bytesToRead);
if(bytesRead != bytesToRead)
{
printf("I2C4 read failed. Return code = %u\n", bytesRead);
exit(1);
}
else
{
printf("I2C4 reading successuful ====%c \n",buff[0]);
}
}//while close
}
after this i follow the following steps,
1. PATH=$PATH:/home/srikanth/Project/buildroot/buildroot_n/buildroot-WCHAR/output/host/usr/bin/
2.arm-linux-gnueabi-gcc i2c4.c
after type these 2 lines in my host machine(my computer , ubuntu-10.4), it gives us a.out.
a.out is copied to i2c4 .
1.The final i2c4 is movied to the path in my rootfs , i.e /usr/bin/
2.Then after ON the board, after run the command ./i2c4 at /usr/bin/
3.it shows -sh:command not supported
4.after i typed in my console, sh i2c4
it shows
i2c4: line1 : syntax error: unexpected word (expecting " )" )
. so kindly solve this problem and give some input's why it is coming? what ever i followed procedure is correct or not? if it is wrong , please mention the correct path. and please review my code, and tell me is their any mistakes?
Thanks In Advance
SrikanthPilli
|