Skip to main content
Visitor II
October 1, 2019
Question

I am using LIS2HH12 ACC, I am able to read the value of status registers and who am i REGISTER BUT NOT ABLE TO READ THE VALUE OF X, Y, Z REGISTERS, i am using a silicon lab efr32 radio board as dev board

  • October 1, 2019
  • 11 replies
  • 2714 views

Can anyone post any code that can help me here please, or suggest me how to move forward

    This topic has been closed for replies.

    11 replies

    Explorer
    October 1, 2019

    Use a scope, and check if the recorded wave forms / I2C bus sequences match those of the accelerometer datasheet / I2C bus section.

    RNata.15Author
    Visitor II
    October 1, 2019

    I am using SPI, yes it does match

    RNata.15Author
    Visitor II
    October 1, 2019

    anyone?

    Explorer
    October 2, 2019

    I suppose you can't read this registers directly. AFAIK, you need to write the desired register index first.

    Check the datasheet.

    RNata.15Author
    Visitor II
    October 2, 2019

    in the following image the registers for x, y, z are enabled already0690X000009jxW2QAI.pngI

    Explorer
    October 3, 2019

    Enable means, the sensor generates sensible measurements that end up in this registers.

    Reading them is a different matter, and not related to the control register.

    Section 6.2 of the datasheet should tell you how it's done.

    Access wide is 16 bits, and you have to give the R/W bit and the register address first, followed by data - or dummy data for a read.

    Section 7 list the register addresses (offsets).

    ST Employee
    October 3, 2019

    Hi @RNata.15​ , in addition to @Ozone​ suggestions, please follow the indication regarding device power up configuration and axl data reading at p.13 of AN4662. Regards

    0690X000009jyVFQAY.png

    Explorer
    October 3, 2019

    The initial question is very superficial - it is not clear if all this is about a SPI sequence error (cannot read axis data registers at all) or data problem (data not as expected).

    RNata.15Author
    Visitor II
    October 3, 2019
    void spi_setup() 													//spi setup
    {
    	CMU_ClockEnable(cmuClock_HFPER,true);
    	CMU_ClockEnable(cmuClock_GPIO,true);
    	CMU_ClockEnable(cmuClock_USART1,true);
     
     
    	GPIO_PinModeSet(gpioPortC,9,gpioModePushPull,1); 				//enabling he chip select
    	GPIO_PinModeSet(gpioPortC,6,gpioModePushPull,1);				//MOSI
    	GPIO_PinModeSet(gpioPortC,7,gpioModeInput,0);					//MISO
    	GPIO_PinModeSet(gpioPortC,8,gpioModePushPull,1);			 	//CLK
     
    	USART_InitSync_TypeDef initdata = USART_INITSYNC_DEFAULT;
     
     
    	initdata.clockMode=usartClockMode3;								//sample on rising edge
    	initdata.msbf=true;
    	initdata.autoCsEnable=true; 			//autochipselect enable is set
    	initdata.master=true;
    	initdata.baudrate=1000000;
    	initdata.enable=usartDisable;
     
    	USART_InitSync(USART1,&initdata);
     
     
     
    	USART1->ROUTELOC0 = (USART_ROUTELOC0_CLKLOC_LOC11)| 		 				//CLK
    						(USART_ROUTELOC0_CSLOC_LOC11)|			 				//CS
    						(USART_ROUTELOC0_TXLOC_LOC11)| 			 					//mosi
    						(USART_ROUTELOC0_RXLOC_LOC11); 		 				//miso
     
    	USART1->ROUTEPEN = USART_ROUTEPEN_CLKPEN | USART_ROUTEPEN_CSPEN | USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN; 		//enabling
     
    	USART_Enable(USART1,usartEnable);
     
    }
     
     
    void spi_tx(uint8_t address, uint8_t data)
    {
    	//GPIO_PinOutClear(gpioPortC,9); 		//pulling the chip select pin low
     
    	while(!(USART1->STATUS & USART_STATUS_TXBL)); 	 //while this is not true, transmit buffer not empty
    	USART_Tx(USART1,address);
    	while(!(USART1->STATUS & USART_STATUS_RXDATAV));	 //recieve buffer not empty, need to read, get out of while loop
    	USART_Rx(USART1);
    	while(!(USART1->STATUS & USART_STATUS_TXBL));
    	USART_Tx(USART1,data);
    	while(!(USART1->STATUS & USART_STATUS_RXDATAV));
    	USART_Rx(USART1);
     
    	//GPIO_PinOutSet(gpioPortC,9);						 //back to high
     
    }
    uint8_t spi_rx(uint8_t address)
    {
     
    	//done so that READ bit is set as 1
    //automatically enable the chip select
    	address = 0x80 | address;
     
    	while(!(USART1->STATUS & USART_STATUS_TXBL));
    	USART_TxDouble(USART1,address);
    	while(!(USART1->STATUS & USART_STATUS_RXDATAV));
    	USART_Rx(USART1);
    	while(!(USART1->STATUS & USART_STATUS_TXBL));
    	USART_Tx(USART1,0x00);								 	//dummy
    	while(!(USART1->STATUS & USART_STATUS_RXDATAV));
     
    	//GPIO_PinOutSet(gpioPortC,9);
     
    	return USART_RxDouble(USART1);;
    }

    Hi,

    Thank you for your patience and trying to help me out. The below image is of when I try to read from "who am i register" and I am getting the readings.

    I did follow the steps as you said by writing the value to ctrl1 register and ctrl3.

    but I am not able to get any values.

    I am following the read and write bit as you told me.

    Kindly help me out here please.

    I have attached the code for reference

    0690X000009jzp1QAA.png

    Explorer
    October 4, 2019

    I think you are aware of the synchronous nature of SPI. Meaning, the first byte the slave sends while you transmit is meaningless and has to be discarded.

    > while(!(USART1->STATUS & USART_STATUS_TXBL)); //while this is not true, transmit buffer not empty

    I don't know your MCU (EFR32), but assuming ST-like semantics, "transmit buffer empty" means the value to send had been moved to the output register, but not that the SPI transaction is finished. You would need to check with the serial/SPI section of the EFR32 manual.

    With STM32 parts, the Tx register is an interface for the core. A Tx register value is transferred to the actual transmission hardware when no other transaction is ongoing. Transmission then takes the time required according to the interface's configuration. A completed transmission finally sets a flag in the status register.

    RNata.15Author
    Visitor II
    October 4, 2019

    I think you are aware of the synchronous nature of SPI. Meaning, the first byte the slave sends while you transmit is meaningless and has to be discarded. -

    By this do you mean value it is reading from who am i register is meaningless and to be discarded

    RNata.15Author
    Visitor II
    October 4, 2019

    Thank you for your reply, do you mean to say the data i am reading from who am i register is meaningless and basically i am not receiving from who am i register

    Explorer
    October 7, 2019

    The byte you receive while clocking out the address value (register offset) is meaningless.

    This is the nature of SPI. To returning some meaningful answer, the slave has to receive the "command" first - i.e. the R/W bit and the address. Synchronous SPI clocks out whatever happens to be in the slave's TX register at that time. With the second byte, the slave is able to fetch the requested register and copy it to the SPI TX register.

    That's what the datasheet implicitly says with the SPI diagrams.