LPC1227 SPI PROBLEM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1227 SPI PROBLEM

658 Views
mikejaber17
Contributor I

Hello,

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_14|=(1<<1);
LPC_IOCON->PIO0_1 &=~(0b111<<0); // Select MEMS nCS
LPC_IOCON->PIO0_16&=~(0b111<<0); // Select MISO on PIO0_16 
LPC_IOCON->PIO0_16|=(1<<1);
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).CPHA=0;
(param_MEMS).CPOL=0;
(param_MEMS).Mode=0;
(param_MEMS).FrameFormat=0;
(param_MEMS).DataSize=0;

(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
(param_MEMS).FrameFormat&=~(0b11<<4);
(param_MEMS).Mode&=~(1<<2);

// **************** 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;
SSP_Test_Send_Data(0x8F);
SSP_Test_Send_Data(0);
who_i_am =SSP_Test_Receive_Data();

Labels (1)
Tags (1)
0 Kudos
1 Reply

462 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Mike Jaber,
Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.
To provide the fastest possible support I'd highly recommend you to refer to SSP demos in the LPC12xx CMSIS Driver Library.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos