3 Wire SPI Working

cancel
Showing results for 
Search instead for 
Did you mean: 

3 Wire SPI Working

2,143 Views
mohwaqas12
Contributor III

Hello guys,

Hope you are having fun using mqx.

I have a question regarding getting SPI to work with 3 Wire SPI slave device.

I want to interface graphics lcd with my Kinetis K60 board.On my board , MOSI is connected to slave's SDA( Slave SPI data pin ) using 10k register. and MISO is connected directly to SDA. According to slave datasheet, master device should float SDA pin during read operation.What i am assuming is that master would output 16 clock pulses ( 2 bytes )  with 1st byte containing read command  from master and 2nd byte would contain valid data from slave. now my question is

1 : How to run spi in half duplex mode. ie disable tx or float SDA pin during read operation.

2 : Do i have to disable spi mosi pin using port control to stop it from sending any data on MOSI during 2nd byte read operation.

3: Do i have to pull up/down spi mosi pin using port control settings to float that pin.

I tried mqx spi driver both with FULL/Half Duplex settings, but unfortunately using fread/fwrite in both cases send and receive data simultaneously.

I have also checked K60 reference manual  , there they have written in spi features that it supports three-wire synchronous transfer but i cannot find anything in spi registers. neither they have any info how to disable tx or rx or make it work in half duplex mode.

Does anyone know how to interface and talk to 3 wire compatible slave using K60. How do i make it work. 

Any help in this regard would be appreciated.

Regards

0 Kudos
1 Reply

358 Views
pavel_chromy
NXP Employee
NXP Employee

Dear Muhammad,

there is probably a confusion about the principle the SPI operates:

3-wire SPI It is always full-duplex. There is no way the controller could tell whether the application is sending or receiving data. To generate SPI clocks the software writes to PUSHR register and there is no way to distinguish whether it is real data or just a dummy pattern.

The full/half duplex option of the SPI driver affects behavior related to data handling in sw, while the physical interface acts always as full-duplex.

So the only way to solve this is to disconnect the SPI module from the pin using port control as you indicated. To automate this I suggest you to create custom CS callback routine with virtual and handle switching of data direction by virtual CS number.

Please have a look at the latest MQX IO user's guide for more information about SPI driver operation, including CS callback.

Best regards, Pavel

0 Kudos