This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

5505 SPI Read / Write is Invalid

I'm trying to perform a full duplix 8-bit read/write on the SPI.  However, my SPIDAT1:2 registers go from 0x0000:0000 -> 0xFFFF:FFFF.

Even if I had a bad connection, or hardware problem with the other device, shouldn't only 8 of the bits change?  The fact that all 32 bits are changing seems to indicate that Im setting up the SPI wrong, or something similar.

Thanks,

-Jason

 

Here's my code:

void SPI_Init() {
    unsigned short i;
   
    SYS_PRCR = SYS_PRCR & ~0x0080;        //take out of reset
    PCGCR1 = PCGCR1 & ~0x0002;            //enable clock
    SPI_SPICCR = SPI_SPICCR & ~0x8000;    //disable clock
    SPI_SPICDR = 0x0363;                    //clk=115200 hz
    SPI_SPICCR = SPI_SPICCR | 0x8000;    //enable clock
    SPI_SPIDCR1 = 0x0000;
    SPI_SPIDCR2 = 0x0000;
    for(i=0; i<0xFFF; i++) { }
}

unsigned short SPI_RW(unsigned short data) {
    unsigned short i;

    //8 bit write
    SPI_SPICMD1 = 0x0000;         //1 character
    SPI_SPIDAT2 = data << 8;
    SPI_SPIDAT1 = 0x0000;
    SPI_SPICMD2 = 0x003A;         //CS0, 8 bits per character, write
    i=0;
    while(SPI_SPISTAT1 & 0x0002 == 0) { if(i++ == 0xFFFF) {break;} }    //wait for CC=1
    i=0;
    while(SPI_SPISTAT1 & 0x0001 != 0) { if(i++ == 0xFFFF) {break;} }    //wait for BUSY=0

    return(SPI_SPIDAT1);
}