HCS08DZ60, peculiar SPI problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08DZ60, peculiar SPI problem

2,775 Views
Lundin
Senior Contributor IV
I'm using HCS08DZ60 on EVB9S08DZ from Softec, with CW6.0.

The HCS08 is master and we are trying to contact a SPI slave device but cannot get it working. On the hardware level, everything is working correctly. The MOSI line sends the correct data and I get the correct response from the external circuit on the MISO pin of the mcu.

But when I read the SPI data register, the data shows up as 0xFF. That is when I have SSOE=1, if I set the /SS pin manually instead, the SPI data shows up as 0x00.

Now, if I let the program run and send several commands, I do get the right values in the SPID. So there seems to be a problem with the first byte of data sent/received. I have tried various clock settings with CPHA and CPOL, but no combination works.

void SPI_init ( SPI_Baudrate baud){

SPIC1 = 0x5E; //SPIE=0;SPE=1;SPTIE=0;MSTR=1;CPOL=1;CPHA=1;SSOE=1;LSBFE=0

SPIC2 = 0x12; //0; 0; 0; MODFEN=1 ; BIDIROE=0 ;0 ;SPISWAI=1 ;SPCO=0
SPIBR = (uint8)baud;
}


uint8 SPI_transfer(uint8 data1, uint8 data2){

volatile uint8 x;

// PTED = 0x00; // SS low

while(SPIS_SPTEF == 0) //wait until transmitter empty
;
SPID = data1; //send data1

while(SPIS_SPTEF == 0) //wait until transmitter empty
;

SPID = data2; //send data2

while (SPIS_SPRF == 0) //wait until receiver is full
;
x= SPID; //read data register

// PTED = 0x04; // SS high

return x;

}


I remember similar problems on the HCS12, which was then caused by silicon bugs. I can't find any errata for the S08 SPI though, is there one for silicon mask 1M05C?
Labels (1)
0 Kudos
Reply
5 Replies

876 Views
Lundin
Senior Contributor IV
I take it there is no errata for the DZ60?

After testing various combinations of dummy reads/writes, it seems as if the cause of the problem is a timing problem in the external slave IC. As one might have suspected at first... though, I suppose it doesn't hurt to check here so I don't spend weeks searching for something that is a known issue. :smileyhappy:

Thanks everyone who replied!
0 Kudos
Reply

876 Views
Bruce_andrew
Contributor I
SPI on the DZ60 works for me :smileyhappy: Just using it for EEprom access, but all seems fine.
0 Kudos
Reply

876 Views
allawtterb
Contributor IV
Are you using his safe suggestion of reading the first data byte only after SPRF is set?  If not this could certainly be the problem.  I would double check that all the timing is right by adding a few dummy waits inbetween some of the commands just to double check.  I have been using the DZ60 on a few products for a while now, 2 with SPI and haven't had any problems.  Most of useage has been in sending data instead of requesting though, so I probably wouldn't have seen a problem of reading the first data 2 data bytes.
0 Kudos
Reply

876 Views
bigmac
Specialist III
Hello Lundin,
 
Your code appears to send two bytes in succession, but reads only a single return byte (after both have been sent or buffered).  An overrun condition is possibly occurring, that may cause subsequent data to be missed.  Both return bytes should be read, even if the data is to be discarded.
 
The safest approach is to send only a single byte at a time, and wait until SPRF flag becomes set before reading the data byte (also clears the flag), and then sending the next byte.
 
After you first enable the SPI module, it is necessary to read SPIS, before sending the first byte.  But you appear to be already doing this by virtue of the while loop that tests the SPTEF flag.
 
Regards,
Mac
 
0 Kudos
Reply

876 Views
Lundin
Senior Contributor IV
I have tried that as well, I get the same phenomenon. There is likely some flag somewhere which doesn't get cleared as it should, though I fail to see where. Perhaps I need to dummy read both the status + data first, before sending anything?
0 Kudos
Reply