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).
This commit is contained in:
Kwabena W. Agyeman 2016-02-13 23:05:27 -05:00
parent abac52534c
commit b6eb26d324

View File

@ -6,14 +6,12 @@
* SCCB (I2C like) driver. * SCCB (I2C like) driver.
* *
*/ */
#include <stdbool.h>
#include <stm32f4xx_hal.h> #include <stm32f4xx_hal.h>
#include "sccb.h" #include <systick.h>
#include "stdbool.h"
#include "systick.h"
#include "omv_boardconfig.h" #include "omv_boardconfig.h"
#include "sccb.h"
#define SCCB_FREQ (100000) #define SCCB_FREQ (100000)
#define TIMEOUT (10000)
static I2C_HandleTypeDef I2CHandle; static I2C_HandleTypeDef I2CHandle;
int SCCB_Init() int SCCB_Init()
@ -24,7 +22,7 @@ int SCCB_Init()
I2CHandle.Init.ClockSpeed = SCCB_FREQ; I2CHandle.Init.ClockSpeed = SCCB_FREQ;
I2CHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; I2CHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2CHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; 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.NoStretchMode = I2C_NOSTRETCH_DISABLED;
I2CHandle.Init.OwnAddress1 = 0xFE; I2CHandle.Init.OwnAddress1 = 0xFE;
I2CHandle.Init.OwnAddress2 = 0xFE; I2CHandle.Init.OwnAddress2 = 0xFE;
@ -42,41 +40,39 @@ uint8_t SCCB_Probe()
uint8_t slv_addr = 0x00; uint8_t slv_addr = 0x00;
for (int i=0; i<127; i++) { for (int i=0; i<127; i++) {
if (HAL_I2C_Master_Transmit(&I2CHandle, i, &reg, 1, TIMEOUT) == HAL_OK) { if (HAL_I2C_Master_Transmit(&I2CHandle, i, &reg, 1, 1) == HAL_OK) {
slv_addr = i; slv_addr = i;
break; break;
} }
systick_sleep(1); if (i!=126) {
systick_sleep(1); // Necessary for OV7725 camera (not for OV2640).
}
} }
return slv_addr; 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, &reg, 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 SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
{ {
uint8_t ret=0; uint8_t ret=0;
uint8_t buf[] = {reg, data}; uint8_t buf[] = {reg, data};
__disable_irq(); __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; ret=0xFF;
} }
__enable_irq(); __enable_irq();
return ret; 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, &reg, 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;
}