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.

TMS320F28377D: Bit shift problem of SPI communication

Part Number: TMS320F28377D


Tool/software:

Hello,

I'm trying to read the device id of adxl345 via spi communication.
It should be 11100101, but it turns out to be 11110010.
I think it's being bit shifted to the right.

Here is my code. 

void readFromSPI(Uint16 __reg_address, int num, Uint16 _buff[])
{

Uint16 _address = 0x0080 | __reg_address;

// If Multi-Byte Read: Bit 6 Set
if(num > 1) {
_address = _address | 0x0040;
}

// Reset the Rx FIFO pointer to zero
SPI_resetRxFIFO(SPIB_BASE);
SPI_resetTxFIFO(SPIB_BASE);

GpioDataRegs.GPACLEAR.bit.GPIO27 = 1;

int i=0;

_buff[i] = SPI_transmitreceiveByteOnceMine(SPIB_BASE, 8U, _address);


printf("%d : %d\n", i, _buff[i]);

GpioDataRegs.GPASET.bit.GPIO27 = 1; 


}

uint16_t
SPI_transmitreceiveByteOnceMine(uint32_t base, uint16_t charLength, uint16_t data)
{
uint16_t rxData =0;
uint16_t rxDataEmu =0;

ASSERT(((HWREGH(base + SPI_O_CCR) & SPI_CCR_SPICHAR_M) + 1) == charLength);

SPI_disableFIFO(base); // Disable FIFO register
SPI_enableFIFO(base); // Enable FIFO register

// Write to SPI Transmit buffer
// Write register what i want to read
SPI_writeDataBlockingFIFO(base, (data<< (16U - charLength))&0xFF00);

while(SPI_getRxFIFOStatus(base) < SPI_FIFO_RX1)
{
}
rxData = SPI_readDataBlockingFIFO(base);

// Write dummy data
SPI_writeDataBlockingFIFO(base, 0x0000);

while(SPI_getRxFIFOStatus(base) < SPI_FIFO_RX1)
{
}
// Read data
rxData = SPI_readDataBlockingFIFO(base);
printf("receive: %d\n", rxData);

return(rxData);
}

This is my SPI setting.

void mySPIB_init(void)
{
// Must put SPI into reset before configuring it
//
SPI_disableModule(SPIB_BASE);

SPI_setConfig(SPIB_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL1PHA1,
SPI_MODE_CONTROLLER, mySPI0_BITRATE, mySPI0_DATAWIDTH);
SPI_setPTESignalPolarity(SPIB_BASE, SPI_PTE_ACTIVE_LOW);
SPI_disableLoopback(SPIB_BASE);
SPI_setEmulationMode(SPIB_BASE, SPI_EMULATION_STOP_AFTER_TRANSMIT);

//
// FIFO and interrupt configuration
//
SPI_enableFIFO(SPIB_BASE);
SPI_setFIFOInterruptLevel(SPIB_BASE, SPI_FIFO_TXEMPTY, SPI_FIFO_RX1);
SPI_clearInterruptStatus(SPIB_BASE, SPI_INT_RXFF);
SPI_enableInterrupt(SPIB_BASE, SPI_INT_RXFF);

//
// Configuration complete. Enable the module.
//
SPI_enableModule(SPIB_BASE);
}

I don't know what the problem is.

Could you help me?

Regards,

WooJoung Lim

  • Hello,

    Per the datasheet for the adxl345, the device ID at reset is 0b11100101, you are correct.

    At a glance, I don't see any obvious issue. However, I am uncertain of one thing- why are you disabling and re-enabling the FIFO in your send/receive function?

    Regards,
    Jason Osborn