SPI don't work with Full Chip Simulation

Showing results for 
Search instead for 
Did you mean: 

SPI don't work with Full Chip Simulation

Contributor I
Hi to all,
I'm trying to use a MC9S08GT60. I'm using Full Chip Simulation to verified that all the function works fine.
I've a data that I want send by SPI, but in Full Chip Simulation I can't write on the SPI1D register.
There is the code:

byte SPI_send(char data)
while (!SPI1S_SPTEF); /* Wait for Tx buffer empty */
SPI1S; /* Read of SPI1S with SPTEF=1 */
SPI1D = data; /* Send byte */
while (!SPI1S_SPRF); /* Wait for Rx buffer full */
return (SPI1D); /* Received byte value */

When I write data to SPI1D with "SPI1D = data" nothing happens!
The memory map don't change.

Where I fail?

Best regard,
Labels (1)
0 Kudos
2 Replies

Specialist III
Hello Davide,
The SPI1D register will always read a different value than it writes because you are writing the value to be sent, but are reading the byte value returned by the SPI slave.  In simulation mode, I wouldn't expect the "returned" value  to alter since the slave end doesn't actually exist.
A comment about your SPI_send() code, the second line -
SPI1S; /* Read of SPI1S with SPTEF=1 */
This is confusing and unnecessary.  The first line that tests the SPTEF bit already reads SPI1S.
0 Kudos

Senior Contributor IV
Hi Davide,
Mac is correct in that you can't see the data you write to SPI1D by looking at SPI1D. You can however see a simulated version of what was shifted out by using the SPDO command or under the HCS08FCS menu select SPI Module and then SPDO. You can also preload a buffer for simulating data coming in on the MISO pin by SPDI. You should look here to check your code.
0 Kudos