cancel
Showing results for 
Search instead for 
Did you mean: 

SPI issue keep getting 0 values from accelerometer

NicRoberts
Senior

NUCLEO-WB55RG communicating via SPI1 to an ADXL362 eval board
I set up the project (attched below) using CubeIDE, generated the code & placed my own callbacks for the SPI in main.

When I look at the value for the Z direction I should be getting a value that indicates roughly 1g but all I get is 0. The same for all the other axis, no change in any value no matter how I orient the sensor.

To check that the acceleromter was working I hooked it up to an Arduino using a 3rd party library especially for the ADXL362. That all worked as expected, so I know the accelerometer is working.

When I go through the code with the debugger it doesn't hang anywhere so I'm guessing my callbacks are working, its just I dont get any data back, all values remain at 0

Anyone see anything obvious that I'm doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
NicRoberts
Senior

Found it!!
I had configured PA4 as SPI1_NSS as soon as I reconfigured it as a GPIO output it all worked fine.

Thanks fellas for walking me through the debugging of this.

View solution in original post

16 REPLIES 16

Check if Arduino Library is doing something to initialize/start the accelerometer. I remember the Bosch devices needing a quick magic sequence and scale selection. 

Get a scope or logic analyzer on the pins and review working and non-working signals.

Link to github library for working driver you're using / attempting to port

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
NicRoberts
Senior

The Arduino library I used Winkelict ADXL362 Arduino library 

The only thing I've spotted is that they do is a soft reset first, which I've now added to ADXL362_Init()

 

SPI_WriteRegister(ADXL362_SOFT_RESET, 0x52);
HAL_Delay(500);

Which doesn't change the behaviour, I still get 0 readings.

I changed the power control register to disable auto-sleep and remain in measurement mode

SPI_WriteRegister(ADXL362_POWER_CTL, 0x02);

Still no readings. So I decided to check if I could even read the chip ID, I cant I just get a value of 0.

Andrew Neil
Super User

To prove basic SPI comms, can you successfully read the Device ID register ?

As @Tesla DeLorean said, use a scope and/or logic analyser to verify comms - compare & contrast with the Arduino.

 

Have you checked the AD Product Page:

https://www.analog.com/en/products/adxl362.html#:~:text=Sheet%20(Rev.%20G)-,Software%20Resources,-All

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Not even getting the device ID. 

Yes I have the device datasheet with the register map & the SPI settings.

As soon as I get a working scope I'll check the comms.

Sorry I should add, the example software doesn't include the hardware specific SPI drivers & I have zero experience with no_OS


@NicRoberts wrote:

 the example software doesn't include the hardware specific SPI drivers 


Of course not: that's what makes it portable to use on any microcontroller!

The only part which is specific to the STM32 is the hardware-specific SPI part.

 


@NicRoberts wrote:

 I have zero experience with no_OS


It simply means that it's plain, portable code with no dependencies on any OS.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Andrew Neil wrote:


Of course not: that's what makes it portable to use on any microcontroller!

The only part which is specific to the STM32 is the hardware-specific SPI part.

I'm aware of that, its the hardware-specific SPI driver that I'm having an issue with.

This is where the scope/analyser really comes in ...

Have you looked at ST's  SPI  examples?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Yeah, I followed how to set up SPI using Cube & the HAL. I've also tried a tutorial implementing SPI from bare metal but none of them work.

I've even swapped the board out but still nothing. I'm not getting why the call-backs would pass their checks if no comms were happening, shouldn't they just hang until they get their appropriate IRQ?


Anyway just got my hands on scope, we'll see...