Configuring Aptina MT9P031 using i2c-tools: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
No edit summary
Line 85: Line 85:
'''NOTE: You must remember to swap the value gotten with i2cget in order to get the correct register's value.'''
'''NOTE: You must remember to swap the value gotten with i2cget in order to get the correct register's value.'''


= How can we write a specific register? =


If you want to write a specific register you must use the following command:


<pre>
i2cset -f -y I2CBUS CHIP-ADDRESS DATA-ADDRESS VALUE MODE
</pre>
Where ''VALUE'' is the value to be written to the register.
As an example we will modify the register 160 (0x0A00) or ''Test_Pattern_Control'' register.


[[Category:Whitepaper]]
[[Category:Whitepaper]]

Revision as of 17:05, 8 March 2011

Introduction

This page shows how to access the MT9P031 registers using i2c-tool in order to read and/or write them.

How to know where your sensor is?

If you didn't know in which i2c address your sensor is you can find it easily by following the next steps:

1. Don't connect your camera module to the board and start it.

2. Once it started run the following command in your board's terminal:

i2cdetect -l

This command will show you any I2C bus available. In our case it will outputs something like this:

i2c-1	i2c       	DaVinci I2C adapter             	I2C adapter

This tell us we have one I2C bus which ID is i2c-1.

3. Once you got the I2C bus name you can get a map of the I2C devices connected to it by running

i2cdetect -y <numerical_id>

where numerical_id is the number that ends your I2C bus's ID. In our case we can run i2cdetect -y 1 and it will outputs the following map:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- 08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

4. Turn off you board, connect the camera module and repeat the process until get the I2C bus map. You will get something like this:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- 08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

We can see now the presence of the camera sensor at the address 0x48, we need this address in order to tell the i2c-tools which device we want to access.

How can we read a specific register?

In order to explain how to read a specific register we will give you a simple example reading the Chip Version register, this is the 0x000 register of the sensor.

Whatever register you want to read you must use the following command:

i2cget -f -y I2CBUS CHIP-ADDRESS DATA-ADDRESS MODE

Almost all the fields showed were already explained, the only one we haven't speak yet is the MODE field, this field allows to us to specify the the read mode, that is byte-read (b) or word-read (w). Since the MT9P031 have 16bit registers we must use work-read. The following is the command used to read the Chip Version register:

i2cget -f -y 1 0x48 0x000 w

After run this command you must get the following outpu:

0x0118

If you see the MT9P031's datasheet you will see that the correct Chip Version register's value is 0x1801. The reason we got a different value is because MT9P031 uses big endian and i2cget uses little endian, so you only need to swap the value obtained in order to get the correct one.

NOTE: You must remember to swap the value gotten with i2cget in order to get the correct register's value.

How can we write a specific register?

If you want to write a specific register you must use the following command:

i2cset -f -y I2CBUS CHIP-ADDRESS DATA-ADDRESS VALUE MODE

Where VALUE is the value to be written to the register.

As an example we will modify the register 160 (0x0A00) or Test_Pattern_Control register.