spi

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

spi

2,406 次查看
intern_praveena
Contributor II

Is this code correct to read device id using spi flash?if wrong please anyone correct itScreenshot (119).png

0 项奖励
13 回复数

2,042 次查看
intern_praveena
Contributor II

what is the format to transmit data, bcz there is some formate lke command + data + register address.I dnt know that format?

0 项奖励

2,042 次查看
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Praveena F

This is a common format when you work with memories, first, you have to send the specific command that could be WRITE, READ, READ ID, etc. then you send the data in the size required and finaly you specify the address of the register.

As I mentioned before this is memory depended and you need to implement the code with the format that the datasheet of the memory specify.

Regards

Jorge Alcala

0 项奖励

2,042 次查看
razva_tilimpea
NXP Employee
NXP Employee

Hi,

You try to use an external flash via SPI? If yes this approach is wrong because FLASH driver provided in SDK is just for internal flash.

Please use LPSPI driver and send the right commands to your external flash based on datasheet.

Best regards,

Razvan

0 项奖励

2,042 次查看
intern_praveena
Contributor II

yes i did wrong,i m using only LPSPI but i dnt know the command to read

0 项奖励

2,042 次查看
intern_praveena
Contributor II

now this is my code,

uint8_t Master_send_buff;
uint8_t Master_receive_buff;

uint16_t transferByteCount;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(PTB,(1<<14)&(1<<15)&(1<<16)&(1<<17));

LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
PINS_DRV_WritePins(PTB,(0<<17)); //pin low to enable device(chip_select)

while(1)
{
LPSPI_DRV_MasterTransfer(LPSPICOM1,Master_send_buff,&Master_receive_buff,transferByteCount);

//LPSPI_DRV_MasterTransferBlocking(LPSPICOM1,Master_send_buff,&Master_receive_buff,transferByteCount,5);
PINS_DRV_WritePins(PTB,(1<<17)); //pin high to disable device
}

0 项奖励

2,042 次查看
razva_tilimpea
NXP Employee
NXP Employee

Hi,

You have to fill tx buffer with data specific to your external memory and in your rx buffer you should have the ID.

Best regards,

Razvan

0 项奖励

2,042 次查看
intern_praveena
Contributor II

can u pls edit my code and send i cant understnd??

0 项奖励

2,042 次查看
razva_tilimpea
NXP Employee
NXP Employee

Hi,

I can't do this. I don't know what flash device you are using and probably I don't have it on my side to validate the code.

Razvan

0 项奖励

2,042 次查看
intern_praveena
Contributor II

i m using only S32K144_100  EVB board simply.is it correct ??? 

/* Write your local variable definition here */
uint8_t Master_send_buff[5]={0x10,0x20,0x30,0x40,0x50};
uint8_t Master_receive_buff[5]={0x00};

uint16_t transferByteCount;
uint32_t rx_size;


/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(PTB,(1<<14)&(1<<15)&(1<<16)&(1<<17));

LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
PINS_DRV_WritePins(PTB,(0<<17)); //pin low to enable device(chip_select)

while(1)
{
LPSPI_DRV_MasterTransfer(LPSPICOM1,Master_send_buff,&Master_receive_buff,transferByteCount);
PINS_DRV_WritePins(PTB,(1<<17)); //pin high to disable device
}

0 项奖励

2,042 次查看
intern_praveena
Contributor II

is this correct? how i verify that data send and receive?

int main(void)
{
/* Write your local variable definition here */
uint8_t Master_send_buff[2]={0x1,0x2};
uint8_t Master_receive_buff[2]={0x1};

uint16_t transferByteCount;
uint32_t rx_size;


/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(PTB,(1<<14)&(1<<15)&(1<<16)&(1<<17));

LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
PINS_DRV_WritePins(PTB,(0<<17)); //pin low to enable device(chip_select)

while(1)
{
LPSPI_DRV_MasterTransferBlocking(LPSPICOM1,Master_send_buff,&Master_receive_buff,transferByteCount,5);
PINS_DRV_WritePins(PTB,(1<<17)); //pin high to disable device
}

0 项奖励

2,042 次查看
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Praveena F

You can corroborate if you receive data in the buffer that you specify to receive data, in this case, you have Master_receive_buff, in order to verify if you send data you can use a scope in the pad and additionaly verify if the callback is correctly called.

As my coallgue mentioned before, we couldn't test a code as long as we don't have the specific memory that you are using, but in the datasheet of the memory should have all the commands that you need to be able to communicate, if you ahve any issue with the SPI, please let us know.

Best regards

Jorge Alcala

0 项奖励

2,042 次查看
intern_praveena
Contributor II

i just want to send and receive via spi??

is this correct for??

uint8_t Master_send_buff[3] = {0x01,0x02,0x03};
uint8_t Master_receive_buff[3] = {0x04,0x05,0x06};

uint32_t rx_data_size;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);

PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(PTD,(1<<0)&(1<<1));
PINS_DRV_SetPinsDirection(PTE,(1<<0)&(1<<1));

LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
PINS_DRV_WritePins(PTE,(0<<1)); //pin low to enable device

while(1)
{
LPSPI_Master_Transmit_Data(LPSPICOM1 ,Master_send_buff,3);
LPSPI_Master_Receive_Data(LPSPICOM1 ,Master_receive_buff,3);
PINS_DRV_WritePins(PTE,(1<<1)); //pin high to disable device
}

0 项奖励

2,042 次查看
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Praveena F

Theoretical is correct the implementation, but in this example, I cannot see what LPSPI_Master_Transmit_Data is doing. Also, you want a constantly transmission and reception? you have this in a while(1) and it will be difficult to track when the transmission happens. My recommendation is using the LPSPI_DRV_MasterTransferBlocking and with the callback set a flag that indicates that the transmission has finished.

Regards

Jorge Alcala

0 项奖励