AnsweredAssumed Answered

stm32f4 discovery LIS3DSH HAL problem

Question asked by britwa.boris on Feb 16, 2016
Latest reply on Feb 20, 2016 by britwa.boris
No answer from the register who I am.
The most interesting is that this code worked for a while, but now does not work.
I have attached a file that previously all worked.

/* USER CODE BEGIN 0 */
uint8_t SPI_read(uint8_t address)
{
    uint8_t  reciveData;
    address = 0x80 | address;  
  CS_ON
    HAL_SPI_TransmitReceive(&hspi1,&address,&reciveData,1,100);
    uint8_t data=0x00;
    HAL_SPI_TransmitReceive(&hspi1,&data,&reciveData,1,100);
  CS_OFF
    return reciveData;
}
 /* USER CODE END 0 */


/* USER CODE BEGIN 2 */
RED_LED_ON
GREEN_LED_ON

if (SPI_read(0x0F)==0x3B){
    RED_LED_OFF
    }else if(SPI_read(0x0F)==0x3F)//LIS3DSH
    GREEN_LED_OFF

 /* USER CODE END 2 */

/* SPI1 init function */

void MX_SPI1_Init(void)
{

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  hspi1.Init.CRCPolynomial = 10;
  HAL_SPI_Init(&hspi1);

}    

Attachments

Outcomes