Its no secret, its just very similar to what you've mentioned.
Below is the code I am using,
void Init_SPI(void) {
SPI0CR1 = 0x00;
SPI0CR2 = 0x02; // 8-bit data format; Stop SPI clock when in wait mode
SPI0BR = 0x23; // Baudrate = 625kbps ; fs= 30MHz
SPI0CR1 = 0x50; // CPOL=CPHA=0; Transmit MSB first; Enable SPI in master mode
}
unsigned char SPI_TxRx(unsigned char data) {
unsigned char temp = SPI0SR,
i = 0;
SPI0DRL = data;
for (i=0; i<0x60; i++); //This delay required here; only then values written correctly to the DSP
// while(!(SPI0SR & SPI0SR_SPIF_MASK)); //Commented because the control gets stuck here.
return SPI0DRL;
}
void main (void){
unsigned char rxdata[5] = {0};
Init_SPI();
//Init DSP in SPI mode by pulling CLATCH low three times.
CLATCH_LOW;
CLATCH_HIGH;
CLATCH_LOW;
CLATCH_HIGH;
CLATCH_LOW;
CLATCH_HIGH;
//read core-register
CLATCH_LOW;
rxdata[0] = SPI_TxRx(0x01); //7bit chip address + read command
rxdata[1] = SPI_TxRx(0x08); // 1st address byte
rxdata[2] = SPI_TxRx(0x1C); // 2nd address byte
rxdata[3] = SPI_TxRx(0x00); //Transmitting dummy bytes
rxdata[4] = SPI_TxRx(0x00);
rxdata[5] = SPI_TxRx(0x00);
CLATCH_HIGH;
}
When I run the above code, rxdata gets filled as,
rxdata[0] = 0xFF
rxdata[1] = 0xFF
rxdata[2] = 0xFF
rxdata[3] = 0xFF
rxdata[4] = 0x00
rxdata[5] = 0x1A
The last two bytes are the correct data from the DSP core-register.
Is something wrong/right here?!