0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

STM32マイコンでOV7670などとSCCB通信する際の注意点

Last updated at Posted at 2017-11-15

STM32 (HAL)によるSCCB通信

OmniVisionのカメラは制御用のインタフェースとしてSCCBを採用しています。SCCBはI2Cとほぼ同じですが、最終ビットにACK/NACKがありません。HALのI2C関数で単純にカメラからREADすると、ACK待ちでタイムアウトが発生します。

HAL_I2C_Mem_Readを使わずに、HAL_I2C_Master_TransmitとHAL_I2C_Master_Receiveに通信を分けてあげることで対処できます。

ov7670.c
static RET ov7670_read(uint8_t regAddr, uint8_t *data)
{
  HAL_StatusTypeDef ret;
  do {
    // HAL_I2C_Mem_Read doesn't work (because of SCCB protocol(doesn't have ack))? */
//    ret = HAL_I2C_Mem_Read(sp_hi2c, SLAVE_ADDR, regAddr, I2C_MEMADD_SIZE_8BIT, data, 1, 1000);
    ret = HAL_I2C_Master_Transmit(sp_hi2c, SLAVE_ADDR, &regAddr, 1, 100);
    ret |= HAL_I2C_Master_Receive(sp_hi2c, SLAVE_ADDR, data, 1, 100);
  } while (ret != HAL_OK && 0);
  return ret;
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?