Kevin Rock

SPIDR unwriteable

Discussion created by Kevin Rock on Aug 30, 2006
Latest reply on Sep 8, 2006 by Kevin Rock
I have somehow managed to make a register unwriteable.

The following code snippet initializes the SPI portion of an NE64 FreeScale chip. I am grabbing UDP packets in another section of the code and then sending them via SPI to a digital compass.

The data is coming through fine. However when I try writing it to SPIDR it simply will not change the register. I've tried hardwiring a number to SPIDR with no results. The information gets to the B register but STAB 0xDD does not write the B information to SPIDR located at 0xDD.

Can anyone give me a hint as to where I am going astray?
Kevin.

PS. I replaced the microcontroller with an exact duplicate with the same results.
KJR




void SPI_init(void)
{ // 1.25 MHz
// SPIBR: ??=0,SPPR2=1,SPPR1=1,SPPR0=0,??=0,SPR2=1,SPR1=1,SPR0=0
SPIBR = 0x66; // Set the baud rate register
// SPICR2: ??=0,??=0,??=0,MODFEN=1,BIDIROE=0,??=0,SPISWAI=0,SPC0=0
SPICR2 = 0x10; // Set control register 2
// SPICR1: SPIE=1,SPE=1,SPTIE=0,MSTR=1,CPOL=0,CPHA=1,SSOE=1,LSBFE=1
SPICR1 = 0xD7; // Set control register 1
}

interrupt void SPI(void)
{
int i=0;
int j=0;

// Send Command String to Compass
SPIDR = (UINT8) in_buf[i++]; // Send 0xA4
while ((SPISR & 0x20) == 0) ; // Wait for transmit buffer empty
SPIDR = (UINT8) in_buf[i++]; // Send command byte
while ((SPISR & 0x20) == 0) ; // Wait for transmit buffer empty
SPIDR = (UINT8) in_buf[i++]; // Send 0xA0
while ((SPISR & 0x20) == 0) ; // Wait for transmit buffer empty

// Receive Data String from Compass
out_buf[j++] = (UINT8) SPIDR; // Receive 0xA4
//while ((SPISR & 0x80) == 0) ; // Wait for receiver full
out_buf[j++] = (UINT8) SPIDR; // Receive 0x02
//while ((SPISR & 0x80) == 0) ; // Wait for receiver full
out_buf[j++] = (UINT8) SPIDR; // Receive first data byte
//while ((SPISR & 0x80) == 0) ; // Wait for receiver full
out_buf[j++] = (UINT8) SPIDR; // Receive second data byte
//while ((SPISR & 0x80) == 0) ; // Wait for receiver full
out_buf[j++] = (UINT8) SPIDR; // Receive 0xA0

// loop until SPIDR == 0xA0
// since this char ends all data and error strings

// byte out_buf[]; output to UDP packet
// byte in_buf[]; input from UDP packet
}

Outcomes