LSM9DS1 not responding to 4-wire SPI.
Hello,
I have been trying for some time to get this to work. It is my understanding from the datasheet that the default values for the IC are suitable to where the acceleration and angular rates can be measured by shifting in the appropriate register values with the CS-A/G pin set to LOW and the CS-M pin set to HIGH, and that when the address is shifted in (MOSI), the byte corresponding to that address will be shifted out (MISO) during the next SPI cycle. I get the feeling that I am doing this entirely wrong. I looked at the library and example, which seemed mainly for I2C, and was hugely confused.
The code for this section of the program is below:
HAL_GPIO_WritePin(GPIOB, 15, 0);
HAL_Delay(10);
HAL_SPI_Transmit(&hspi1, (uint8_t *) &ORIENT_CFG_G, 1, 50);
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_X_L_G, (uint8_t *) &receive, 1, 50);
OrientationByte = receive;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_X_H_G, (uint8_t *) &receive, 1, 50);
hold = receive;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_L_G, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
pitch = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_H_G, (uint8_t *) &receive, 1, 50);
hold = receive;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_L_G, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
roll = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_H_G, (uint8_t *) &receive, 1, 50);
hold = receive;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_X_L_XL, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
yaw = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_X_H_XL, (uint8_t *) &receive, 1, 50);
hold = receive;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_L_XL, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
yaw = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Y_H_XL, (uint8_t *) &receive, 1, 50);
hold = receive;
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
x_Accel = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Z_L_XL, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
y_Accel = hold;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *) &OUT_Z_H_XL, (uint8_t *) &receive, 1, 50);
hold = receive;
HAL_SPI_Receive(&hspi1, (uint8_t *) &receive, 1, 50);
hold = (hold << 8) + receive;
if (hold > 32767)
hold = -((~hold)+1);
z_Accel = hold;
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOB, 15, 1);
HAL_Delay(50);The register values I am using are below:
const uint8_t ORIENT_CFG_G = 0x13;
const uint8_t OUT_X_L_G = 0x18;
const uint8_t OUT_X_H_G = 0x19;
const uint8_t OUT_Y_L_G = 0x1A;
const uint8_t OUT_Y_H_G = 0x1B;
const uint8_t OUT_Z_L_G = 0x1C;
const uint8_t OUT_Z_H_G = 0x1D;
const uint8_t OUT_X_L_XL = 0x28;
const uint8_t OUT_X_H_XL = 0x29;
const uint8_t OUT_Y_L_XL = 0x2A;
const uint8_t OUT_Y_H_XL = 0x2B;
const uint8_t OUT_Z_L_XL = 0x2C;
const uint8_t OUT_Z_H_XL = 0x2D;Thank y'all for your time.
