Hi all:
I wrote a code to directly read the register 0x43 (MPU_REG_GYRO_XOUT_H) But the GYRO data I got is wrong
Chip: nRF51422
Board: PCA10028
Firmware: S130_nRF51_2.0.1
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
spi_config.ss_pin = 4;
spi_config.sck_pin = 1;
spi_config.mosi_pin = 2;
spi_config.miso_pin = 3;
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
I plugged my SPI device to P0.01~P0.04 on board, and MOSI/MISO swap has been tried but nothing changed.
for (;;)
{
// Reset rx buffer and transfer done flag
memset(m_rx_buf, 0, 7);
spi_xfer_done = false;
m_tx_buf = m_tx_buf | MPU_SPI_READ_BIT; //m_tx_buf = 0x43, MPU_SPI_READ_BIT = 0x80
err_code = nrf_drv_spi_transfer(&spi, &m_tx_buf, 1, m_rx_buf, 7);
//printf("%d\n",err_code);
//printf("%d\n",sizeof(m_rx_buf));
uint8_t *data;
data = (uint8_t*)m_rx_buf;
for(uint8_t i = 0; i<6; i++) {
*data = m_rx_buf[5-i];
data++;
}
int16_t gxc, gyc, gzc;
if(!err_code){
gxc = ((int16_t)m_rx_buf[0] << 8) | (int16_t)m_rx_buf[1];
gyc = ((int16_t)m_rx_buf[2] << 8) | (int16_t)m_rx_buf[3];
gzc = ((int16_t)m_rx_buf[4] << 8) | (int16_t)m_rx_buf[5];
}
printf("%d\n",gxc);
printf("%d\n",gyc);
printf("%d\n",gzc);
LEDS_INVERT(BSP_LED_1_MASK);
nrf_delay_ms(100);
power_manage();
}
I got gxc, gxy, gxz showed -1 in uart
((int16_t)m_rx_buf[0] << 8) showed 65280 in uart (int16_t)m_rx_buf[1]; showed 255 in uart
so as m_rx_buf[2],m_rx_buf[3],m_rx_buf[4],m_rx_buf[5]
I have tried github.com/.../nrf5-ble-mpu-simple And I can't get the correct result, too.
My MPU9255 Module can run on NVIDIA TX1 correctly with RTIMULIB. Did I miss something or did I do something wrong?