Hello I am doing communication with MCP3202 with LPC1768 via SPI .....But I am unable to see my data in SPDR I only got 0X00FF

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

Hello I am doing communication with MCP3202 with LPC1768 via SPI .....But I am unable to see my data in SPDR I only got 0X00FF

599 Views
akshaybuchake
Contributor I

Here is my interrupt based code:

#include <lpc17xx.h>
#include "spi.h"
#include "lcd.h"

uint8_t dummy_u8=0,test=0;

void spi_init(void)
{


//clksetting for SPI
//pclk= cclk divide by 4 = 24Mhz...
LPC_SPI->SPCCR = SPCCR_VAL ; //24// 24Mhz is now divided by 24=1Mhz final clk

LPC_PINCON->PINSEL0 |=(3U<<30); //SCK
LPC_PINCON->PINSEL1 |=(3U<<0); //SSEL
LPC_PINCON->PINSEL1 |= (3U<<2); //MISO
LPC_PINCON->PINSEL1 |= (3U<<4); //MOSI

//clk setting for SPI
LPC_SPI->SPCCR = SPCCR_VAL ;
// SPI0_CLK=(SystemFrequency / 8 ) /(SPCCR_VAL) ; // ussed to check in watch at debug
//Config SPI = Master,8Bit,CPOL=0,CPHA=0
LPC_SPI->SPCR &= ~(1<<3); // CPHA = 0 = Rising Clock Shift Data
LPC_SPI->SPCR &= ~(1<<4); // CPOL = 0 = Normal Clock "0",Active = "1"
LPC_SPI->SPCR |= (1<<5); // MSTR = 1 = Master SPI
LPC_SPI->SPCR &= ~(1<<6); // LSBF = 0 = MSB First

LPC_SPI->SPCR &= ~(15<<8); // BITS = 0000 (Reset Bits Format)
LPC_SPI->SPCR |= (1<<11); // BITS = 1000 (8 Bit Data)
LPC_SPI->SPCR |= (1<<2); // BitEnable = 1 = Enable SPI
}
void spi_dir(void)
{
LPC_GPIO0->FIODIR |= SCK ; //output
LPC_GPIO0->FIODIR |= SSEL ; //output
LPC_GPIO0->FIODIR &= ~MISO; //input
LPC_GPIO0->FIODIR |= MOSI; //output
}

void SPI_Chsel(uint8_t spich_u8)
{

if(spich_u8 == 0)
{
LPC_SPI->SPDR = 0X01;//start bit
LPC_SPI->SPDR = 0XA0;//for MCP ADC only....start,ch0,single ended mode,MSB first
}
else
{
LPC_SPI->SPDR = 0X01;//start bit
LPC_SPI->SPDR = 0XE0;//for MCP ADC only....start,ch1,single ended mode,MSB first
}
//return spich_u8;
}
uint8_t SPI_write(uint8_t spidata_u8)
{
LPC_SPI->SPDR = spidata_u8;
// while(util_GetBitStatus(LPC_SPI->SPSR,SBIT_SPIF) == 0); /* wait until data is sent */
test = Read_SPI_Status;
dummy_u8 = LPC_SPI->SPDR;
return spidata_u8;
}

uint32_t dummy;
uint8_t value_1=0,value_2=0,value_3=0;
uint16_t adc_count=0;
unsigned int i;

//uint8_t slave_data,dummy;
void SPI_IRQHandler(void) //interrupt handler for spi
{
//value |=((LPC_SPI->SPDR) << (16-(8*i)));//ADC is sending bit data but my spdr...
//..is 8 bit so by shifting data has been taken..
//...on 3 times recieve interrupt
if(i==1)
{
value_1 = LPC_SPI->SPDR & 0X00;
i++;
}
else if(i==2)
{
value_2 = LPC_SPI->SPDR & 0X0F;
i++;
}
else if(i==3)
{
value_3 = LPC_SPI->SPDR;
i++;
}
LPC_SPI->SPINT |=(1<<0); //Clear SPI interrupt

}

int main()
{

i=0;
SystemInit();
NVIC_DisableIRQ(SPI_IRQn); // disable interrupt first
spi_init();
spi_dir();
//LPC_SPI->SPDR = 0x00; //clr garbage data
dummy=LPC_SPI->SPDR; // read weather clr or not
Enable_SPI;
Enable_SPI_Interrupt ;
NVIC_EnableIRQ(SPI_IRQn);

while(1)
{

i=1;
clr_salve;
SPI_Chsel(0);//start and channel sel for MCPADC only
delayus(2000000);
dummy=SPI_write(0x00);//0 padding
adc_count= value_1 | value_2 | value_3 ;
set_salve;
}

}

0 Kudos
1 Reply

413 Views
soledad
NXP Employee
NXP Employee

Hi,

In order to isolate the issue (hardware or software) could you please test the LPCopen spi examples?

LPCOpen Software for LPC17XX|NXP 

Have a great day,

Sol

 

 

 

-----------------------------------------------------------------------------------------------------------------------

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

-----------------------------------------------------------------------------------------------------------------------

0 Kudos