2020-11-22 02:06 PM
I used the STM32F401 discovery board which has an L3GD20H gyroscope sensor communicated with the MCU via SPI1, I made the necessary configuration by Cube MX
I tried to read the device ID of the gyroscope but each time I received 0xff,
can someone help me to resolve this problem to continue my work
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
SpiTxBuff[0]=0x0f;
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1,&SpiTxBuff[0],1,50);
HAL_SPI_Receive(&hspi1,&SpiRxBuff[0],1,50);
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2020-11-22 04:08 PM
Add delays after setting CS low or high
Check the configuration of PE3, and scope it to see it go LOW/HIGH
Use HAL_SPI_TransmitReceive, send 0x0F,0xFF
2020-11-23 04:18 AM
why i should send 0x0f , 0xff
the adress of the register who I AM is 0x0f
2020-11-23 05:44 AM
To generate clocks for the pad byte to get a response on the symmetrical bus to clock out the ID
2020-11-24 01:36 AM
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_RESET);
spiTxBuf[0]=0x0f|0x80;
spiTxBuf[1]=0x00;
spiRxBuf[1]=0xff;
HAL_SPI_Transmit(&hspi1,spiTxBuf,2,50);
HAL_SPI_Receive(&hspi1,&spiRxBuf[1],1,50);
HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}