LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 02-16-2011, 02:16 PM   #1
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Fedora at home, Ubuntu 10.04 at work
Posts: 88

Rep: Reputation: 16
Question How to determine success of I2C byte and word read operations


I have a I2C client driver that reads some registers on a device via an I2C bus driver. Depending on the length of data to be read, it either calls i2c_smbus_read_byte_data, i2c_smbus_read_word_data or i2c_smbus_read_i2c_block_data depending on the length of data to be read:

Code:
	if (count == 1)	{		/* I2C_SMBUS_BYTE_DATA */
		*reg_val = i2c_smbus_read_byte_data(i2c_client, reg_addr);
		noBytes = 1;
	} else if (count == 2) {	/* I2C_SMBUS_WORD_DATA */
		*((uint16_t *)reg_val) = i2c_smbus_read_word_data(i2c_client, reg_addr);		
		noBytes = 2;
	} else if (count > 2) {		/* I2C_SMBUS_I2C_BLOCK_DATA */
		noBytes = i2c_smbus_read_i2c_block_data(i2c_client, reg_addr, count, reg_val); 
	}
The block read function returns the number of bytes read, so I can use this to determine if the read was successful, but the byte and word read functions return the value read. How can I determine whether or not this was successful? When the device is unplugged, the registers read 0xff or 0xffff, but those are also valid register values.

I'll probably figure something out myself eventually but if anyone has any ideas?
 
Old 02-16-2011, 04:31 PM   #2
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Fedora at home, Ubuntu 10.04 at work
Posts: 88

Original Poster
Rep: Reputation: 16
Fixed. i2c_smbus_read_byte_data and word_data return -1 in case of failure. Just had to change my data types to signed numbers.
 
  


Reply


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
bash shell script read file word by word part 2 justina Programming 7 01-25-2011 01:19 PM
[SOLVED] bash shell script read file word by word. justina Programming 15 01-22-2011 10:12 AM
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
i2c block read problemsss westermani Linux - Software 4 05-08-2008 08:13 AM
Slow read/write operations on 3592 drive Joejr4u Linux - Hardware 2 03-17-2008 05:25 AM


All times are GMT -5. The time now is 07:14 PM.

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