cancel
Showing results for 
Search instead for 
Did you mean: 

Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all FF...

saimaddy123
Associate II
Posted on March 23, 2011 at 13:44

Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all FF...

4 REPLIES 4
saimaddy123
Associate II
Posted on May 17, 2011 at 14:29

I changed GPIO configuration to have MISO to be input floating as mentioned in STM32f10xx reference manual now..I still see

the same behavior. BTW, I am toggling the GPIO connected to SPI2_NSS between ''low'' and ''high'' for every byte read/write. 

/* Enable GPIO clock */

RCC_APB2PeriphClockCmd(R_ACC_SPI_GPIO_CLK  | RCC_APB2Periph_AFIO , ENABLE);

/* Enable SPI clock  */

RCC_APB1PeriphClockCmd(R_ACC_SPI_CLK, ENABLE);

/* Configure SPI pins: SCK, MISO and MOSI */

GPIO_InitStructure.GPIO_Pin = R_ACC_SPI_SCK_PIN | R_ACC_SPI_MOSI_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(R_ACC_SPI_GPIO_PORT, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = R_ACC_SPI_MISO_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(R_ACC_SPI_GPIO_PORT, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = R_ACC_SPI_NSS_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(R_ACC_SPI_GPIO_PORT, &GPIO_InitStructure);

SPI_I2S_DeInit(R_ACC_SPI);

/* SPI Config */

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

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_Init(R_ACC_SPI, &SPI_InitStructure);

domen23
Associate II
Posted on May 17, 2011 at 14:29

Is it the correct SPI mode, and frequency?

NSS usually needs to be low for the whole transfer, not just one byte.

Use a scope to check clock, NSS, MOSI, MISO... if only MISO remains high for the whole time, then you might have a defective slave.

drzile86
Associate II
Posted on May 17, 2011 at 14:29

Hi,

I don't see your function or part of code where are you read from this device? Which register are you trying to read? Try to read CTRL_REG1 register which address is 20h and reset value is all 0's and look all signals and clocks on scope,

regards,

saimaddy123
Associate II
Posted on May 17, 2011 at 14:29

Hi,

The issue was with SPI clock...the device worked only with a prescaler value of 32. I should have updated latest status..

Thanks for the comment,

Sai