lpcware

Problem With SSP Code

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by naveed_33 on Mon Jan 21 13:58:49 MST 2013
hello,
i have written a code for SPI with DMA but it seems that the data is not being transmitted over the SPI. i will be thankful if someone can help me with this. my code is given below.

=========================================================

#include "lpc18xx_gpdma.h"
#include "lpc18xx_cgu.h"
#include "lpc18xx_libcfg_default.h"
#include "debug_frmwrk.h"
#include "lpc18xx_scu.h"
#include "lpc18xx_ssp.h"
#include "lpc18xx_gpio.h"


void send_data(unsigned short int a)
{
// GPIO_ClearValue(7, 0x40000);

SSP_SendData(LPC_SSP1, a);
while (SSP_GetStatus(LPC_SSP1 , SSP_STAT_BUSY));
//GPIO_SetValue(7, 0x40000);
}
int main ()
{
int  a;
int b=0;
int count =0;
GPDMA_Channel_CFG_Type GPDMACfg;
SSP_CFG_Type SSP_ConfigStruct;
a= (unsigned int)&b;
SystemInit();
CGU_Init();
////////////////////////////////////////////////////////
//debug test      //
////////////////////////////////////////////////////////
scu_pinmux(0x9,2,MD_PLN_FAST,FUNC0);
GPIO_SetDir(4, 0xffffffff, 1);
GPIO_ClearValue(4, 0xffffffff);
GPIO_SetValue(4, 0xffffffff);
////////////////////////////////////////////////////////
//SPI configs            //
////////////////////////////////////////////////////////
/* Configure SSP1 pins*/
scu_pinmux(0xF,4,MD_PLN_FAST,FUNC0);// func2=SSP1 SCK0
scu_pinmux(0xF,6,MD_PLN_FAST,FUNC2);// func2=SSP1 MISO0
scu_pinmux(0xF,7,MD_PLN_FAST,FUNC2);// func2=SSP1 MOSI0
// P f4,f5,f6,f7
scu_pinmux(0x3,3,MD_PLN_FAST,FUNC2);// P3.3 connected to SCL/SCLKfunc2=SSP0 SCK0
scu_pinmux(0x3,6,MD_PLN_FAST,FUNC2);// P3.6 connected to nCSfunc2=SSP0 SSEL0
scu_pinmux(0x3,7,MD_PLN_FAST,FUNC2);// P3.7 connected to SOfunc2=SSP0 MISO0
scu_pinmux(0x3,8,MD_PLN_FAST,FUNC2);// P3.8 connected to nSIfunc2=SSP0 MOSI0
// p 33,36,37,38
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_ConfigStruct.Databit=16;
//make ssp1 master and ssp0 slave
// Initialize SSP peripheral with parameter given in structure above
SSP_Init(LPC_SSP1, &SSP_ConfigStruct);
SSP_ConfigStruct.Mode=SSP_MASTER_MODE;
// Enable SSP peripheral
SSP_Cmd(LPC_SSP1, ENABLE);
SSP_ConfigStruct.Mode=SSP_SLAVE_MODE;
// Initialize SSP peripheral with parameter given in structure above
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);

//////////////////////////////////////////////////////////
// dma configurations//
//////////////////////////////////////////////////////////
// Setup GPDMA channel --------------------------------
// channel 0
GPDMACfg.ChannelNum = 0;
// Source memory
GPDMACfg.SrcMemAddr =  (unsigned int)(&LPC_SSP0->DR);
// Destination memory
GPDMACfg.DstMemAddr = (unsigned int) a;
// Transfer size
GPDMACfg.TransferSize = 1;
// Transfer width
GPDMACfg.TransferWidth = GPDMA_WIDTH_HALFWORD;
// Transfer type
GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA;
// Source connection - ssp0 receive
GPDMACfg.SrcConn = GPDMA_CONN_SSP0_Rx;
// Destination connection - unused
GPDMACfg.DstConn = 0;
// Linker List Item
GPDMACfg.DMALLI = 0;
// Setup channel with given parameter
GPDMA_Setup(&GPDMACfg);
//GPDMA_ChannelCmd(0, ENABLE);
/////////////////////////////////////////////////
//test part        //
/////////////////////////////////////////////////
while (1)
{
b++;
send_data(0xabcd);
count = SSP_ReceiveData(LPC_SSP0);



}
return 0;}

Original Attachment has been moved to: main_0.c.zip

Outcomes