This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrF52832 get wrong WHO_AM_I value with spi

Hey guys (and merry Christmas),

I'm working with a Laird BL652-DVK (nrF 52832 - chip), Nordic SDK v.14.2.0 and SES (Segger Embedded Studio v.4.30). I try to receive data from an accelerometer using spi. At first I configured the uart example because I want to send the data to my pc with uart and Termite v3.4. That's working.

Now I have implented the spi example into the uart example.  I have configured spi and the accelerometer. After that I read the WHO_AM_I register (uint8_t read_data_1), but I get a wrong value. I get the value "11" instead of "33".... My code is below. If I read the "uint8_t read_data[1]" (commented out), I get the value "0x0". I really don't know, what to do. I hope someone can help me.

My code:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here I get the value "0x11" instead of "0x33":

Fullscreen
1
2
uint8_t read_data_1 = nrf_drv_spi_transfer(&spi, LIS3DH_WHO_AM_I_REG, sizeof(LIS3DH_WHO_AM_I_REG), read_data, sizeof(read_data));
printf("\r\nWHO_AM_I: %x\n", read_data_1); //value: 0x11 ??
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And here I get the value "0x0" instead of "0x33":

Fullscreen
1
2
nrf_drv_spi_transfer(&spi, LIS3DH_WHO_AM_I_REG, sizeof(LIS3DH_WHO_AM_I_REG), read_data, sizeof(read_data));
printf("\r\nWHO_AM_I: %x\n", read_data[1]); //value: 0x0 ??
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thanks in advance,

Christoph