Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-07-2011, 02:19 AM   #1
LQ Newbie
Registered: May 2011
Location: india,andhrapradesh,guntur
Posts: 29
Blog Entries: 3

Rep: Reputation: 0
Question 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;

adapter_nr=4;/* i2c4 initialisation*/
printf("device opened at: %d\n",adapter_nr);
if ((dev_i2c = open(i2c_name, O_RDWR)) < 0)
printf("Cannot Open I2C4 Master Device\n");

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");


// 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***********************/

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);


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/ 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
Old 12-07-2011, 07:18 AM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
if you run "sh programname" then sh will try to interpret the program as a shell script. as compiled c code you should be running it as "./programname" but if for some reason it's not set as executable already run "chmod +x programname" and try again.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] line 1: syntax error: word unexpected (expecting ")") me011089 Linux - Embedded & Single-board computer 5 08-23-2011 09:34 AM
Busybox Syntax error: word unexpected (expecting ")") asprakash Linux - Embedded & Single-board computer 6 10-13-2010 03:22 AM
[SOLVED] Shell Scripting "syntax error : unexpected end of file" roxie600 Programming 12 04-30-2010 01:18 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 10:28 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration