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
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