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:

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

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

Thanks in advance,

Christoph

  • Several issues in the code above, try the following changes:

    A read operation is required for the Id, so try this:

    The data sheet implies Mode 3, but I find Mode 0 works best:

    This should now work, but I would suggest making this the first operation before init_lis():

    Once it works, the clock speed can be increased to 8MHz, although if connected by long traces SCK and MOSI and CS might require H0H1 drive levels at the faster clock speed. Good luck!

  • Hey hmolesworth,

    thanks for you fast reply. Because of Christmas I can't make the changes unitl December 28th (saturday). But from saturday I will make the changes und write the results here.

    Best regards and merry Christmas,

    Christoph

  • Hey hmolesworth,

    the changes doesn't work. Now I get: 0x0.

    Here is my current code:

    And I don't know where is the issue..

  • Hope you had a good Christmas! Actually your code does work now, I just ran it (on a LIS2DH12, very similar part)! I tried both 2MHz and 8MHz and both return 0x33 as expected. I had printfs commented out and just put in a breakpoint to look at the 2-byte returned values:

    Maybe share your circuit (or at least the part of the LIS3DH).in case there is some issue, perhaps i/o pin voltage. Typically (LIS2DH12) pins 5,6,7,8 are all Gnd; pins 9,10 share nRF52832 Vdd; LIS3 is similar but different pins

  • Hey hmolesworth,

    yes thanks, I hope you had a good Christmas too! Ok, I insert photos of my development kit, Uart-to-USB-Bridge and the LIS3DH-circuit. At first I wanted to say, that I changed my code a little bit and got more terminal output.

    My changes:

    And now I got this output:

    I think that the manual pin configuration made SPI transfers and the spi_event_handler (code below) was triggered by it.

    From here come photos and circuits of the components:

    -BL652_SA:

    Here is the BL652-SA datasheet: https://connectivity-staging.s3.us-east-2.amazonaws.com/2019-05/CS-DS-BL652%20v2_9.pdf

    I can send BL652_SA circuit by mail, if you want. Maybe it's not allowed to public the circuit in a forum.

    -LIS3DH:

    *photo removed*  ->not public

    circuit:

    *removed*  ->not public

    ->pin6: 3.3V, pin5: GND, pin4: SCL 3.3V, pin3: MOSI, pin2:MISO, pin1:CSD/SS

    Connector:

    MOSI and MISO connectioh to board:

    SCL and SS connection to board:

    VDD and GND connection to board:

    -USB-to-UART-Bridge:

    I hope this will help. I can insert more photos if needed.

    PS: hmolesworth thank you for your dedication to help me!

1 2 3