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.

SPI 24 bit communication

Other Parts Discussed in Thread: TMS320F28027

Hi,

    i am using TMS320F28027 in one of my  project. i wants to communicate TMS320F28027(master)   to AD5204(slave)  through SPI protocol

if i set SPI_CharLength_16_Bits means  it works fine. if i set SPI_CharLength_8_Bits means  it  is not working

________________________________________________________________________. 

This method is working( SPI_CharLength_16_Bits )

    SPI_write(mySpi, 0x0116);       // combined address and data   

_________________________________________________________________________

this method is not working  (SPI_CharLength_8_Bits )

    SPI_write(mySpi, 0x01);            // address
    SPI_write(mySpi, 0x16);            // data

    i think the problem is chip select pin .how to control spi chip select pin

Thanks in advance.

Ramesh

  • Hi Ramesh,

    ramesh rahi said:
        i think the problem is chip select pin .how to control spi chip select pin

    Are you using SPISTEA or any GPIO? You can configure SPISTEA as GPIO19 and control the same manually.

    Regards,

    Gautam

  • The spi data register is left aligned.
    You have to change it to
    The SPI_write(mySpi, 0x16 << 8);

    It is in the documentation but TI didn't made very much effect to make it easy to find.
  • i tried that one also .but it is not working

    i have one doubt my controller spi buffer is 16 bit. for example i want to send 24 bit data how this one is possible ?

    my part of code

    //GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_GeneralPurpose);
    //GPIO_setDirection(myGpio, GPIO_Number_19, GPIO_Direction_Output);
    //GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);

    //GPIO_setHigh(myGpio, GPIO_Number_19);


    // Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

    spi_init(); // Initialize SPI
    spi_fifo_init(); // Initialize the SPI FIFOs

    //SPI_write(mySpi, 0x0000 | 0x64<<1); // refer data sheet table 4 for shifting (64= wiper 40K)
    //GPIO_setLow(myGpio, GPIO_Number_19);
    SPI_write(mySpi, 0x00);
    SPI_write(mySpi, 0x64<<1);
    //GPIO_setHigh(myGpio, GPIO_Number_19);

    Regards,
    Ramesh
  • You want to send spi word size of 24 bit. That is not possible with the hardware. You have to disable the hardware SPI CS.
    And make you own with the GPIO option.
    So it works like this:
    GPIO CS pin low
    SPI_write(mySpi, byte1 <<8);
    SPI_write(mySpi, byte2 <<8);
    SPI_write(mySpi, byte3 <<8);
    GPIO CS pin high
  • The out put of digital trim-pot is varying when i use gpio as SPISTEA

    if i use SPISTEA pin as chip select digital trim-pot output is 40k
    if i use GPIO pin as chip select digital trim-pot output is 70k


    my code

    // Initalize GPIO
    GPIO_setPullUp(myGpio, GPIO_Number_16, GPIO_PullUp_Enable);
    GPIO_setPullUp(myGpio, GPIO_Number_17, GPIO_PullUp_Enable);
    GPIO_setPullUp(myGpio, GPIO_Number_18, GPIO_PullUp_Enable);
    //GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
    GPIO_setQualification(myGpio, GPIO_Number_16, GPIO_Qual_ASync);
    GPIO_setQualification(myGpio, GPIO_Number_17, GPIO_Qual_ASync);
    GPIO_setQualification(myGpio, GPIO_Number_18, GPIO_Qual_ASync);
    //GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync);
    GPIO_setMode(myGpio, GPIO_Number_16, GPIO_16_Mode_SPISIMOA);
    GPIO_setMode(myGpio, GPIO_Number_17, GPIO_17_Mode_SPISOMIA);
    GPIO_setMode(myGpio, GPIO_Number_18, GPIO_18_Mode_SPICLKA);
    //GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SPISTEA_NOT);

    GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
    GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_GeneralPurpose);
    GPIO_setDirection(myGpio, GPIO_Number_19, GPIO_Direction_Output);


    GPIO_setHigh(myGpio, GPIO_Number_19);


    // Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

    spi_init(); // Initialize SPI
    spi_fifo_init(); // Initialize the SPI FIFOs

    GPIO_setLow(myGpio, GPIO_Number_19);
    SPI_write(mySpi, 0x0000 | 0x64<<1); // refer data sheet table 4 for shifting (64= wiper 40K)
    GPIO_setHigh(myGpio, GPIO_Number_19);

    //GPIO_setLow(myGpio, GPIO_Number_2);
    //SPI_write(mySpi, 0x00<<8);
    //SPI_write(mySpi, 0x64<<9);
    //GPIO_setHigh(myGpio, GPIO_Number_2);


    Regards,
    Ramesh
  • dear sir,

    In my project i wants to communicate with ade7763 energy meter ic through SPI by using TMS320f28027 .

    for example if i send mode register address (8 bit) 0x09 means it will return (16 bit) 0x000C from that register.now i checked the MISO signal by CRO it gives the same output 0x000C .but the value read by my spi code is data1= 255 and data2= 0

    i tried with separate GPIO for cs .but the same problem is continuing .please help me to solve this problem

    my code

    while(1)
    {

    SPI_write(mySpi, 0x09<<8);
    DELAY_US(6);
    SPI_write(mySpi, 0x00); // dummy data 1
    DELAY_US(4);
    while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
    }
    data1=SPI_read(mySpi);
    SPI_write(mySpi, 0x00); // dummy data 2
    DELAY_US(4);
    while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
    }
    data2=SPI_read(mySpi);

    printf("data1:%d data2:%d\r\n",data1,data2);

    for(i=0;i<100;i++)
    DELAY_US(10000);
    }


    Regards
    Ramesh
  • dear sir,

    In my project i wants to communicate with ade7763 energy meter ic through SPI by using TMS320f28027 .

    for example if i send mode register address (8 bit) 0x09 means it will return (16 bit) 0x000C from that register.now i checked the MISO signal by CRO it gives the same output 0x000C .but the value read by my spi code is data1= 255 and data2= 0

    i tried with separate GPIO for cs .but the same problem is continuing .please help me to solve this problem

    my code

    while(1)
    {

    SPI_write(mySpi, 0x09<<8);
    DELAY_US(6);
    SPI_write(mySpi, 0x00); // dummy data 1
    DELAY_US(4);
    while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
    }
    data1=SPI_read(mySpi);
    SPI_write(mySpi, 0x00); // dummy data 2
    DELAY_US(4);
    while(SPI_getRxFifoStatus(mySpi) == SPI_FifoStatus_Empty){
    }
    data2=SPI_read(mySpi);

    printf("data1:%d data2:%d\r\n",data1,data2);

    for(i=0;i<100;i++)
    DELAY_US(10000);
    }


    Regards
    Ramesh
  • Ramesh,

    I will reply to this question on the new post you created.

    -Mark