AnsweredAssumed Answered


Question asked by Mike Jaber on Jun 5, 2018
Latest reply on Jun 6, 2018 by jeremyzhou


I'm using the LPC1227 to read data from an accelerometer via SPI. I configured the SPI using some functions in the SPP library. The accelerometer sensor is the LSM6DS3. This sensor has an only read register  (who is called "WHO_I_AM") which its value is always 0x69. In order to test the spi communication I wanted to see if I can get this value in the SSP data register (DR). The problem is that I'm always getting a 0 in this data register. Could someone please check this code below and tell me if I did something wrong. I also attached the SPP library from where I used these functions. Thank you!



LPC_GPIO0->DIR|=1<<1; // MEMS CS
LPC_GPIO0->DIR|=(1<<17); // MOSI 
LPC_GPIO0->DIR&=~(1<<16); // MISO 
LPC_GPIO0->DIR|=1<<14; // SCK 


// **************** PIN CONFIGURATION **************************


LPC_IOCON->PIO0_14&=~(0b111<<0); // Select SCK on PIO0_14 
LPC_IOCON->PIO0_1 &=~(0b111<<0); // Select MEMS nCS
LPC_IOCON->PIO0_16&=~(0b111<<0); // Select MISO on PIO0_16 
LPC_IOCON->PIO0_17&=~(0b111<<0); // Select MOSI on PIO0_17 
LPC_IOCON->PIO0_17 |=(1<<1);

LPC_GPIO0->OUT&=~(1<<1); // nCS MEMS = 0


// *********** MEMS SPI CONFIGURATION ************* //


SSP_InitTypeDef param_MEMS;


(param_MEMS).DataSize|=DATASIZE_8<<0; // transfert de 8 bits (attention Datasize est un uint16_t)
(param_MEMS).CPHA|=1<<7; // voir p 37 datasheet du MEMS
(param_MEMS).CPOL|=1<<6; // garde le sck à l'état haut entre deux transferts et MISO ET MOSI en high impedance


// **************** CONFIGURATION DU SPI ****************************


SSP_DeInit(); // Deinitializes the SSP peripheral registers to their default reset values.
SSP_Init(&param_MEMS); // Initialization
SSP_SetClockRate(MEMS_SPI_CLK); // 10 MHz Max
SSP_Cmd(ENABLE); // Enable SPI
SSP_LoopbackCmd(DISABLE); // Normal mode operation 
SSP_SlaveOutputCmd(DISABLE); // Slave mode disabled


// **************** MEMS TEST ********************

int who_i_am=0;
who_i_am =SSP_Test_Receive_Data();