Interrupt driven spi?

06 Oct 2010

Hi,

Would it be possible to do interrupt driven spi?   I don't see it in the mbed libraries and am not sure how difficult it would be to code up on my own with the mbed libraries between me and the lpc17xx libraries .   Any pointers?

Thanks

06 Oct 2010

Have a look at the implementation in NXP's DriverLibrary. Might give you some ideas.

06 Oct 2010

Thanks Igor!  I was wondering earlier if just including their driver library like that would work after getting a small program working that included lpc17xx.h.       I will give it a shot.

23 Mar 2012

I'm working on this problem as well and would like to share results with others.

23 Mar 2012

I didn't get very far... we ended up using blocking SPI.

I am still interested though and would like to hear about progress you may have made.

23 Mar 2012

try this out, SPI on P0.15, P0.16, P0.17, P0.18 (check your mbed schematics for the corresponding board pins)

volatile uint8_t data;

//interrupt handler
extern "C" void SPI_IRQHandler()
{
	uint32_t status_reg=0;

	//clear interrupt flag
	LPC_SPI->SPINT = 1<<0;

	status_reg = LPC_SPI->SPSR;

	if((status_reg & (1<<7)) == 1<<7)
		data = LPC_SPI->SPDR;
}



//SPI init call
void spi0_init(void)
{
    LPC_SC->PCONP |= (1<<8);                                //power up SPI
    LPC_SC->PCLKSEL0 |= (1<<16);                            //run SPI0 at 96MHz (prescale 1)
    
    //configure PIN-outs
    LPC_PINCON->PINSEL0 |= (0xC0000000);	            //SCK
    LPC_PINCON->PINSEL1 |= (3<<4) | (3<<2) | (3<<0);        //MISO, MOSI, SSEL
    LPC_PINCON->PINMODE0 |= (0x80000000);                   //no pull-up or down on SCK
    LPC_PINCON->PINMODE1 |= (2<<4) | (2<<2) | (2<<0);       //no pull-up or down on MISO, MOSI, SSEL

    //clock counter/prescaler setup
    LPC_SPI->SPCCR = 12;                                    //run SPI clock at 8MHz
    
    //interrupt enabled, MSB first, slave mode, SCK active high, first clock sampled, 8 bits per transfer
    LPC_SPI->SPCR = (8<<8) | (1<<7) | (0<<6) | (0<<5) | (0<<4) | (0<<3) | (0<<2) | (0<<0);   //(CPOL=0, CPHA=0)

    //enable interrupt
    NVIC_SetPriority(SPI_IRQn);
    NVIC_EnableIRQ(SPI_IRQn);
}

in your main loop, catch the SPI data byte by flagging a variable in the interrupt handler.

also, you might want to pull-up your slave select line from the master SPI

this assuming you are running your mbed at 96MHz

23 Mar 2012

@Joshua: You might want to follow my new topic: http://mbed.org/forum/mbed/topic/3369/