SPIMaster_LDD not working correctly

cancel
Showing results for 
Search instead for 
Did you mean: 

SPIMaster_LDD not working correctly

335 Views
yadhukrishnanvm
Contributor III

Hi,

   I am doing SPI operations on SST25VF020 spi flash memmory in KL25Z128 custom board. The below is my code

#define BLOCK_SIZE 1

int main(void)

{

uint8_t OutData[BLOCK_SIZE ] = {0x05}; 

uint8_t InpData[BLOCK_SIZE];
LDD_TDeviceData *spi_ptr;
LDD_TUserData *fp;
LDD_TError Error;

PE_low_level_init();

HOLD_SetVal();

WP_SetVal();
spi_ptr=SM1_Init(NULL);
while(1)
{
CS_ClrVal();
Error = SM1_ReceiveBlock(spi_ptr, InpData, BLOCK_SIZE);
Error = SM1_SendBlock(spi_ptr, OutData, BLOCK_SIZE );

while (!SM1_GetBlockReceivedStatus(spi_ptr))

{
SM1_Main(spi_ptr);
}

CS_SetVal();
}


#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif

for(;;){}
}

The above code is for just reading the status register of spi memory. I got the correct output. But when I tried to read the manufacure ID of the spi flash. I didn't get the output. For reading the manufature ID we have to send "0x90" instruction and "0x000000" memory address. Please anybody tell me how to send multiple bits using the "SendBlock" instruction.

0 Kudos
9 Replies

41 Views
kerryzhou
NXP TechSupport
NXP TechSupport

HI Yadhukrishnan V M,

    Question: Please anybody tell me how to send multiple bits using the "SendBlock" instruction.

      Answer:You also can use SM1_SendBlock to send the according data.

     You can define :

OutData[0] =0x90

OutData[1] =0x00

OutData[2] =0x00

OutData[3] =0x00

OutData[4] =0xff // don't care, just for read back data.

CS_ClrVal();

Error = SM1_ReceiveBlock(spi_ptr, InpData, 5);

  Error = SM1_SendBlock(spi_ptr, OutData, 5);

while (!SM1_GetBlockReceivedStatus(spi_ptr))

{
SM1_Main(spi_ptr);
}

CS_SetVal();

   But please check the SST25VF020 datasheet at first:

pastedImage_1.png

you can find the 5th byte is the DOUT.

Then when you read the data, you will find InpData[4] is the data which you want.

 Please check it again on your side.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

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

0 Kudos

41 Views
yadhukrishnanvm
Contributor III

Dear kerryzhou,

               Thank you for your response :smileyhappy: . I have done that what you said, and I got the output, but the problem is when I send the block {0x90,0x00,0x00,0x00}, the output is only visible on the second or third debug process. I don't know why this is happening. I think using dma will solve this issue. Could you please tell me how to use the dma in spimaster_ldd component.

0 Kudos

41 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yadhukrishnan V M,

   You can run the send block directy, instead of debug one byte.

    You said the output is only visible on the second or third debug process, did you check the SPI wave? Is the SPI wave correct? You also can post some SPI wave for {0x90,0x00,0x00,0x00}.

    I think you can test the none DMA code and make it works at first. After it works, you add the dma is also not later.

   About the DMA spi code, you can refer to this post:

[Kinetis] DMA-SPI examples for L2K and K60 

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos

41 Views
yadhukrishnanvm
Contributor III

Tkank you kerryzhou‌, now I got the correct output in code warrier. But when I try it on processor expert stand alone linked using  IAR compiler, write operation is not taking place. The byte is not writing when I send the block {0x02,0x020,0x00,0x00,0x22} where 0x22 is the data byte. But in code warrier it worked correctly. I do chip erase and write enable operations before byte program but writing is not working in IAR. 

[Kinetis] DMA-SPI examples for L2K and K60  when I try to access this link it shows unauthorized! 

0 Kudos

41 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yadhukrishnan V M,

   If the same code, but the IAR not working, did you also check the SPI wave?

   What the difference between the IAR and CW project SPI wave?

   You also can check the IAR project optimization, and select none optimization in the IAR project options, then try it again.

Wish it helps you!


Have a great day,
Kerry

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

0 Kudos

41 Views
yadhukrishnanvm
Contributor III

Hi kerryzhou‌,

    I don't know how to check spi wave, please tell me how and please give any link of spi example using dma. I already done the optimization IAR, there is no difference in code between IAR and CW I don't why the write operation isn't working.

/* ###################################################################
** Filename : main.c
** Project : RCC_SPI
** Processor : MKL25Z128VLK4
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2016-12-23, 16:33, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */


/* Including needed modules to compile this module/procedure */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "SM1.h"
#include "SM1_TxDMA.h"
#include "HOLD.h"
#include "BitIoLdd1.h"
#include "WP.h"
#include "BitIoLdd2.h"
#include "CS.h"
#include "BitIoLdd3.h"
#include "DMA1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"


#define BLOCK_SIZE 5
#define BLOCKSIZE 5


/* User includes (#include below this line is not maintained by Processor Expert) */


/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */


uint8 OutData[BLOCKSIZE];
OutData[0] =0x02;
OutData[1] =0x02;
OutData[2] =0x00;
OutData[3] =0x00;
OutData[4] =0x22; // don't care, just for read back data.
//uint8 OutData[BLOCKSIZE] = {0x90,0x00,0x00,0x00,0xff};
//uint8 OutData[BLOCKSIZE] = {0x05};
uint8 InpData[BLOCK_SIZE]={0xFF};
LDD_TDeviceData *spi_ptr;
uint16 transmit_no;
uint16 receive_no;
uint16 Error;





/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/


/* Write your code here */
/* For example: for(;;) { } */
/* PORTD_PCR7: Enable Pull Up ON MISO (PORT_PCR_PE_MASK|PORT_PCR_PS_MASK) */

HOLD_SetVal();
WP_SetVal();





//SM1_TxDMA_ChInit
spi_ptr=SM1_Init(NULL);
while(1)
{
// PORTE_PCR4 |= (PORT_PCR_PE_MASK|PORT_PCR_PS_MASK);//
GPIOE_PDOR &= ~(GPIO_PDOR_PDO(0x10));
//CS_ClrVal();
Error = SM1_ReceiveBlock(spi_ptr, InpData, BLOCK_SIZE);

Error = SM1_SendBlock(spi_ptr, OutData,BLOCKSIZE);

while (!SM1_GetBlockSentStatus(spi_ptr)) { /* Wait until data block is transmitted/received */
SM1_Main(spi_ptr);
}
transmit_no=SM1_GetSentDataNum(spi_ptr);
receive_no=SM1_GetReceivedDataNum(spi_ptr);

while (!SM1_GetBlockReceivedStatus(spi_ptr)) { /* Wait until data block is transmitted/received */
SM1_Main(spi_ptr);
}
// PORTE_PCR4 &= ~(PORT_PCR_PE_MASK|PORT_PCR_PS_MASK);
//CS_SetVal();
GPIOE_PDOR |= (GPIO_PDOR_PDO(0x10));
}

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

The above is the code in IAR for writing a byte.

0 Kudos

41 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yadhukrishnan V M,

   1. check SPI wave method

      You can use the 4 channels oscilloscope to check the SPI_CLK, SPI_CS, SPI_MOSI, SPI_MISO wave, compare the wave in CW project and the IAR project.

      If you have the logic analyzer, it will be better.

  2.  SPI DMA code.

    Sorry, you don't have the authority for that link, I attached the code from that link for your reference.

Wish it helps you!

After you get the wave, please attached it.


Have a great day,
Kerry

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

0 Kudos

41 Views
yadhukrishnanvm
Contributor III

Thank you kerryzhou‌ for the code :heart::smileywink:.But how do I test this code (in which IDE), You know I have no much experience in embedded field now I am a student. So please tell me how to test this code. I will attach the SPI waves soon!

0 Kudos

41 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Yadhukrishnan V M,

   If you open the project, you will find it is the MDK project.

   Just for your reference.

   About the testing, you need to read the code carefully at first.

   This code is use the DMA to send and receive the SPI data.

   About the SPI pin which used, you can find it is using  SPI1, PTE2, PTE4, PTE1, PTE3. For details, please read the vfnSPI_Init function in SPI.C file.


Have a great day,
Kerry

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

0 Kudos