AnsweredAssumed Answered

STM32f103 connection with ADXRS453 via SPI

Question asked by joe ted on Dec 2, 2017
Latest reply on Dec 3, 2017 by joe ted

Hi.

Recently i'm using ADXRS453BEYZ but failed to work with it !

I used 5V power supply for sensor and connect it via Buffer to 3.3v ARM microcontroller (STM32f103CBT6).

this is my configs

/*SPI config*/

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = SPI2_PIN_SCK | SPI2_PIN_MOSI | SPI2_PIN_MISO;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);


RCC_APB1PeriphClockCmd(SPI2_RCC,ENABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex ;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge ;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_Init(SPI2, &SPI_InitStructure);
/*SPI Peripheral Enable*/
SPI_Cmd (SPI2, ENABLE);

 

and this is the sensor data reading function

 

unsigned long ADXRS453_Data(void)
{
   unsigned char data[4] = {0, 0, 0, 0};
   unsigned long receivedData = 0x00;

 

   /*Reset the CS pin */
   GPIO_InitStructure.GPIO_Pin = SPI2_CS_Roll;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

 

      delay (1000);

   data[0] = ADXRS453_SENSOR_DATA;    //ADXRS453_SENSOR_DATA = 0x20
   SPI_I2S_SendData (SPI2, data [0]);
   delay (1000);

   data[0] = SPI_I2S_ReceiveData (SPI2);


   SPI_I2S_SendData (SPI2, data [1]);
   delay (1000);

   data[1] = SPI_I2S_ReceiveData (SPI2);


   SPI_I2S_SendData (SPI2, data [2]);
   delay (1000);
   data[2] = SPI_I2S_ReceiveData (SPI2);

 

   SPI_I2S_SendData (SPI2, data [3]);
   delay (1000);

   data[3] = SPI_I2S_ReceiveData (SPI2);

   delay (1000);

 

   /*Set the CS pin */

   GPIO_InitStructure.GPIO_Pin = SPI2_CS_Roll;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   

   receivedData = data[0];
  receivedData = (receivedData<<8) + data[1];
  receivedData = (receivedData<<8) + data[2];

  receivedData = (receivedData<<8) + data[3];

  Data =  (receivedData >> 10) & 0x0000FFFF;

This is the what i see:

 

receivedData == 0xFFFB 3800    //  11111111111110110011100000000000

Data == 0xFECE   // 1111111011001110

and it never changes.

I have working on it for 2 weeks and nothing special happened.

i will be thanks full if any one help me on this !

Best regards

Joe 

Outcomes