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...
/* 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:32Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:48Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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..
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:49Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:59Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:42Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:02Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:54Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:22Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:41Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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:54Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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'.
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...
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:26Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F
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).
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:14Reading MEMS sensor(LIS331HH) from STM32F107 through SPI returns all F