/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 Family
  •  » Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

# 1   2011-03-23 12:53:49 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

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

HI folks,

I am trying to read MEMS sensor through SPI. I am using Olimex's STM32-H107(which uses STM32F107VC). When I read, it returns all FFs.. I checked the chip select of SPI interface. It properly moves to low and high..So, the slave is selected properly.  Here is how I configure SPI interface...I am running the MCU at 72MHz..If you guys can give some pointers, that would be great...

My connections:

SPI2_NSS ->PB12
SPI2_SCK ->PB!3
SPI2_MISO -> PB!4
SPI2_MOSI -> PB15
   
   SPI_InitTypeDef    SPI_InitStructure;
   GPIO_InitTypeDef   GPIO_InitStructure;

   /* 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_MISO_PIN | R_ACC_SPI_MOSI_PIN| R_ACC_SPI_NSS_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_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);

 

    /* SPI enable */
    SPI_Cmd(R_ACC_SPI, ENABLE);

 
    GPIO_WriteBit(R_ACC_SPI_GPIO_PORT, R_ACC_SPI_NSS_PIN, Bit_SET);
    GPIO_WriteBit(R_ACC_SPI_GPIO_PORT, R_ACC_SPI_SCK_PIN, Bit_RESET);
    GPIO_WriteBit(R_ACC_SPI_GPIO_PORT, R_ACC_SPI_MISO_PIN, Bit_RESET);
    GPIO_WriteBit(R_ACC_SPI_GPIO_PORT, R_ACC_SPI_MOSI_PIN, Bit_RESET);


My system_Init( ) is as follows - just to give you guys info on how I am configuring PLLs.

void SystemInit()
{
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if (HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
 
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

#ifdef STM32F10X_CL
    /* Configure PLLs *********************************************************/
    /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
    RCC_PREDIV2Config(RCC_PREDIV2_Div5);
    RCC_PLL2Config(RCC_PLL2Mul_8);

    /* Enable PLL2 */
    RCC_PLL2Cmd(ENABLE);

    /* Wait till PLL2 is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
    {}

    /* PLL configuration: PLLCLK = (PLL2 / 5) * 9 = 72 MHz */
    RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
    RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
#else
    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
#endif

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock configuration.
       User can add here some code to deal with this error */   

    /* Go to infinite loop */
    while (1)
    {
    }
  }
  SystemCoreClock = 72000000; // 72 Mhz
}

Offline

 

# 2   2011-03-23 12:58:32 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Hello,

Do you have scope pictures of the CS ?

Are you sure the CS does not toggle at each byte ? I had a similar problem with SPI memories and I solved it by using the CS as an IO, setting it low before the transfer and setting back to high after the transfer.

Moreover, I do not use the STM libraries but the programmation of MISO must be input floating as per RM0008.pdf p154. And it seems to me that you program it as an output. You can check directly in the GPIO registers if you want to be 100% sure (if you have a way to display them).

Last edited by pascal697 (2011-03-23 13:02:30)

Offline

 

# 3   2011-03-23 13:31:48 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Pascal - First thanks for the reply.
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. I will see if I can print GPIO values on fly..


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


pascal697 :

Hello,

Do you have scope pictures of the CS ?

Are you sure the CS does not toggle at each byte ? I had a similar problem with SPI memories and I solved it by using the CS as an IO, setting it low before the transfer and setting back to high after the transfer.

Moreover, I do not use the STM libraries but the programmation of MISO must be input floating as per RM0008.pdf p154. And it seems to me that you program it as an output. You can check directly in the GPIO registers if you want to be 100% sure (if you have a way to display them).

Offline

 

# 4   2011-03-23 13:44:49 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

No pb. I went through a similar problem a few weeks ago.

GPIO values on the fly is not what I meant. Just the GPIO CFG registers values before starting the 1st SPI transmission. Just to be sure you set the GPIOs correctly.

I really do think that CS management can be the key to such behaviour -by the way, how is your SPI sensor connected ? what is the default value for MISO signal ? I did not open your sensor datasheet but you may find in it the expected chronograms for  your peripheral and then check against what you have on board, provided you have a decent scope (I mean a decent scope eases such kind of debugging).

If ever you do not have relevant information on the datasheet, I would suggest that you try once to set the CS to 0 before the transaction and then back to 1 after the last received data. This is in the case that the transaction takes more than one byte.

Also you might have noticed but I prefer to say it. Pay attention to the fact that in STM32, sending and receiving data are synchronous so if you want to send one byte to your peripheral, you will receive one byte (but if the peripheral answers on the next byte on the transaction, this 1st received byte is a dummy byte) and on the other way round : in order to receive a data from your peripheral, you have to send a dummy byte in order to send the clock to the slave => you have to pay attention to this fact when you decode the received bytes.

Hope this helps !

Last edited by pascal697 (2011-03-23 13:58:35)

Offline

 

# 5   2011-03-23 14:24:59 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Hi Pascal, I am exactly did the dummy byte kind of synchronization that you mentioned..I am also doing the CS toggling before and after data read .I gathered the GPIO_B Configuration and it is as follows:

GPIO_B input: 0x7ff3

GPIO_B output: 0x1010


I am seeing that the code is hung now to receive the data...I never see the the data coming in...

Hmm...got to dive into this..

Offline

 

# 6   2011-03-23 14:30:42 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

sorry! it was my mistake...i am at the same point as earlier... getting all FFs..thanks for your help Pascal...i will look into it...

Offline

 

# 7   2011-03-23 14:55:18 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

No pb.
In fact, I was speaking about GPIO configuration registers (GPIOB_CRL and CRH) to be sure about your IOs -especially MISO- configuration. I am not sure wether the GPIO data registers are updated when alternate functions are used!
Tell me if you solved it ;-)

Offline

 

# 8   2011-03-23 15:14:02 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697 :

No pb.
In fact, I was speaking about GPIO configuration registers (GPIOB_CRL and CRH) to be sure about your IOs -especially MISO- configuration. I am not sure wether the GPIO data registers are updated when alternate functions are used!
Tell me if you solved it ;-)

GPIOB_CRH: 0xb4b34444 GPIOB:CRL: 0x44484444

Does that ring any bell?

Offline

 

# 9   2011-03-23 15:30:54 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

yes ;-)
so MOSI and SCLK (PB15 and PB13) are configured as alternate output push-pull => OK
MISO (PB14) is configured as input with pull-up/down => the choice between pull-up and down is performed through PB_ODR bit 14 : what do you configure by default ? how is your hw ?
CS (PB12) is configured as an output : do you set the bit to 1 prior to starting the first transfer ? and how is your hw on this signal ?

Offline

 

# 10   2011-03-23 15:37:22 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam :

pascal697 :

No pb.
In fact, I was speaking about GPIO configuration registers (GPIOB_CRL and CRH) to be sure about your IOs -especially MISO- configuration. I am not sure wether the GPIO data registers are updated when alternate functions are used!
Tell me if you solved it ;-)

GPIOB_CRH: 0xb4b34444 GPIOB:CRL: 0x44484444

Does that ring any bell?

I think there is some issue.... Get me your ideas as well...

b -> PB15(MOSI) Configuration : 1011 =>Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for MOSI
4 -> PB14(MISO) Configuration: 0100 => Floating input (CNF) && Input Mode(MODE) ->  I think this is good for MISO. What was your config for MISO?
b -> PB13(SCL) Configuration => 1011 => Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for SCL

3 -> PB12(CS/NSS) Configuration => 0011 => General purpose output push-pull(CNF) && Output mode, max speed 50 MHz(MODE) => I think this is also good for NSS

Were these your configs as well?

Offline

 

# 11   2011-03-23 15:49:41 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam :

saiRam :

pascal697 :

No pb.
In fact, I was speaking about GPIO configuration registers (GPIOB_CRL and CRH) to be sure about your IOs -especially MISO- configuration. I am not sure wether the GPIO data registers are updated when alternate functions are used!
Tell me if you solved it ;-)

GPIOB_CRH: 0xb4b34444 GPIOB:CRL: 0x44484444

Does that ring any bell?

I think there is some issue.... Get me your ideas as well...

b -> PB15(MOSI) Configuration : 1011 =>Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for MOSI

=> open drain is not a good idea, you need 1011 (10 for push-pull). In B, 11 stands for the max speed (here 50MHz)

4 -> PB14(MISO) Configuration: 0100 => Floating input (CNF) && Input Mode(MODE) ->  I think this is good for MISO. What was your config for MISO?

=>my mistake : I missed this point : 4 is input floating, so the default value on your MISO line depends on your hw

b -> PB13(SCL) Configuration => 1011 => Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for SCL

=> the same as MOSI : B is the correct value for SCL

3 -> PB12(CS/NSS) Configuration => 0011 => General purpose output push-pull(CNF) && Output mode, max speed 50 MHz(MODE) => I think this is also good for NSS

=> yes it is ok

Were these your configs as well?

I have the above values B4B3.
So now, it depends on what your peripheral needs for a transaction. Did you get a chance to open the datasheet ?

Offline

 

# 12   2011-03-23 15:49:54 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697 :

yes ;-)
so MOSI and SCLK (PB15 and PB13) are configured as alternate output push-pull => OK
MISO (PB14) is configured as input with pull-up/down => the choice between pull-up and down is performed through PB_ODR bit 14 : what do you configure by default ? how is your hw ?
CS (PB12) is configured as an output : do you set the bit to 1 prior to starting the first transfer ? and how is your hw on this signal ?

THe HW Schematic is here..http://olimex.com/dev/pdf/ARM/ST/STM32-H107-schematic.pdf

ODR value is 0x1010 => 14th bit appears to be '0'.

GPIOB_CRH: 0xb4b34444 GPIOB:CRL: 0x44484444 GPIOB:ODR: 0x1010

The connections are: PB12 -> SPI_CS
                               PB13 -> SCL
                               PB14 -> MISO
                               PB15 -> MOSI

My initial configuration(before any SPI transfer) :

PB12 ->1
PB13 -> 0
PB14 -> input
PB15 -> 0

During a transfer

First PB12 ->0

<transfer>

Last PB12 ->1

Offline

 

# 13   2011-03-23 15:55:55 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697 :

saiRam :

saiRam :


GPIOB_CRH: 0xb4b34444 GPIOB:CRL: 0x44484444

Does that ring any bell?

I think there is some issue.... Get me your ideas as well...

b -> PB15(MOSI) Configuration : 1011 =>Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for MOSI

=> open drain is not a good idea, you need 1011 (10 for push-pull). In B, 11 stands for the max speed (here 50MHz)

4 -> PB14(MISO) Configuration: 0100 => Floating input (CNF) && Input Mode(MODE) ->  I think this is good for MISO. What was your config for MISO?

=>my mistake : I missed this point : 4 is input floating, so the default value on your MISO line depends on your hw

b -> PB13(SCL) Configuration => 1011 => Alternate function output Push-pull (CNF) &&Alternate Function Output Open-Drain(MODE) -> I think this is good for SCL

=> the same as MOSI : B is the correct value for SCL

3 -> PB12(CS/NSS) Configuration => 0011 => General purpose output push-pull(CNF) && Output mode, max speed 50 MHz(MODE) => I think this is also good for NSS

=> yes it is ok

Were these your configs as well?

I have the above values B4B3.
So now, it depends on what your peripheral needs for a transaction. Did you get a chance to open the datasheet ?

Of course ... I am inspecting the data sheet as well.. i think the sequence i am following should be OK..

Here is the peripheral data sheet...the SPI read/write sequence is in Page20 and Page 21..I see the CS and CLK signals are fine on my scope as well...

http://www.st.com/internet/com/TECHNICA … 250937.pdf

Offline

 

# 14   2011-03-23 15:57:42 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Sorry, I have to leave now. I will have a look tomorrow.

Offline

 

# 15   2011-03-23 16:00:08 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697 :

Sorry, I have to leave now. I will have a look tomorrow.

Thanks for your help.. I will continue to debug..This is the sequence i follow for example to read a byte from peripheral..

/* Put CS to low PB12-> 0 */
   /*Wait until the transmit buffer is empty - TXE flag */

   /* Send the address first  */
  /*Wait until a data is received - check on RXNE */
  /* Get the received data - ignore it */

  /*Wait until the transmit buffer is empty - Check on TXE flag*/
 
  /* Send the dummy byte - 0x0 */

   /* Wait until a data is received - check on RXNE */

  /*Get the received data - This is the data i want */

/* Put CS to high PB12 -> 1 */

Offline

 

# 16   2011-03-23 17:31:12 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Can any one confirm if the sequence i mentioned in the previous post is correct one for an SPI read from stm32f107vc?

Thanks,
SaiRAm

Offline

 

# 17   2011-03-24 03:25:45 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam :

pascal697 :

Sorry, I have to leave now. I will have a look tomorrow.

Thanks for your help.. I will continue to debug..This is the sequence i follow for example to read a byte from peripheral..

/* Put CS to low PB12-> 0 */
   /*Wait until the transmit buffer is empty - TXE flag */

   /* Send the address first  */
  /*Wait until a data is received - check on RXNE */
  /* Get the received data - ignore it */

  /*Wait until the transmit buffer is empty - Check on TXE flag*/
 
  /* Send the dummy byte - 0x0 */

   /* Wait until a data is received - check on RXNE */

  /*Get the received data - This is the data i want */

/* Put CS to high PB12 -> 1 */

One catch here is I see that the MISO pin is always staying at 1...i think which is not good...

HEre are my GPIO values after CS is set to low..

SPI2_NSS: 0x0

SPI2_CLK: 0x0

SPI2_MOSI: 0x0

SPI2_MISO: 0x1

reg_val: 0x00ff.

After the CS is set to high..

SPI2_NSS: 0x1

SPI2_CLK: 0x0

SPI2_MOSI: 0x0

SPI2_MISO: 0x1

Offline

 

# 18   2011-03-25 09:15:16 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Hello,
I am not sure these readings can be of any help because during the transmission, every signal (except CS) has to toggle => the actual mean to understand what is happening on the line is an oscilloscope.

Also, my understanding of the board you are working on is that it is equipped with a pull-up resistor on MISO net. Can you confirm ? If not, this behavior has to be explained differently.

I had a look at the component datasheet (LIS331HH). It requires that the CS is toggled once before the transmission then set back to 1 after le last byte. As you now perform such management, you can go to the next step. What bytes are you sending to the component ?

Offline

 

# 19   2011-04-06 09:18:26 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

saiRam
Member
Registered: 2011-03-21
Posts: 18

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

The problem was simple... The clock..I had to prescale it by a factor 32. It worked like a charm after that...

Thanks for all your help folks...

Offline

 

# 20   2011-04-26 11:03:25 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

pascal697
Member
Registered: 2011-03-23
Posts: 16

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Nice to read this ;-)
Regards,
Pascal.

Offline

 

# 21   2011-07-29 07:56:39 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

adamricky
New member
Registered: 2011-07-29
Posts: 5

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Are you sure the CS does not toggle at each byte ? I had a similar problem with SPI memories and I solved it by using the CS as an IO, setting it low before the transfer and setting back to high after the transfer.

Moreover, I do not use the STM libraries but the programmation of MISO must be input floating as per RM0008.pdf p154. And it seems to me that you program it as an output. You can check directly in the GPIO registers if you want to be 100% sure (if you have a way to display them).

Offline

 

# 22   2011-09-29 11:41:34 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Lync85
New member
Registered: 2011-09-04
Posts: 4

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

i grounded the CS because I use the SPI interface, was that a bad idea? because I use the LIS331DLH  ... and with CS =1 it means that i use I2C interface and with CS = 0 it means I use the SPI interface.


STM32F103ZE T6 | KEIL MDK-ARM

Offline

 

# 23   2011-10-26 18:10:14 Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

anand
New member
Registered: 2011-10-26
Posts: 1

Re: Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Hi saiRam

   Which IDE are you using??
I have the stm32-h107 olimex board...Is it possible to flash the code on to board through through usb??....


Thank you


stm32-h107 stm32f107vc

Offline

 

  • Index
  •  » STM32 Family
  •  » Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F

Board footer