This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28069M: SPI Communication Issue

Part Number: TMS320F28069M

When I use the code below, I get the expected recieved data. However, when I change the SPICHAR bits in the SPICCR register from 16 bit to 8 bit, I get values that are multiplied by a factor of 256. Why is that happening?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
void spi_init()
{
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase, enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x007F; // SPI Baud Rate = LSPCLK/128
SpiaRegs.SPICCR.all =0x009F; // 16-bit char bits, SPI loopback mode enabled, Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x2041;
SpiaRegs.SPIFFCT.all=0x0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The code below is what I use to test the SPI communication.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Void MotorPositionSaveTask()
{
unsigned int MotorPosition = 0;
unsigned int i = 0;
while(1)
{
while(SpiaRegs.SPIFFTX.bit.TXFFST); // Wait until the FIFO Buffer is empty and the chip select line is deactivated
SpiaRegs.SPITXBUF = 0x06; // Set write enable latch (WREN)
while(SpiaRegs.SPIFFTX.bit.TXFFST); // Wait until the FIFO Buffer is empty and the chip select line is deactivated
SpiaRegs.SPITXBUF = 0x02; // Write memory data (WRITE)
while(SpiaRegs.SPIFFTX.bit.TXFFST >= 4); // Wait until the FIFO Buffer is clear to send while keeping the chip select line is activate
SpiaRegs.SPITXBUF = 0x00; // Memory address of write location (MSB)
while(SpiaRegs.SPIFFTX.bit.TXFFST >= 4); // Wait until the FIFO Buffer is clear to send while keeping the chip select line is activate
SpiaRegs.SPITXBUF = MotorPosition++&0x00FF; // Data to Write (LSB)
for(i=0;i<4;i++)
rdata[i] = SpiaRegs.SPIRXBUF; // Read data (MSB)
Task_sleep(1000);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX