lpcware

Dumb SPI question

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by mubes on Sat Nov 23 17:13:23 MST 2013
Help!

I've got a simple SPI configuration problem, but I can't see the wood for the trees....in its distilled form, I've produced it below just using loopback to send an output back into the input again, and I've pulled the register setting apart just to make it all slightly more obvious what I'm doing.

The problem is that I can only read back 0x01FF0000 from the RXDAT register...but then it gets confusing. If I go to the LPCExpresso Peripheral Browser I _do_ see the correct value for RXDAT (i.e. incrementing), but if I look at memory location 0x40058014 in LPCExpresso I see the value that I am reading back....this is deeply confusing to me.

I'm not expecting instant answers or anything, but this is the second evening I've spent battling this and I'd really appreciate a few pointers where to look next.  I'm 100% sure it'll be a facepalm when I find it, but can I the hell as like get to the bottom of it at the moment...

If it's useful to anyone I'll produce an executable version of the code below so you can experience the problem for yourself.  Board is in standard config and I've reproduced the problem both on an LPCExpresso and my own 812 based board.  Only very slightly odd thing is that I'm using the internal oscillator, but I can't understand why that would cause a problem.

Thanks in advance for any pointers.

DAVE


#include "config.h"
#include "printf.h"

#define SPIPORT LPC_SPI0
#define SPI_FRAMELEN  15

static volatile uint32_t rxedData=0;


void spiInit(void)

{
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11); // Enable SPI0
LPC_SYSCON->PRESETCTRL &= ~(1<<0);
LPC_SYSCON->PRESETCTRL |= (1<<0);// Reset SPI0

LPC_SWM->PINASSIGN3=(LPC_SWM->PINASSIGN3&0x00FFFFFF)|(8<<24); // CLK on P0_8
LPC_SWM->PINASSIGN4=(LPC_SWM->PINASSIGN4&0xFF000000);
LPC_SWM->PINASSIGN4|=(9<<16);
LPC_SWM->PINASSIGN4|=(15<<8); // CS on P0_9, MISO on P0_15
LPC_SWM->PINASSIGN4|=(1<<0);// MOSI on P0_1

SPIPORT->DIV=1000;  // Don't need anything too fast - there's not much else going on!
SPIPORT->DLY=0;
SPIPORT->CFG=0;

SPIPORT->CFG=(1<<0)|(1<<2)|(1<<7);   // Enabled, master mode,
}
// ============================================================================================
void spiGet_sample(void)

{
static uint32_t i=0;

while (1)
{
// This will trigger a reception - we don't care about the sent data
SPIPORT->TXDATCTL=i++|(SPI_FRAMELEN<<24)|(1<<20)|(1<<21);
while (!(SPIPORT->STAT&1));
rxedData=SPIPORT->RXDAT;
printf("%X\n",rxedData);
}
}

Outcomes