Part Number: TMS320F28386S
Tool/software:
Currently I have 5 SPI devices connected to MCU:
- 2xADS8900B ADCs
- AD5293 digital potenziometer
- FM25V02A FRAM storage
- BT815 based display module connected to CM's SSI.
All of these have the same issue:
According to datasheets, all the devices operate with SPI mode 0 (CPOL=0, CPHA=0) except AD5293, which is a mode 1 (CPOL=0, CPHA=1) device.
So, when I do configure SPI ports to these settings, nothing works, except for BT815, at least it accepts data sent.
So I change the settings for SPI port to the opposite, mode 0 for AD5293 and mode 1 for others. After this all the device accept the commands. But:
When I read data back from devices it is shifted 1 bit! AD5293 is ok, as no reading from it is required.
So for BT815 I change SSI port to mode 1 before reading and to mode 0 back after.
For other 3 devices on SPI ports I change SPI port to mode 0 before reading and to mode 1 back after.
So common workflow for all SPI devices except AD5293 is:
(port is initally configured for mode 1, no matter the devices are mode 0)
- Send command
- Change to mode 0
- Read response
- Change to mode 1
Now everything works fine. But it is weird!
The code which works for FRAM is:
static void SPI_setReadMode(bool read)
{
SPI_disableModule(FRAM_SPI_BASE);
SPI_setConfig(FRAM_SPI_BASE, DEVICE_LSPCLK_FREQ, read ? SPI_PROT_POL0PHA0 : SPI_PROT_POL0PHA1,
SPI_MODE_CONTROLLER, FRAM_SPI_BITRATE, FRAM_SPI_DATAWIDTH);
SPI_setPTESignalPolarity(FRAM_SPI_BASE, SPI_PTE_ACTIVE_LOW);
SPI_enableModule(FRAM_SPI_BASE);
}
void FRAM_Read(uint32_t addr, void *buf, uint32_t len) {
FRAM_CS_LOW();
SPI_WriteByte(FRAM_SPI_HANDLE, 0x03); // READ
SPI_WriteByte(FRAM_SPI_HANDLE, (addr >> 8) & 0xFF);
SPI_WriteByte(FRAM_SPI_HANDLE, addr & 0xFF);
uint8_t *p = (uint8_t*)buf;
uint32_t i;
SPI_setReadMode(true);
for (i = 0; i < len; i += 2)
{
uint8_t w = SPI_ReadByte(FRAM_SPI_HANDLE);
p[i / 2] = w << 8;
w = SPI_ReadByte(FRAM_SPI_HANDLE);
p[i / 2] |= w;
}
while (SPI_isBusy(FRAM_SPI_HANDLE));
FRAM_CS_HIGH();
SPI_setReadMode(false);
}
And for BT815 on CM:
void HAL_SPI_ReadBuffer(uint8_t *Buffer, uint32_t Length)
{
HAL_SPI_Write(0);
SSI_disableModule(SSI0_BASE);
SSI_setConfig(SSI0_BASE, CM_CLK_FREQ, SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 12000000, 8);
SSI_enableModule(SSI0_BASE);
for(; Length; Buffer++, Length--)
{
*Buffer = HAL_SPI_Write(0);
}
SSI_disableModule(SSI0_BASE);
SSI_setConfig(SSI0_BASE, CM_CLK_FREQ, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 12000000, 8);
SSI_enableModule(SSI0_BASE);
}
The scope shows everething is ok on SPI lines with this code, but 1 bit shifted without.
Changing the bit rate for ports does not affect this behaviour. (The bit rate for FRAM chip is 40MHz by datasheet, I tried reducing it to 400kHz, same result).
I noticed same issue previousely on F2837x devices.
IMPORTANT NOTICE
I will attach the scope shots later, as now I am not at the device, but, Scope shows correct data in mode 0 in BOTH directions for all devices and mode 1 for AD5293.
So the problem is difinitely in SPI/SSI hardware in MCU.

