2012-02-14 11:55 PM
Good day,
I have some problem here, I took some code from another project, I rewrote some parts. But my camera do not want to work. I just want to read the ID of camera through I2C (or so called SCCB), but I always get 0xFF. I even tried to scan all I2C devices (0x00-0xFF). Here is some code:I use STM3210C-EVAL board with stm32f107 mcu. I connected camera to PB6 (SCL), PB7(SDA), 2.8V voltage and ground. Maybe I did something wrong, but I cannot find the mistake..sensor datasheet:http://www.trulydisplays.com/ccm/specs/0.3M Sensor OV7670.pdf
and the camera:http://www.emartee.com/Images/websites/emartee.com/products/thumbnails/big/41908.jpg
2012-02-16 12:02 AM
Hi,
The problem is that Alternate function are not configured. changei2c_cfg
(
) as follow :
void
i2c_cfg
(
void
)
{
GPIO_InitTypeDef
GPIO_InitStructure
;
I2C_InitTypeDef
I2C_InitStruct
;
RCC_APB1PeriphClockCmd
(
RCC_APB1Periph_IOE_I2C
,
ENABLE
);
RCC_APB2PeriphClockCmd
(
RCC_APB_IOE_I2C_PORT
|
RCC_APB_GPIO_IOE_ITPORT
|
RCC_APB2Periph_AFIO
,
ENABLE
);
/* Alternate function configuration : modify parameters with your application requirement */ GPIO_PinAFConfig(IOE_I2C_PORT
, GPIO_PinSource6, GPIO_AF_I2C1); GPIO_PinAFConfig(IOE_I2C_PORT
, GPIO_PinSource9, GPIO_AF_I2C1);/* Configure I2C1 GPIOs *****************************************************/
GPIO_InitStructure
.
GPIO_Pin
=
IOE_SCL_PIN
|
IOE_SDA_PIN
;
GPIO_InitStructure
.
GPIO_Mode=
GPIO_Mode_AF
;
GPIO_InitStructure
.
GPIO_OType
=
GPIO_OType_OD;
GPIO_InitStructure
.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_50MHz;
GPIO_Init
(
IOE_I2C_PORT
,
&
GPIO_InitStructure
);
/* Configure I2C1 ***********************************************************/
/* I2C DeInit */
I2C_DeInit
(
I2C1
);
/* Enable the I2C peripheral */
I2C_Cmd
(
I2C1
,
ENABLE
);
/* Set the I2C structure parameters */
I2C_InitStruct
.
I2C_Mode
=
I2C_Mode_I2C
;
I2C_InitStruct
.
I2C_DutyCycle
=
I2C_DutyCycle_2
;
I2C_InitStruct
.
I2C_OwnAddress1
=
0xFE
;
I2C_InitStruct
.
I2C_Ack
=
I2C_Ack_Enable
;
I2C_InitStruct
.
I2C_AcknowledgedAddress
=
I2C_AcknowledgedAddress_7bit
;
I2C_InitStruct
.
I2C_ClockSpeed
=
30000
;
/* Initialize the I2C peripheral w/ selected parameters */
I2C_Init
(
I2C1
,
&
I2C_InitStruct
);
}
2012-02-18 06:04 AM
Hi Kurosaki,
Thank you for the reply.You see I took this code from another board, another cpu, but I2C Write and Read functions matches.I have STM3210C-EVAL board. It uses stm32f107 cpu. So the difference is that stm32f10x.h library:http://www.keil.com/dd/docs/arm/st/stm32f10x/stm32f10x.h
typedef struct{ __IO uint32_t CRL; __IO uint32_t CRH; __IO uint32_t IDR; __IO uint32_t ODR; __IO uint32_t BSRR; __IO uint32_t BRR; __IO uint32_t LCKR;} GPIO_TypeDef;and stm32f2xx.h:http://www.keil.com/dd/docs/arm/st/stm32f2xx/stm32f2xx.h
typedef struct{ __IO uint32_t MODER;__IO uint32_t OTYPER;__IO uint32_t OSPEEDR;__IO uint32_t PUPDR;__IO uint32_t IDR;__IO uint32_t ODR;__IO uint16_t BSRRL; /* BSRR register is split to 2 * 16-bit fields BSRRL */ __IO uint16_t BSRRH; /* BSRR register is split to 2 * 16-bit fields BSRRH */__IO uint32_t LCKR;__IO uint32_t AFR[2];} GPIO_TypeDef;
So in my library I do not see the function called:GPIO_PinAFConfig(
IOE_I2C_PORT
, GPIO_PinSource6, GPIO_AF_I2C1); //6 SCLGPIO_PinAFConfig(
IOE_I2C_PORT
, GPIO_PinSource7, GPIO_AF_I2C1); //7 SDA2015-04-22 07:40 AM
Hello
I can write to registers but can't read them, what is the reason?I supply xclk pin with 42MHz sysclk coming from MCO2.Thanks.2015-06-28 07:26 AM
Hello
My problem was solved, it was related to the incompatibility of SCCB protocol and HAL_I2C_Mem_Read function of the stm32cubef4 software package.