lpcware

ssp(spi) on lpc1785

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by castiel on Mon Dec 03 21:51:08 MST 2012
Please help.I try to transfer 3 bytes back-to-back(1st byte-command,2-3 addres) via ssp.Data is transmitted but incorrectly.Where is my mistake? Here is my code.

#include <LPC177x_8x.h>
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_ssp.h"
#define SSP_DR_BITMASK(n)   ((n)&0xFFFF)

void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data)
{
SSPx->DR = SSP_DR_BITMASK(Data);
}



int main(void) {
LPC_SC->PCONP   |= (1<<15);            /* enable power to GPIO & IOCON  */
LPC_SC->PCONP |=(1<<21);//enable ssp0
/* APB 48МHz*/
LPC_SSP0->CPSR |= (0x2);  //clock prescaler SSP0=2

LPC_IOCON->P0_15 |= (1<<1) ; //sck    
LPC_IOCON->P0_16 |= (1<<1);//ssel
LPC_IOCON->P0_17 |= (1<<1);//miso
        LPC_IOCON->P0_18 |=(1<<1);//mosi

LPC_SSP0->CR0 |= (0x787);  // CPOL=0,CPHA=1,Frame Format=SPI,Serial Clock Rate=7,8 bit mode     
  LPC_SSP0->CR1 |= (1<<1);//sse enable,master mode
//master clock rate 3МHz

SSPTransfer(0x2);
SSPTransfer(0x0);
SSPTransfer(0x2);

}

Outcomes