Hi All,
I’m looking for your assistance to get the SSP SPI1 port on the Logomatic V2 operational. While I am specifically looking to communicate with the LSI3LV02DQ accelerometer module, i’m thinking that this should be relatively generic in its setup.
I have spent considerable time searching this forum (and others related to LPC2000) and reviewing the NXP manual without much success.
So here is what i have so far.
My SSP SPI1 init code is:
//Initialise I/O Ports and Peripherals
//Outputs
IODIR0 = SCLK0 | MOSI0 | CS_SD | SCLK1 | MOSI1 | CS_ACCEL | LED_RED | LED_GREEN;
//Inputs
IODIR0 &= ~(MISO0 | MISO1 | BATT_MEAS);
//Make sure peripheral devices are not selected
UnselectAccelerometer();
//Initialize the SPI bus
SPI0_Init(); // Select pin functions for SPI0 signals.
S0SPCCR = 64; // SCK = 1 MHz (60MHz / 64 ~= 1Mhz)
S0SPCR = 0x20; // Master, no interrupt enable, 8 bits
SPI1_Init(); // Select pin functions for SPI1 signals.
SSPCR1 = 0x00; // Disable SSP SPI1
// SSPCPSR clock prescale register, master mode, minimum divisor is 0x02
// SCK1 = PCLK / (CPSDVSR * [SCR+1])
SSPCPSR = 60; // SCK = 1 MHz (60MHz / 60 ~= 1Mhz)
SSPCR0 = 0x07; // CPHA=0, CPOL=0, FRF=01(SPI mode), DSS=0111(8 bits)
// SSPCR1 = 0x02; // Master, SSP enable
SSPIMSC = 0x00; // no interuupt enable
SSPCR1 |= (1 << 1); // SSP Enable
for(i = 0;i < 8;i++)
{
Dummy = SSPDR; // clear the RxFIFO
}
As best as i can interpret chapter 13 of the NXP manual, this appears to be okay.
Now, my SPI1.h code is
#define BSY (1<<4)
void SPI1_Init(void);
void SPI1_send(char c);
char SPI1_recv(void);
char SPI1_send_recv(char c);
and SPI1.c code is
#include “spi1.h”
#include “LPC214x.h”
#include <stdio.h>
void SPI1_Init(void){
//This function needs to go in bootup() of Main.c
PINSEL1 = (PINSEL1 & ~(3 << 2)) | (1 << 3); // Enable SCLK1 on P0.17
PINSEL1 = (PINSEL1 & ~(3 << 4)) | (1 << 5); // Enable MISO1 on P0.18
PINSEL1 = (PINSEL1 & ~(3 << 6)) | (1 << 7); // Enable MOSI1 on P0.19
}
void SPI1_send(char c){
while (!(SSPSR & 0x02));
SPI1_send_recv(c);
}
char SPI1_recv(void){
return SPI1_send_recv(0xff);
}
char SPI1_send_recv(char c){
int in;
SSPDR = c; // Place data to be sent into SPI data register
while(!(SSPSR & !BSY)); // Wait for transfer to complete
in = SSPDR&0xff; // Return the character placed in the SPI data register by the slave
return in;
}
As best as i have been able to confirm my application is stopping at the SPI1_send_recv(c) function.
For info i guess, i am using WINARM and programmers note pad for this project.
If you have a working example of code for the SPI1 port on the logomatic V2 OR can advise the correction to my code (above) i’d appreciate you help.
Thanks
Neil