How does the DSPI driver of the R41Z work?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How does the DSPI driver of the R41Z work?

1,023 Views
cral_martin
Contributor II

Hello community,

I am trying to communicate a R41Z-TA-A to a Serial Flash device (SST25VF040B) which uses the SPI. I've got an example library for the Serial Flash and I want to do my own driver for the flash but with the functions of the examples.

First of all I was trying to understand the examples given on the SDK that uses the DSPI. I am using the dspi_polling_transfer as base (although I've change almost everything), the r41z as master and the flash as slave. Here is the code for the configuration of the master:

config.png

The flash needs the CE or CS (Chip Select or Chip Enable) to be Low in order to be active that's why I set the pcsActiveHighOrLow to kDSPI_PcsActiveLow. Is that enough to set the CS from high to low each time that I want to send a command from the r41z to the flash or should I do something else in addition?

Next problem: As I mentioned I want to send simple commands, a byte bit by bit with each clock cycle (that's how the flash works) so I am trying to use the simplest functions of the DSPI driver as following:

funciones.png

For the second function (Send_Byte) I'm not sure if I have to send bit by bit (the commented code) or if the function DSPI_MasterWriteData allready sends the byte bit by bit with each clock cycle. After sending that byte the flash is suppossed to send back another byte, but I get always the same answer so I guess I'm doing something wrong. So here's the second question: does any function of the driver send a byte bit by bit with each clock cycle? Am I using correctly the DSPI_MasterWriteData function? Should I use a different one?

Also I would need the same for the Get_Byte function because I'm also not sure if the reading is ok or not.

Finally I post here the main code:

main.png

Thank you all for your time. 

Regards,

Cristina.

Labels (2)
0 Kudos
5 Replies

897 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Cristina, I hope you're doing well!

 

API reference for the different MCU families is provided along with the SDK for each MCU.

The KW41Z/R41Z's SDK has a document called the MCUXpresso SDK API Reference Manual_MKW41Z4, containing information and example code for all of the different supported peripherals in KW41Z/R41Z devices, also including reference information for the different functions included in the SDK.

 

This document can be found in the following path:

<…\SDK_SDK_2.2.1_FRDM-KW41Z\docs\MCUXpresso SDK API Reference Manual_MKW41Z4.pdf>

 

For information about the DSPI module driver, could you please check Chapter 11 of said document?

 

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 Kudos

897 Views
cral_martin
Contributor II

Hi Sebastian,

I've already read the "DSPI: Serial Peripheral Interface Driver" chapter of the Reference Manual and its examples, as you can see my code is pretty similar to the example with the difference that in the example is used the function DSPI_MasterTransferBlocking and I'm trying to use easier funtions like DSPI_WriteData and DSPI_ReadData.

Thanks

Cristina.

0 Kudos

897 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Cristina,

 

Information transferred using the DSPI module is sent as full bytes, with a bit being sent each clock cycle (depending on the module's configuration). This can be can be configured using the dspi_master_config_t configuration structure.

 

The DSPI_MasterTransferBlocking and DSPI_MasterTransferNonBlocking functions might be better suited for ease of use and the purpose you want to use the module for. These functions receive a DSPI configuration structure and two buffers (one for Tx and another one for Rx). The Tx buffer can be specified as an array of however many bytes you need to send in a single transmission, with also the possibility to receive using the same transfer function, in the specified Rx buffer.

 

Example code for a typical application of these functions can be found on Chapter 11.2.2.1 of the MCUXpresso SDK API Reference Manual_MKW41Z4.

 

If you want to use the DSPI_MasterWriteData function instead of the MasterTransferBlocking functions, an example code can be found in section 11.2.7.26 of the same document.

 

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 Kudos

897 Views
cral_martin
Contributor II

Hi Sebastian:

Thank you for your help! I understand what you say, I've been trying to use both code examples that you mention and in both cases the Rx buffer is filled with ones everytime. Maybe it's not a code error and there's something wrong with the flash. I post here the code with the transfer functions instead of the write data function. If you see that there's any error could you please let me know?

C1.jpg

C2.jpg

C3.jpg

C4.jpg

C6.jpg

Again thank you for your time and help!

Regards,

Cristina.

0 Kudos

897 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Cristina,

 

Could you please check the pin configuration? Which pins are you configuring for the DSPI module you're using?

 

Could you please check the corresponding pins with a logic analyzer or an oscilloscope to see if any kind of signal is being outputted from the pins?

 

Please let me know if you still have any issues.

 

Best regards,

Sebastian

0 Kudos