cancel
Showing results for 
Search instead for 
Did you mean: 

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

RNata.15
Associate II

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

15 REPLIES 15
Ozone
Lead

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

RNata.15
Associate II

I am using SPI, yes it does match

RNata.15
Associate II

anyone?

Ozone
Lead

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

Check the datasheet.

RNata.15
Associate II

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

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

Eleon BORLINI
ST Employee

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

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.15
Associate II
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