From b6eb26d324c890280e4174328ba4d75a07b42a50 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 13 Feb 2016 23:05:27 -0500 Subject: [PATCH] Lowered timeout. It was previous set to 10 seconds... since the timeout is in ms. Now it's at 1 second. This represents 100 clocks at 100KHz I2c. Also, I noticed general call mode was being set for the I2C which is not at all something we want (the ability to address multiple devices at once). I tested the changes with all my cameras. No problems. This was 4 units (2 being the original protos). --- src/omv/sccb.c | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/omv/sccb.c b/src/omv/sccb.c index c6c6fa6ca..7d8db1873 100644 --- a/src/omv/sccb.c +++ b/src/omv/sccb.c @@ -6,14 +6,12 @@ * SCCB (I2C like) driver. * */ +#include #include -#include "sccb.h" -#include "stdbool.h" -#include "systick.h" +#include #include "omv_boardconfig.h" -#define SCCB_FREQ (100000) -#define TIMEOUT (10000) - +#include "sccb.h" +#define SCCB_FREQ (100000) static I2C_HandleTypeDef I2CHandle; int SCCB_Init() @@ -24,7 +22,7 @@ int SCCB_Init() I2CHandle.Init.ClockSpeed = SCCB_FREQ; I2CHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; I2CHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; - I2CHandle.Init.GeneralCallMode = I2C_GENERALCALL_ENABLED; + I2CHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; I2CHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; I2CHandle.Init.OwnAddress1 = 0xFE; I2CHandle.Init.OwnAddress2 = 0xFE; @@ -42,41 +40,39 @@ uint8_t SCCB_Probe() uint8_t slv_addr = 0x00; for (int i=0; i<127; i++) { - if (HAL_I2C_Master_Transmit(&I2CHandle, i, ®, 1, TIMEOUT) == HAL_OK) { + if (HAL_I2C_Master_Transmit(&I2CHandle, i, ®, 1, 1) == HAL_OK) { slv_addr = i; break; } - systick_sleep(1); + if (i!=126) { + systick_sleep(1); // Necessary for OV7725 camera (not for OV2640). + } } return slv_addr; } +uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg) +{ + uint8_t data=0; + + __disable_irq(); + if((HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, ®, 1, 1) != HAL_OK) + || (HAL_I2C_Master_Receive(&I2CHandle, slv_addr, &data, 1, 1) != HAL_OK)) { + data=0xFF; + } + __enable_irq(); + return data; +} + uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data) { uint8_t ret=0; uint8_t buf[] = {reg, data}; __disable_irq(); - if (HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, buf, 2, TIMEOUT) != HAL_OK) { + if(HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, buf, 2, 1) != HAL_OK) { ret=0xFF; } __enable_irq(); return ret; } - -uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg) -{ - uint8_t data=0; - - __disable_irq(); - if (HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, ®, 1, TIMEOUT) != HAL_OK) { - data = 0xFF; - goto error_w; - } - if (HAL_I2C_Master_Receive(&I2CHandle, slv_addr, &data, 1, TIMEOUT) != HAL_OK) { - data = 0xFF; - } -error_w: - __enable_irq(); - return data; -}