cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f103 connection with ADXRS453 via SPI

joe ted
Associate II
Posted on December 02, 2017 at 12:00

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);

 0690X0000060938QAA.png

      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 

1 REPLY 1
joe ted
Associate II
Posted on December 03, 2017 at 08:15

I think I just found what is wrong!

SPI buffer not empty flag, resets even i didn't red the SPI register !

I used debugger to watch the SPI register bits, and i saw buffer not empty flag even goes reset after after seconds standing on that breakpoint (without reading the SPI buffer) !!!

here i have no idea what happening .