CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using I2C to interface with SCCB bus

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Using I2C to interface with SCCB bus
PostPosted: Fri Jun 04, 2010 1:37 pm     Reply with quote

Hi , Guys I did some some reading and most ppl said it possible to read and write to omnivisions SCCB protocol with standard i2c.

I have tried to do this but I am unsuccessful, has anyone got experience using this protocol with a CCS i2c command set ?

Any help will be greatly appreciated.

Note I have my tried my code on a little temp sensor on the Picdem 2 dev kits and it works but it is not working on the camera module. I'm reading a constant -1.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 04, 2010 5:15 pm     Reply with quote

Quote:

I have tried to do this but I am unsuccessful.

1. Post a link to the full data sheet for the product. This data sheet
should show the SCCB bus timing, all registers and any information
needed to talk to the product (using the SCCB bus).

2. Post your SCCB driver routines. For example, the CCS file 24256.c
has the driver routines for a 24LC256 eeprom. You should have a file
similar to that (containing code that you wrote).

3. Post your test program that calls the driver routines. This should
have the #include for the PIC, #fuses, #use delay, #use i2c, etc.,
and it should have a main(). It should do something to test that the
driver is working. The results of the test should be displayed in a
terminal window on the PIC, using printf. Or, perhaps the device
should just do something. Describe your test and how it works.

4. Make the code be as short as possible (no useless CCS Wizard code).

5. The posted code should be complete. For example, if we copy and
paste your code into an MPLAB project, it should compile with no errors.

6. Post a description of the hardware connections between the PIC and
the SCCB bus device. Describe any external components, such as
pull-up resistors, etc. Give the component values.

7. Post the type of PIC board that you are using with the SCCB bus
device ? You mentioned a PicDem2 "kit". Is it one of these boards
in the links below ? Tell us which one.

This is the original PicDem2-Plus:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010072

This is the new "Rohs" version.
http://www.microchipdirect.com/ProductSearch.aspx?Keywords=DM163022
It looks different in the prototype area. Notice the two silver "bars" in
that area of the photograph.

8. Post what you are currently seeing in the SCCB bus test when you
run the test program. Post why you think it's failing. Then post the
result that you would like to see. Give details.

9. Post your CCS compiler version.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Jun 04, 2010 5:50 pm     Reply with quote

...

Last edited by dyeatman on Sat Jun 05, 2010 7:29 am; edited 1 time in total
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Sat Jun 05, 2010 2:40 am     Reply with quote

Hi, I have added all the items you requested

1a) SCCB specification
http://www.ovt.com/download_document.php?type=document&DID=63
1b) ov5620 data sheet
http://www.express-hitech.com/resource/datasheet/OV5620.pdf
this data sheet is preliminary but I have compared the interested areas with my confidential one and its similar.

2&3&4&5)
Code:
#include "16F877A.h"
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=n, stop=1)

//sets up the I2C pins
#define Device_SDA PIN_C4
#define Device_SCL PIN_C3
//Configures the I2C
#use i2c(master,sda=Device_SDA,scl=Device_SCL)

void main()
{
while(TRUE)
{
while(input_state(PIN_B0)==0)
{
//variable to camera id in
signed int8 value = 0x0;

//i2c routine
i2c_start();
i2c_write(0x60);
i2c_write(0x1C);
//i2c_start();
i2c_write(0x61);
value = i2c_read(0x0);
i2c_stop();
printf("camera ID: %d",value);
output_high(pin_B1);
delay_ms(1000);
}
}
}
From the code above the second i2c start is commented out because in the sccb specification for a read you need only need start+deviceid(W)(X)+deviceaddr(X)+deviceid(R)(X)+devicedata(X)+stop
The X's refers to dont care bits, thus a second start to reverse the direction is not specified.

So the above code works when I push the B0 button the code runs 'while = 1', setups the i2c and does a read then prints to the uart and computer.

Finally pin b1 goes high to show me I have run thorough the code.

6)I made a pcb in which the camera slides in to make its pins more accessible. The camera uses 2.8v so I used a lvl translator between the pic which runs on 3.3v and the camera. I have tested the i2c data and clk one both sides of the lvl translator and all signals are translated and looks good. On the camera board I use 4k7 pullups.

MY end application is a camera system used on a satellite so I am using a actel fpga for all the parallel interconnect between the camera my sram and final storage (this is just some extra info and not necessary for the task at hand)

7) Yes im using the second board on this web page http://www.microchipdirect.com/ProductSearch.aspx?Keywords=DM163022

8)When I run the test i receive a -1 in place where I should receive a manufacturers id of 7F or at least the high byte of the ID. I have tested the code above by using the second i2c_start command and reading the temperature sensor on the pic dem board and displaying it on the uart and it works nice using putty.

9) Lastly im using ccs 4.104 running under a xp addon for windows 7 because i could not get the ICD's to work under win 7 64bit

Thx allot I i can add more information please let me know

Regards
Jacques
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 3:19 am     Reply with quote

Was in contact with the design engineer and he said I need to feed the camera with a active clk for the internal sccb engine to function.

I am going to try it and post my results.

Added power down and reset but I'm still reading a -1.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 10:12 pm     Reply with quote

This document gives a sample protocol to read the manufacturer ID
word from the OV6120, which is similar camera. Look on page 15.
http://www.kanecomputing.co.uk/pdfs/d_module%20to%20cmos%20image%20sensor.pdf

I've implemented that protocol in the program below. I changed the
device addresses to 0x60 and 0x61, because the OV5620 data sheet
says to use those addresses. The manufacturer ID is the same for
both the OV6120 and OV5620. It's 0x7FA2.

If this code doesn't work then post a link to your schematic which
shows the PIC, the OV5620, and the level shifter circuit (with all
components).
Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)

#define OV5620_WRITE_ADDR  0x60
#define OV5620_READ_ADDR   0x61

#define OV5620_ID_REG      0x1C


int16 read_manufacturer_id(void)
{
int8 lsb;
int8 msb;
int16 retval;

i2c_start();
i2c_write(OV5620_WRITE_ADDR);
i2c_write(OV5620_ID_REG);
i2c_stop();

delay_us(2);  // Bus Free time (OV5620 data sheet, pg. 11)

i2c_start();
i2c_write(OV5620_READ_ADDR);
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

retval = make16(msb, lsb);

return(retval);
}

//===============================
void main()
{
int16 id;

delay_ms(1);  // Reset settling time (OV5620 data sheet, pg. 10)

id = read_manufacturer_id();

printf("Mfr id = %lx \n\r", id);  // Should be 0x7FA2

while(1);
}
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

:)
PostPosted: Mon Jun 07, 2010 3:35 am     Reply with quote

Thank you kind SiR Smile

And it works.....


thx thx
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Checking for ACK
PostPosted: Wed Oct 20, 2010 10:49 am     Reply with quote

Hi Guys, How Can I check for an Ack in the above code?

Thx
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 11:14 am     Reply with quote

Download the CCS manual. Look at the description of i2c_write().
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Checking for ACK
PostPosted: Wed Oct 20, 2010 12:18 pm     Reply with quote

Hi Can I try something like this:
Code:

if(!i2c_write(OV5620_WRITE_ADDR))
{
i2c_start();
i2c_write(OV5620_WRITE_ADDR);
i2c_write(OV5620_ID_REG);
i2c_stop();
}

before I send the camera a new command.

Because at the moment I am only reading 0xFF :(

I don't know what happened between my last post when it worked until now.

Kindest Regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 12:47 pm     Reply with quote

Page 3 of AN1028 shows the Ack-Polling sequence of operations:
http://ww1.microchip.com/downloads/en/AppNotes/01028a.pdf

This post has a program to detect the existence of an i2c device by
checking the ACK value:
http://www.ccsinfo.com/forum/viewtopic.php?t=42368&start=4
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 1:09 pm     Reply with quote

I will be back at my university lab tomorrow, to see if I can get a peep from my camera.

Thanks for the assistance
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 1:14 pm     Reply with quote

Make sure you have 4.7K pull-up resistors installed on SCL and SDA.
Also check the camera's menu, to make sure the i2c interface is enabled.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 1:47 pm     Reply with quote

HI PCM,

I am using the older original picdem2 plus board (As far as I could remember that board has 4k7 pull ups.) through a level shifter(don't really know if this is needed) to shift the voltage from 3.3v to 2.8v used by the OV5620 camera sensor (i2c).

Also the camera is using SCCB interface but the code you helped on in the top of this post got me to read back the manufactures ID so I know it works but now I can't get it to work. Hopefully its a magic loose wire that I'll plug in and voila.

The ack checking routine is quite interesting and I will definitely utilise it in future projects of mine.

I have viewed the I2C from the level shifter to the camera and everything looks corrects as the line is being release for the ack but then the camera does nothing its like throwing rock at a wall i2c commands at pins. I have tested the camera... Got a little dev kit or more like a interface to usb board with it so I know it works software is kinda [censored] but it works.

I have this one
http://www.electronics123.com/s.nl/it.A/id.2787/.f

So thats it Smile
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group