Content originally posted in LPCWare by tecnoemerson on Fri Jun 15 18:09:36 MST 2012
I have board where LPC2368 use SSP0 to set DAC MCP4922 by SPI.
I have tried setup SSP to work like SPI, but i didn't have success, below is part of code, please check if is is ok.
static int fnInitMCP4922(void)
{
POWER_UP(PCSSP0); // power up the SSP used
PINSEL3 |= (PINSEL3_P1_20_SCK0 | PINSEL3_P1_21_SSEL0 | PINSEL3_P1_23_MISO0 | PINSEL3_P1_24_MOSI0); // SSEL, MOSI, MISO and SCK pins enabled - on SSP0
SSP0CR0 = 0; // ensure disabled (master mode)
SSP0CPSR = 2; // set clock prescaler (even prescale 2..254)
SSP0CR0 = (FRS_FREESCALE_SPI | DSS_8_BIT | ((((SSP_CLOCK/2 + 2000000/2)/2000000) - 1) << SSP_SCR_SHIFT)); // set 2MHz and mode
SSP0CR1 = SSP_SSE; // enable
_WRITE_PORT(0, ~PORT0_BIT4); //LOW P0.4 - cs line active low
WriteSpiData(0xFF);
WriteSpiData(0xFF);
_WRITE_PORT(0, 0XFF); //UP P0.4 - cs line
}
static void WriteSpiData(unsigned int data)
{
while ((SSP0SR & SSP_TFE) == 0) { // wait for the transfer to complete
}
SSP0DR = data;
}
Thanks
Emerson