2024-10-21 06:19 AM
Hello
Iam using STM32H562RGV6 for my project and iam using SPI6 on this MCU in order to communicate with LSM6DSOX which is an IMU from ST itself but i couldn’t get proper data from the IMU, as its giving random data sometimes and sometimes its zero.
Pin connections :
SPI6_SCK -> PB3
SPI6_MOSI -> PB5
SPI6_MISO -> PB4
CS -> PH0 (This is an external crystal oscillator pin but iam using it as GPIO, Will this be an issue as on this pin even if i set the GPIO to high its giving a maximum voltage of 1V)
I tried to change the CS pin instead of toggle before and after communication to ground always and used pull-up in cube ide also but nothing seems to work as i cant communicate and get proper data , chip id itself.
Here are my SPI6 configuration settings of my project, I changed the prescalar to different values but nothing is working. When I measure voltage on SPC and MOSI pins its giving 1.35V (If this would be an issue)
How to debug this issue i dont have print log iam just using Debug windows live expressions for checking change in values.
For your reference iam adding the code here like only transfer function using SPI:
int32_t spi_read_reg_mtn_snsr(void *handle, uint8_t Reg, uint8_t *pdata, uint16_t Length)
{
uint8_t ret;
Reg = Reg|0x80;
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_0, GPIO_PIN_RESET);
//HAL_GPIO_WritePin(GPIOF, GPIO_PIN_13, GPIO_PIN_RESET);
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
ret=HAL_SPI_Transmit(&hspi6, &Reg, 1, HAL_MAX_DELAY);
if(ret != HAL_OK)
printf("\r\nSPI Read Error");
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
ret=HAL_SPI_Receive(&hspi6, pdata, Length, HAL_MAX_DELAY);
if(ret != HAL_OK)
printf("\r\nSPI Read Error");
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
//HAL_GPIO_WritePin(GPIOF, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_0, GPIO_PIN_SET);
return HAL_OK;
}
int32_t spi_write_reg_mtn_snsr(void *handle, uint8_t Reg, uint8_t *pdata, uint16_t Length)
{
uint8_t ret;
Reg = Reg & 0x7F;
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_0, GPIO_PIN_RESET);
//HAL_GPIO_WritePin(GPIOF, GPIO_PIN_13, GPIO_PIN_RESET);
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
ret=HAL_SPI_Transmit(&hspi6, &Reg, 1, HAL_MAX_DELAY);
if(ret != HAL_OK)
printf("\r\nSPI Write Error");
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
ret=HAL_SPI_Transmit(&hspi6, pdata, Length, HAL_MAX_DELAY);
if(ret != HAL_OK)
printf("\r\nSPI Write Error");
while (HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY){}
//HAL_GPIO_WritePin(GPIOF, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_0, GPIO_PIN_SET);
return HAL_OK;
}
void read_chip(LSM6DSOX_Object_t *pobj)
{
LSM6DSOX_ReadID(pobj, &Chip_ID); //This is part of ST driver of lsm6dsox itself
printf("\n\rChip id is %X", Chip_ID);
}
For Reading chip_id iam using this instruction in while loop but not getting any thing:
spi_read_reg_mtn_snsr(&hspi6, LSM6DSOX_WHO_AM_I , &data1 , 1);
read_chip(pObj);
Any help is greatly appreciated and thanks in advance.