4-wire LPSPI on RT1170

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

4-wire LPSPI on RT1170

4,231 次查看
landerega
Contributor I

Hello,

I am having trouble reading from the RT1170 evaluation board in SPI 4-wire mode. I read the AN5320 and also the i.MX RT1170 Processor Reference Manual but I cannot solve two main problems:

1. Before reading the data (as I work in master mode) the processor has to send 4 command bytes. So first I send 4 bytes in transmit mode (this works just fine). After these 4 bytes are sent I change the  Pin configuration register (base->CFGR1 |= LPSPI_CFGR1_PINCFG(kLPSPI_SdiInSdiOut);) to swap SDI and SDO pins (I do not know why but this is necessary if I want DATA0 & DATA1 bits to read properly). The problem is that it changes the pin configuration BEFORE finishing the send operation, therefore in the last byte DATA0 and DATA1 pins are swapped. Before changing CFGR1 register I wait for the TX fifo to be empty.

2. When reading (once the first 4 bytes are transmitted) I start reading. To do so I clear the RXMSK value in the TCR register (no save the data in the FIFO) and then I set the TXMSK to start a transmission (trigger the clocks so the slave starts responding). The problem in this case is that I do not know how to stop the trasmission process when I want to. As I want to read 4 bytes I wait for the RXFifoCount to be 4 and then I stop the transmission by clearing the continuous mask and clearing the TXMSK value in the TCR register. It always read at least 5 bytes and the stop process does not work properly either. 

 

I know I am doing something wrong but I cannot figure out what. As I mentioned before, I followed the instructions on the AN5320 appnote and I also read the reference manual to check for possible registers to read or write but I did not have any success.

 

I attach the main file. The project is based on the polling_b2b_transfer_master but it has been severely changed to be used as 4 wire mode. The main problem (the reading function) is called "LPSPI_MasterReceiveBlocking".

 

Any suggestion will be appreciated,

Lander 

0 项奖励
回复
4 回复数

4,168 次查看
landerega
Contributor I

i

0 项奖励
回复

4,189 次查看
nxf77486
NXP TechSupport
NXP TechSupport

Hello,

 

Thankyou in advance for contacting NXP support.

This AN5320 is for our product KL28Z, for this RT11700 product please find some examples of the use of the SPI mode.

Regarding your two points mentioned:

  1. For this I would recommend to wait for clear flag on the sending operation to proceed. So it is ot affected before finishing the operation.
  2. For this I would first recommend to not use non-blocking functions this could affected to it to wait until a certain number of bytes is arriving and affecting that you are not getting the 4 bytes required.

Please let me know if you have any other question I will be happy to assist you.

0 项奖励
回复

4,161 次查看
landerega
Contributor I

Hello,

I did notice that AN5320 was for another product but in the RT1170 there is no documentation about using SPI as 4-wire (QuadSPI). I tried to find any related information or demo but I could not find anything related. If you happen to have some demos or documentation I would be grateful if you could send them to me. 

Regarding your two points mentioned:

  1. For this I would recommend to wait for clear flag on the sending operation to proceed. So it is ot affected before finishing the operation.

I tried that, after sending the first 4 bytes I tried with this register:

"for(readData = 0; readData<400;readData++)
{    if(base->SR & LPSPI_SR_TCF_MASK)
        readData = 500;
    asm("nop");
}"

With this logic the processor should wait for 400 cycles or if the TCF (Transfer completion flag according to RT1170 reference manual) is set it should continue as well. When debugging, I can see that it goes out of the for with readData == 400, meaning that the flag has not been set. 

  1. For this I would first recommend to not use non-blocking functions this could affected to it to wait until a certain number of bytes is arriving and affecting that you are not getting the 4 bytes required.

What kind of blocking functions should I use? I currently clear the LPSPI_TCR_RXMSK_MASK and wait for the RX fifo to have the amount of bytes that I want, 4 in this case.

 

I would really appreciate any tips or help that you can give me and I look forward to hearing from you,

Lander

0 项奖励
回复

4,152 次查看
nxf77486
NXP TechSupport
NXP TechSupport

Hello,

Thank you in advance for your response.

I would recommend to give a look into a master example in the SDK, they could be helpful as a reference. For the flag status I believe that there could be an non appropriate manage of use. Als o regarding your question of the non-blocking functions inside de lpspi drivers you will find them (status_t LPSPI_MasterTransferNonBlocking(LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_transfer_t *transfer)) this is an example.

The reason I recommend this is because this function transfers data using an interrupt method. This is a non-blocking function, which returns right away. When all data is transferred, the callback function is called.

And I believed based on you application description it is better to work with the use of interruptions instead of polling.

Please let me know if you have any other question.

0 项奖励
回复