SPI using KEA128

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SPI using KEA128

跳至解决方案
1,261 次查看
jashanm
Contributor III

hi all,

         i am working on KITMC07XS5617EVB and KEA128 via SPI. I am initialising it but the SPI_D register is not updating, am initialising SPI0 using following code...

void SPI_INIT(){

  SIM_SCGC |= SIM_SCGC_SPI0_MASK;

  SPI0_C1 |= SPI_C1_SPE_MASK;

  SPI0_C1 |= SPI_C1_MSTR_MASK;

  SPI0_C1 |= SPI_C1_CPHA_MASK;

  SPI0_C2 |= SPI_C2_SPMIE_MASK;

  SPI0_S |= SPI_S_SPTEF_MASK;

  SPI0_S |= SPI_S_MODF_MASK;

  SPI0_S |= SPI_S_SPRF_MASK;

  SPI0_S |= SPI_S_SPMF_MASK;

}

am i missing something here in SPI ???

标签 (1)
0 项奖励
回复
1 解答
926 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Jashan Mahadevu,

    Which baud do you want to define? If you you define SPI0_BR=0x00, did you calculate the baud rate, whether your SPI slave device can use this baud rate?

You code have some problem, I help you do some modifications:

void SPI_INIT(){                                                                            // to initialise the SPM module...

SIM_PINSEL0 |= SIM_PINSEL_SPI0PS_MASK;  // choose PTE0, PTE1, PTE2, and PTE3. as SPI pin

  SIM_SCGC |= SIM_SCGC_SPI0_MASK;

  SPI0_BR = 0x00; //choose the right BR to get the proper baud rate

  SPI0_C1 |= SPI_C1_MSTR_MASK;

  SPI0_C1 |= SPI_C1_CPOL_MASK;

  SPI0_C1 |= SPI_C1_SSOE_MASK;

  SPI0_C1 |= SPI_C1_LSBFE_MASK;

  SPI0_C2 |= SPI_C2_SPMIE_MASK;

  SPI0_C2 |= SPI_C2_MODFEN_MASK;

  SPI0_M = 0x64;

  SPI0_C1 |= SPI_C1_SPE_MASK;

}

//Send Data

uint8_t SPI_WriteData(uint8_t *pWrite,uint32_t uiLength)

{

    uint16_t i;

    for( i=0;i<uiLength;i++)

    {

        while(!(SPI0_S & SPI_S_SPTEF_MASK ) );// take care, not just SPI_S_SPTEF_MASK

                    SPI0_D = pWrite[i];

    }

    return 1;

}

// Send and read data

uint8_t SPI_WriteReadData(uint8_t *pRead,uint8_t *pWrite,uint32_t uiLength)

{

    uint16_t i;

    for( i=0;i<uiLength;i++)

    {

        while(!(SPI0_S & SPI_S_SPTEF_MASK ) );

                    SPI0_D = pWrite[i];

        while(!(SPI0_S & SPI_S_SPRF_MASK ) );

                    pRead[i] = SPI0_D;

    }

    return 1;

}

Please try again,

Wish it helps you

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
3 回复数
926 次查看
jashanm
Contributor III

hi,
     i am using the following code to be clear.

void SPI_INIT(){                                                                            // to initialise the SPM module...

  SIM_SCGC |= SIM_PINSEL_SPI0PS_MASK;

  SIM_SCGC |= SIM_SCGC_SPI0_MASK;

  SPI0_BR = 0x00;

  SPI0_C1 |= SPI_C1_SPE_MASK;

  SPI0_C1 |= SPI_C1_MSTR_MASK;

  SPI0_C1 |= SPI_C1_CPOL_MASK;

  SPI0_C1 |= SPI_C1_SSOE_MASK;

  SPI0_C1 |= SPI_C1_LSBFE_MASK;

  SPI0_C2 |= SPI_C2_SPMIE_MASK;

  SPI0_C2 |= SPI_C2_MODFEN_MASK;

  SPI0_M = 0x64;

}

  while(SPI_S_SPTEF_MASK){                                        // checking for tx buffer

  SPI0_C1 = 0x5d;

  SPI0_C2 = 0x80;

  SPI0_D = RX;                                                                 // to send the data

  SPI0_C1 |= SPI_C1_SSOE_MASK;

  SPI0_C2 |= SPI_C2_MODFEN_MASK;

am i missing something ??

0 项奖励
回复
927 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Jashan Mahadevu,

    Which baud do you want to define? If you you define SPI0_BR=0x00, did you calculate the baud rate, whether your SPI slave device can use this baud rate?

You code have some problem, I help you do some modifications:

void SPI_INIT(){                                                                            // to initialise the SPM module...

SIM_PINSEL0 |= SIM_PINSEL_SPI0PS_MASK;  // choose PTE0, PTE1, PTE2, and PTE3. as SPI pin

  SIM_SCGC |= SIM_SCGC_SPI0_MASK;

  SPI0_BR = 0x00; //choose the right BR to get the proper baud rate

  SPI0_C1 |= SPI_C1_MSTR_MASK;

  SPI0_C1 |= SPI_C1_CPOL_MASK;

  SPI0_C1 |= SPI_C1_SSOE_MASK;

  SPI0_C1 |= SPI_C1_LSBFE_MASK;

  SPI0_C2 |= SPI_C2_SPMIE_MASK;

  SPI0_C2 |= SPI_C2_MODFEN_MASK;

  SPI0_M = 0x64;

  SPI0_C1 |= SPI_C1_SPE_MASK;

}

//Send Data

uint8_t SPI_WriteData(uint8_t *pWrite,uint32_t uiLength)

{

    uint16_t i;

    for( i=0;i<uiLength;i++)

    {

        while(!(SPI0_S & SPI_S_SPTEF_MASK ) );// take care, not just SPI_S_SPTEF_MASK

                    SPI0_D = pWrite[i];

    }

    return 1;

}

// Send and read data

uint8_t SPI_WriteReadData(uint8_t *pRead,uint8_t *pWrite,uint32_t uiLength)

{

    uint16_t i;

    for( i=0;i<uiLength;i++)

    {

        while(!(SPI0_S & SPI_S_SPTEF_MASK ) );

                    SPI0_D = pWrite[i];

        while(!(SPI0_S & SPI_S_SPRF_MASK ) );

                    pRead[i] = SPI0_D;

    }

    return 1;

}

Please try again,

Wish it helps you

Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
926 次查看
jashanm
Contributor III

hi jingjing,

               i modified my code accordingly, it works fine! thank you.

Regards,

Jashan M

0 项奖励
回复