Configuring Aptina MT9P031 using i2c-tools

From RidgeRun Developer Connection

(Difference between revisions)
Jump to:navigation, search
(How can we write a specific register?)
(7 intermediate revisions not shown)
Line 63: Line 63:
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.  
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:
+
You can read a register by using the following command:
<pre>
<pre>
Line 69: Line 69:
</pre>
</pre>
-
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:
+
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 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:
<pre>
<pre>
Line 83: Line 83:
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.  
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.  
-
<pre>
 
'''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>
</pre>
 +
 +
Where ''VALUE'' is the value to be written to the register.
 +
 +
As an example we will modify the register 32 (0x020) or ''Read Mode 2 (RW)'' register.
 +
 +
1. Run the following pipeline, it will run a video capture from the camera to the composite output. You should see a normal vertical image in your display device.
 +
 +
<pre>
 +
gst-launch -e v4l2src always-copy=false ! video/x-raw-yuv,format=\(fourcc\)UYVY, width=640, height=480, framerate=\(fraction\)30/1 ! dmaiaccel ! TIDmaiVideoSink sync=false accelFrameCopy=false videoOutput=composite videoStd=D1_NTSC
 +
</pre>
 +
 +
2. We will modify the register in order to flip the image vertically writing  on it with the following command:
 +
 +
<pre>
 +
i2cset -f -y 1 0x48 0x020 0x00C0 w
 +
</pre>
 +
 +
If you see the MT9P031's datasheet you will find that the value you must write is 0xC000 but remember you must swap the bytes before you write the register.
 +
 +
'''NOTE: You must remember to swap the desired value before write it into the register.'''
 +
 +
3. Now run again the pipeline, you will see that your image is flipped vertically.
 +
 +
4. In order to restore you image you could write the register again:
 +
 +
<pre>
 +
i2cset -f -y 1 0x48 0x020 0x0040 w
 +
</pre>
 +
 +
[[Category:Whitepaper]]
[[Category:Whitepaper]]

Revision as of 20:44, 8 March 2011

Contents

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.

You can read a register by using 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 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 32 (0x020) or Read Mode 2 (RW) register.

1. Run the following pipeline, it will run a video capture from the camera to the composite output. You should see a normal vertical image in your display device.

gst-launch -e v4l2src always-copy=false ! video/x-raw-yuv,format=\(fourcc\)UYVY, width=640, height=480, framerate=\(fraction\)30/1 ! dmaiaccel ! TIDmaiVideoSink sync=false accelFrameCopy=false videoOutput=composite videoStd=D1_NTSC

2. We will modify the register in order to flip the image vertically writing on it with the following command:

i2cset -f -y 1 0x48 0x020 0x00C0 w

If you see the MT9P031's datasheet you will find that the value you must write is 0xC000 but remember you must swap the bytes before you write the register.

NOTE: You must remember to swap the desired value before write it into the register.

3. Now run again the pipeline, you will see that your image is flipped vertically.

4. In order to restore you image you could write the register again:

i2cset -f -y 1 0x48 0x020 0x0040 w
Navigation
Toolbox