BL652 (nRF) MPU 6050 Basic

 


【回路の構成】

VCCとGND、SDA,SCKの4本だけを接続する。上の写真ではmax30102とカスケードに接続している。むろんマイコンから直接でも。

【基本のやりとり】

テンプレートから開始する。TWI、NRF_LOGが少なくとも使える状態のもの。

ここ。

https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf

まずは、write, readする関数を書いてみる。

int main(void)の上に記載する。

void mpu6050_register_write(uint8_t register_address, uint8_t value)
{
ret_code_t err_code;
uint8_t buffer[2] = {register_address, value};
err_code = nrf_drv_twi_tx(&m_twi, 0x68, buffer, sizeof(buffer), true);
APP_ERROR_CHECK(err_code);
}

uint8_t mpu6050_register_read (uint8_t reg_address)
{
uint8_t data;
ret_code_t err_code;
err_code = nrf_drv_twi_tx(&m_twi, 0x68, &reg_address, sizeof(reg_address), true);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_twi_rx(&m_twi, 0x68, &data, sizeof(data));
APP_ERROR_CHECK(err_code);
return data;
}

whileの外の部分で、
 uint8_t mpu6050_ID;
としてIDを格納する変数を定義


レジスタ0x75は、WHO_AM_Iになっていて、ここを読みにいけば、I2Cのアドレスである0x68を返してくるはず。
whileの中を以下のようにしてやる。
    while (true)
    {
      mpu6050_ID=mpu6050_register_read(0x75);
      NRF_LOG_INFO("ID=0x%x",mpu6050_ID);
      NRF_LOG_FLUSH();
      nrf_delay_ms(500);
    }

ビルトして問題なければ、

無事に0x68を返してきてくれる。
















コメント

このブログの人気の投稿

Attiny85とAQM0802A(LCD)のI2C接続

ILI9341 240X320 Arduino

Attiny85 FuseRest