10 posts / 0 new
Last post
eeecapstone
Offline
Last seen:5 years 6 months ago
加入:2015-04-01 03:55
SPI with LIS3DH

Hello Dialog team,

I'm a student working on a project and have run into some difficulties.

I'm trying to read acceleration data from the LIS3DH accelerometer using the DA14580 development board. When I try to read from any of the acceleration axes registers I receive -1 back. I believe my SPI isn't working.

I've utilised the functions provided in the LIS3DH_driver.c provided in the dice application example.
I've tried initializing in different modes:
LIS3DH_WriteReg(0x20, 0x77); //CTRL_REG1: Turn on the sensor, enable X, Y, and Z. ODR = 400Hz. LPen = 0 "Normal" mode
LIS3DH_WriteReg(0x23, 0x80); //CTRL_REG4: FS = 2g. HR = 0 "Normal" mode with low resolution

AxesRaw_t a_data;
LIS3DH_GetAccAxesRaw(&a_data);
Then sending the 3 axes acceleration data over Bluetooth via modification of DSPS code.

I've set up the following pins in periph_setup.h:

#define SPI_GPIO_PORT GPIO_PORT_0
#define SPI_CLK_PIN GPIO_PIN_0
#define SPI_CS_PIN GPIO_PIN_3
#define SPI_DI_PIN GPIO_PIN_5
#define SPI_DO_PIN GPIO_PIN_6

I've set up the following in periph_setup.c
RESERVE_GPIO (SPI_CLK, SPI_GPIO_PORT, SPI_CLK_PIN, PID_SPI_CLK);
RESERVE_GPIO (SPI_CS, SPI_GPIO_PORT, SPI_CS_PIN, PID_SPI_EN);
RESERVE_GPIO (SPI_DI, SPI_GPIO_PORT, SPI_DI_PIN, PID_SPI_DI);
RESERVE_GPIO (SPI_DO, SPI_GPIO_PORT, SPI_DO_PIN, PID_SPI_DO);
RESERVE_GPIO (UART1_TX,UART1_TX_PORT,UART1_TX_PIN,PID_UART1_TX);

I have connected the MOSI of the accelerometer to 'P0_6'. MISO to 'P0_5'. Vdd to 'SPI_SUP'. Chip Select to 'P0_3' and Clock to 'P0_0'. The ground is connected to ground two pins above 'P1_2'.

I have been trying to figure out why my SPI might not be working and would greatly appreciate any help. Thank you in advanced for your time.

Yours sincerely,
eeecapstone

Device:
eeecapstone
Offline
Last seen:5 years 6 months ago
加入:2015-04-01 03:55
For some reason it is

For some reason it is censored with stars so I do apologise. The first censored word in second line of RESERVE_GPIO is " SPI_CS" and the second censored word is "P0_0"

Thank you once again.

Yours sincerely,

eeecapstone

eeecapstone
Offline
Last seen:5 years 6 months ago
加入:2015-04-01 03:55
芯片选择和“P 0 _ 0”我

芯片选择和“P 0 _ 0”我don't know why it was censored again even though it was fine in the preview and I do apologise once again.

Yours sincerely,

eeecapstone

JE_Dialog
Offline
Last seen:1 month 1 week ago
Staff
加入:2013-12-05 14:02
Helo eeecapstone, can you

Helo eeecapstone, can you spell out the word that is asterixed (with space in between each letter) - our fitler is incorrectly picking it up as bad langauge. BR JE_Dialog

eeecapstone
Offline
Last seen:5 years 6 months ago
加入:2015-04-01 03:55
Hi JE_Dialog,

Hi JE_Dialog,

The first word that has been asterixed is: S P I _ C S
The second word that has been asterixed is: P 0 _ 0

Thank you very much for the reply.

Yours sincerely,

eeecapstone

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi eeecapstone

Hi eeecapstone

Try to switch the MISO ->SDO and MOSI->SDI line which i think that is the proper configuration.Are you able to use the GetWHO_AM_I function ? Does it return the identification code ?

Thanks MT_dialog

eeecapstone
Offline
Last seen:5 years 6 months ago
加入:2015-04-01 03:55
Hi MT_dialog,

Hi MT_dialog,

When I use the WHO_AM_I function I get the same output of -1. This happens for every register I read from. So I believe this is default value when SPI isn't working. I forgot to mention this is also my periph_setup.c :
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_3, OUTPUT, PID_SPI_EN, true );
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_0, OUTPUT, PID_SPI_CLK, false );
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_6, OUTPUT, PID_SPI_DO, false );
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_5, INPUT, PID_SPI_DI, false );

So the output of accelerometer is going into the input pin of the DA14580.

Is the way I'm setting up the pins correct? Not really sure why the SPI isn't working.

Yours sincerely,

eeecapstone

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
加入:2015-06-08 11:34
Hi eeecapstone,

Hi eeecapstone,

Try setting the SPI_DI pin in INPUT_PULLUP state and give it a try.

Thanks MT_dialog

ligo.george
Offline
Last seen:1 year 6 months ago
加入:2018-05-22 00:32
I also faced same issue. Then

I also faced same issue. Then find out that CHIP SELECT pin is hardcoded in the driver c file. It is working fine after editing that.

PM_Dialog
Offline
Last seen:2 days 15 hours ago
Staff
加入:2018-02-08 11:03
Hi ligo.george,

Hi ligo.george,

Thanks for the indication.

Regards, PM_Dialog