<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17587/nrf52832-spi-to-builtin-lis2dh-accelerometer</link><description>Hi,
I have the D52QD2M4IA-A chip (from dynastream) that has inside nrf52832 chip. It has also builtin an onboard LIS2DH accelerometer. However when I am trying to connect to it through SPI interface this seems not to respond back.
Can Anyone help?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Aug 2017 16:48:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17587/nrf52832-spi-to-builtin-lis2dh-accelerometer" /><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67622?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 16:48:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d83502bb-5e24-4b76-bd25-6984e19ad0b6</guid><dc:creator>Nestor Matas</dc:creator><description>&lt;p&gt;I know this is a bit old, but for future reference, make sure you set the LIS2DH operation mode to low power, normal or high resolution before trying to read or you will get 0 when reading the axis values. By default it is in powered down mode.
To do that write CTRL_REG1[3] (LPen) and CTRL_REG4[3] (HR) bits with your desired configuration.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67621?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 21:45:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89e03a46-49cc-422f-8f8a-bae358d7b187</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Well, you could read the technical reference&lt;/p&gt;
&lt;p&gt;Or other people have written code for this device that you could port e.g.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Snowda/LIS2DH"&gt;github.com/.../LIS2DH&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67620?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2016 21:23:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b1e49c6-0ad3-432c-a64e-adf27abfe887</guid><dc:creator>Balco</dc:creator><description>&lt;p&gt;Ok without changing the bit order I Was able to send WHO_AM_I reg (= 0x0F ) and to get back the value of 33. Now how I can go on to read more data? I am trying to read the OUT_X_L register but no lack (I am getting 00 value). Do I have to set something prior? Is there any sample code to get the xyz accelerometer values?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67619?ContentTypeID=1</link><pubDate>Thu, 10 Nov 2016 23:05:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4112f547-dabc-41cc-8689-10d29061d439</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;My code doesn&amp;#39;t change the speed or the bit order, are you sure you need to change them ?&lt;/p&gt;
&lt;p&gt;Also. The WHO_AM_I reg is 0x0F and you need to set the MSB for a read operation&lt;/p&gt;
&lt;p&gt;PS. I ran my code in async mode, but that should not make any difference&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67618?ContentTypeID=1</link><pubDate>Thu, 10 Nov 2016 22:46:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2209f41-4733-4c38-9e6b-13e7a8a003a0</guid><dc:creator>Balco</dc:creator><description>&lt;p&gt;My code is as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;nrf_drv_spi.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_temp.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;

#if defined(BOARD_PCA10040)
#define SPI_CS_PIN   27 /**&amp;lt; SPI CS Pin.*/
#elif defined(BOARD_PCA10036) 
#define SPI_CS_PIN   29 /**&amp;lt; SPI CS Pin.*/
#elif defined(BOARD_PCA10028)
#define SPI_CS_PIN   4  /**&amp;lt; SPI CS Pin.*/
#else
#error &amp;quot;Example is not supported on that board.&amp;quot;
#endif
#define SPI_INSTANCE  0
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);
static volatile bool spi_xfer_done;  /**&amp;lt; Flag used to indicate that SPI instance completed the transfer. */


void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
    spi_xfer_done = true;

}

int main(void)
{

	uint32_t err_code = NRF_SUCCESS;
	uint8_t reg;
		nrf_gpio_cfg_output(17);
	
		nrf_delay_ms(1);
	nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
	spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
	spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_LSB_FIRST;
	spi_config.ss_pin = SPI_CS_PIN;
		nrf_delay_ms(1);
	err_code = nrf_drv_spi_init(&amp;amp;spi, &amp;amp;spi_config, spi_event_handler);
		nrf_delay_ms(1);
	if (err_code != NRF_SUCCESS)
  {
    // Initialization failed. Take recovery action.
		reg = 0x01;
  }
	 APP_ERROR_CHECK(err_code);
	
	uint8_t OUT_X_L_addr = 0x28;       // The address of the register you want to write
	uint8_t WHO_AM_I = 0x0F;
  uint8_t tx_data[2] = {0x00, 0x00}; // Transmit register
  uint8_t rx_data[2] = {0x00, 0x00}; // Receive register

	  while (true)
    {
			 tx_data[0] = ( WHO_AM_I | 0x80 ); //Add the RW bit to the address.
		
	    spi_xfer_done   = false;
			nrf_delay_ms(1);
						APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, tx_data, 2, rx_data, 2));
			if (rx_data[1]&amp;gt;0){
				nrf_gpio_pin_write(17,1);
				nrf_delay_ms(1000);
			}
			nrf_gpio_pin_write(17,0);
	
			
			nrf_delay_ms(500);

    }
		
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67617?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2016 22:15:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f63b1509-1782-4773-8316-2d9b9c973938</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;I just tested this on my dev board and I can read the WHO_AM_I register as soon as the LOG init stuff has finished, even before I do APP_TIMER_INIT etc&lt;/p&gt;
&lt;p&gt;So your code probably has an error, double check the pin assignments and also that you initialised the SPI correctly&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67616?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2016 21:20:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90ca6e59-294a-421e-8fa9-eb8b4b921672</guid><dc:creator>Balco</dc:creator><description>&lt;p&gt;How I can hook this logic analyser? Itried the  WHO_AM_I but in debug mode i got back 0 value in the device response!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67615?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2016 05:04:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:729f6791-fd7e-469b-bcb8-3904650d7c08</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Did you  try reading the WHO_AM_I register ?&lt;/p&gt;
&lt;p&gt;Have you hooked up a logic analyser to confirm that you are enabling the device and sending valid data to it ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67614?ContentTypeID=1</link><pubDate>Tue, 08 Nov 2016 06:00:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86e5a6b5-2b7f-4448-ae00-f541d30ecbfd</guid><dc:creator>Balco</dc:creator><description>&lt;p&gt;Hi, I run my program in debug mode so I suppose there is the appropriate time needed from the chip tto initialize. Or is there the need to change the nrf_drv_spi_init builtin function to add inside this time delay?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 SPI to builtin LIS2DH accelerometer</title><link>https://devzone.nordicsemi.com/thread/67613?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2016 22:01:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85dea4ca-3c3b-4a50-9a4c-7a5e81ea0ebb</guid><dc:creator>Dave_couling</dc:creator><description>&lt;p&gt;The is a required start up time for this chip to run its own initialization routine.  Add a time delay before writing to the chip and it should work fine.  Check the LIS2DH data sheet for the exact time delay required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>