How to Receive data in spi slave mode?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to Receive data in spi slave mode?

3,321件の閲覧回数
myna
Contributor III

Hello. support team.

I use s32k118 & 3.0 SDK.

Now I have a problem that spi read operation in slave mode.

Slave sends well data to the master. but Slave can not receive data from the master.

uint8_t slaveDataSend = 0x14;

uint8_t slaveDataReceive = 0x0;

LPSPI_DRV_SlaveTransfer(DRV_SPI_SLAVE, &slaveDataSend, &slaveDataReceive, 1);

slaveDataSend --> Master receive well slave write data.

slaveDataReceive -->  Slave can not receive Spi Read data from the master.

Could you please let me know how to receive spi data in slave mode?

or

Could you send me a sample code about spi read operation in slave mode?

ラベル(1)
0 件の賞賛
返信
5 返答(返信)

3,026件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi MinYeop Na

Are you able to see the data in a scope that is been transmitting by the master side? in the MOSI line? the example code in the SDK is a fully functional code example, so you should be able to use this example to see the SPI transfer working with the LPSPI_DRV_SlaveTransfer function.


Have a great day,
TIC

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

0 件の賞賛
返信

3,026件の閲覧回数
myna
Contributor III

Hello. Jorge Antonio Alcala Vazquez

there is current spi waveform. ( c1 : clk // c2 : mosi // c3 : CS // c4 : miso )

pastedImage_1.png

I think that waveform is output correctly.

but I don't know why slave doesn't receive data.

And when should I use function(LPSPI_DRV_SlaveTransfer)?

I think the slave should sync to the master.

Thank you.

Best Regards.

0 件の賞賛
返信

3,026件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi MinYeop Na

The SlaveTransfer function must be called before any action of the master side. The master will output the clock and the slave should be "ready" for the transfer. Is your master able to see data from the slave side? the same data that is in the scope and the same data that was sent in the slaveDataSend variable?

Regards

Jorge Alcala

0 件の賞賛
返信

3,026件の閲覧回数
myna
Contributor III

Hi. Jorge Alcala

The Master Can receive well data from the slave. 

But, My problem is that the Slave can not receive data from the Master.

There is Master&Slave SPI  Flow Diagram

%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22SPI%20FLOW%20DIAGRAM%22%20style%3D%22swimlane%3Bhtml%3D1%3BchildLayout%3DstackLayout%3BstartSize%3D20%3Brounded%3D0%3Bshadow%3D0%3BlabelBackgroundColor%3Dnone%3BstrokeColor%3D%23000000%3BstrokeWidth%3D1%3BfillColor%3D%23ffffff%3BfontFamily%3DVerdana%3BfontSize%3D8%3BfontColor%3D%23000000%3Balign%3Dcenter%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22140%22%20y%3D%2220%22%20width%3D%22380%22%20height%3D%22450%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Master%22%20style%3D%22swimlane%3Bhtml%3D1%3BstartSize%3D20%3B%22%20vertex%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20y%3D%2220%22%20width%3D%22210%22%20height%3D%22430%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%224%22%20value%3D%22%22%20style%3D%22line%3BstrokeWidth%3D2%3Bdirection%3Dsouth%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22100%22%20y%3D%2220%22%20width%3D%2210%22%20height%3D%22410%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%225%22%20value%3D%22Master%20Spi%20WriteRead%22%20style%3D%22text%3Bhtml%3D1%3Bresizable%3D0%3Bpoints%3D%5B%5D%3Bautosize%3D1%3Balign%3Dleft%3BverticalAlign%3Dtop%3BspacingTop%3D-4%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22105%22%20y%3D%2288%22%20width%3D%22130%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%226%22%20value%3D%22Trigger%20Interrupt%22%20style%3D%22text%3Bhtml%3D1%3Bresizable%3D0%3Bpoints%3D%5B%5D%3Bautosize%3D1%3Balign%3Dleft%3BverticalAlign%3Dtop%3BspacingTop%3D-4%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22105%22%20y%3D%2220%22%20width%3D%22100%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%227%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BexitX%3D0.055%3BexitY%3D0.367%3BexitDx%3D0%3BexitDy%3D0%3BentryX%3D0.055%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3BexitPerimeter%3D0%3BentryPerimeter%3D0%3B%22%20edge%3D%221%22%20parent%3D%222%22%20source%3D%224%22%20target%3D%2210%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22290%22%20y%3D%2285%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22480%22%20y%3D%2285%22%20as%3D%22targetPoint%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%228%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BexitX%3D0.25%3BexitY%3D0.5%3BexitDx%3D0%3BexitDy%3D0%3BexitPerimeter%3D0%3BentryX%3D0.25%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3BentryPerimeter%3D0%3B%22%20edge%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22105.20689655172418%22%20y%3D%22130.65517241379314%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22296.2413793103449%22%20y%3D%22130.65517241379314%22%20as%3D%22targetPoint%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%229%22%20value%3D%22Slave%22%20style%3D%22swimlane%3Bhtml%3D1%3BstartSize%3D20%3B%22%20vertex%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22210%22%20y%3D%2220%22%20width%3D%22170%22%20height%3D%22430%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2210%22%20value%3D%22%22%20style%3D%22line%3BstrokeWidth%3D2%3Bdirection%3Dsouth%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%229%22%3E%3CmxGeometry%20x%3D%2281%22%20y%3D%2220%22%20width%3D%2210%22%20height%3D%22410%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2211%22%20value%3D%22%26lt%3Bb%26gt%3B%26lt%3Bfont%20style%3D%26quot%3Bfont-size%3A%2015px%26quot%3B%26gt%3BISR%26lt%3Bbr%26gt%3B%26lt%3B%2Ffont%26gt%3B%26lt%3B%2Fb%26gt%3B%26lt%3Bbr%26gt%3BLPSPI_DRV_SlaveTransfer%22%20style%3D%22rounded%3D1%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%229%22%3E%3CmxGeometry%20x%3D%2287%22%20y%3D%2245%22%20width%3D%22165%22%20height%3D%2255%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3EpastedImage_3.png

%3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22SPI%20FLOW%20DIAGRAM%22%20style%3D%22swimlane%3Bhtml%3D1%3BchildLayout%3DstackLayout%3BstartSize%3D20%3Brounded%3D0%3Bshadow%3D0%3BlabelBackgroundColor%3Dnone%3BstrokeColor%3D%23000000%3BstrokeWidth%3D1%3BfillColor%3D%23ffffff%3BfontFamily%3DVerdana%3BfontSize%3D8%3BfontColor%3D%23000000%3Balign%3Dcenter%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22140%22%20y%3D%2220%22%20width%3D%22380%22%20height%3D%22450%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22Master%22%20style%3D%22swimlane%3Bhtml%3D1%3BstartSize%3D20%3B%22%20vertex%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20y%3D%2220%22%20width%3D%22210%22%20height%3D%22430%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%224%22%20value%3D%22%22%20style%3D%22line%3BstrokeWidth%3D2%3Bdirection%3Dsouth%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22100%22%20y%3D%2220%22%20width%3D%2210%22%20height%3D%22410%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%225%22%20value%3D%22Master%20Spi%20WriteRead%22%20style%3D%22text%3Bhtml%3D1%3Bresizable%3D0%3Bpoints%3D%5B%5D%3Bautosize%3D1%3Balign%3Dleft%3BverticalAlign%3Dtop%3BspacingTop%3D-4%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22105%22%20y%3D%2288%22%20width%3D%22130%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%226%22%20value%3D%22Trigger%20Interrupt%22%20style%3D%22text%3Bhtml%3D1%3Bresizable%3D0%3Bpoints%3D%5B%5D%3Bautosize%3D1%3Balign%3Dleft%3BverticalAlign%3Dtop%3BspacingTop%3D-4%3B%22%20vertex%3D%221%22%20parent%3D%223%22%3E%3CmxGeometry%20x%3D%22105%22%20y%3D%2220%22%20width%3D%22100%22%20height%3D%2220%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%227%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BexitX%3D0.055%3BexitY%3D0.367%3BexitDx%3D0%3BexitDy%3D0%3BentryX%3D0.055%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3BexitPerimeter%3D0%3BentryPerimeter%3D0%3B%22%20edge%3D%221%22%20parent%3D%222%22%20source%3D%224%22%20target%3D%2210%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22290%22%20y%3D%2285%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22480%22%20y%3D%2285%22%20as%3D%22targetPoint%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%228%22%20style%3D%22edgeStyle%3DorthogonalEdgeStyle%3Brounded%3D0%3BorthogonalLoop%3D1%3BjettySize%3Dauto%3Bhtml%3D1%3BexitX%3D0.25%3BexitY%3D0.5%3BexitDx%3D0%3BexitDy%3D0%3BexitPerimeter%3D0%3BentryX%3D0.25%3BentryY%3D0.5%3BentryDx%3D0%3BentryDy%3D0%3BentryPerimeter%3D0%3B%22%20edge%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20relative%3D%221%22%20as%3D%22geometry%22%3E%3CmxPoint%20x%3D%22105.20689655172418%22%20y%3D%22130.65517241379314%22%20as%3D%22sourcePoint%22%2F%3E%3CmxPoint%20x%3D%22296.2413793103449%22%20y%3D%22130.65517241379314%22%20as%3D%22targetPoint%22%2F%3E%3C%2FmxGeometry%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%229%22%20value%3D%22Slave%22%20style%3D%22swimlane%3Bhtml%3D1%3BstartSize%3D20%3B%22%20vertex%3D%221%22%20parent%3D%222%22%3E%3CmxGeometry%20x%3D%22210%22%20y%3D%2220%22%20width%3D%22170%22%20height%3D%22430%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2210%22%20value%3D%22%22%20style%3D%22line%3BstrokeWidth%3D2%3Bdirection%3Dsouth%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%229%22%3E%3CmxGeometry%20x%3D%2281%22%20y%3D%2220%22%20width%3D%2210%22%20height%3D%22410%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%2211%22%20value%3D%22%26lt%3Bb%26gt%3B%26lt%3Bfont%20style%3D%26quot%3Bfont-size%3A%2015px%26quot%3B%26gt%3BISR%26lt%3Bbr%26gt%3B%26lt%3B%2Ffont%26gt%3B%26lt%3B%2Fb%26gt%3B%26lt%3Bbr%26gt%3BLPSPI_DRV_SlaveTransfer%22%20style%3D%22rounded%3D1%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%229%22%3E%3CmxGeometry%20x%3D%2287%22%20y%3D%2245%22%20width%3D%22165%22%20height%3D%2255%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3C%2Froot%3E%3C%2FmxGraphModel%3

Regards

MinYeop.

0 件の賞賛
返信

3,026件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi MinYeop Na

Is the master using a GPIO interrupt to call the LPSPI_DRV_SlaveTransfer? Can you assure that the slave transfer function was called before master start the SPI "WriteRead" function?

This is important because our drivers are implemented in a method that if the SlaveTransfer function was not called before master start communication, then it can occur the behavior that you see where the Receive data is not received.

Hope this helps

Best regards

0 件の賞賛
返信