Daniel Rogers

SPI0DR register always loaded with oxFF on a read.

Discussion created by Daniel Rogers on Feb 3, 2006
Latest reply on Feb 15, 2006 by Daniel Rogers
I are trying to read a register on a MAX7301 device. The logic analyser tells me that the data on the pins is correct. I read of 0xFF when I should be getting 0x55.
 
Code:
void MAX7301_SPI_init( void ){SPI0CR1 = 0x50;SPI0CR2 = 0x00;DDRS |= 0xE0;PERS |= 0x10;PTS |= 0x80;MAX7301_WriteMAX7301_Config,MAX7301_On);}void MAX7301_Write(uchar cCommand, uchar cData){PTS &= ~0x80; - SS lowwhile(!(SPI0SR & 0x20));SPI0DR = cCommand; - MAX commandwhile(!(SPI0DR & 0x20));SPI0DR = cData; - MAX dataasm("nop"); x 23 times for delay.PTS |= 0x80; - SS high }uchar MAX7301_Read(uchar cCommand){uchar cData;cCommand |= 0x80;PTS &= ~0x80; - SS lowwhile(!(SPI0SR & 0x20));SPI0DR = cCommand;while(!(SPI0SR & 0x20));SPI0DR = cData; - rubish dataasm("nop"); x 23 times for delayPTS |= 0x80; SS highwhile(!(SPI0SR & 0x20));SPI0DR = 0x00; - shift data outwhile(!(SPI0SR & 0x20));SPI0DR = 0x00; - shoft data outwhile(!(SPI0SR & 0x80));cData = SPI0DR; - read data.return cData;}

 
The MAX shift register is 16 bits wide therefore I need to write 2 dummy bytes to get it shifted out to the S12 buffer.
I can write to registers fine and if I put the logic analyser on the signal lines the lines toggle exactly as expected. The SPI0DR registor however always reads 0xFF. for the registor I are reading off it should be 0x55. I know this as it is what I have loaded it with. If it wasnt loaded with 0xff I would not be able to toggle the status of the relivant port pins. The registor is RW that I are trying to read.
(Moderator edited post to highlight source code)

Message Edited by Alban on 02-03-2006 10:07 AM

Outcomes