Using lib_spi with 4-pin port

If you have a simple question and just want an answer.
ffomich
Experienced Member
Posts: 119
Joined: Mon Sep 15, 2014 1:32 pm

Using lib_spi with 4-pin port

Post by ffomich »

Hello,

I want to use lib_spi 3.0.0 only for one-directional communication.

"lib_spi user guide" shows this pin connections:

port p_miso = XS1_PORT_1A;
port p_ss[1] = {XS1_PORT_1B};
port p_sclk = XS1_PORT_1C;
port p_mosi = XS1_PORT_1D;
 
I don't have p_miso pin, other pins are connected to PORT_4E (4E1, 4E2, 4E3).
 
Is it possible to assign spi interface instance from lib_spi to 4-pin port? 
If YES, how can I initialize connections between port variables & these pins?
 
Thanks in advance.

 

User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Personally have not used the SPI Library but after a quick review of the application note AN00160:

http://www.xmos.com/published/an00160-h ... ion=latest

the task will not be quick and easy to implement with your 4 bit port. However, it is very possible to use your 4 bit port to drive your SPI target device.

Questions & suggestions:

1) confirm you are planning to ONLY write to a single target SPI device since MISO pin is missing. If possible, attempt to locate and use a single bit port somewhere on your device as it will help to debug the code (ie. read back from your SPI device if the device offers this feature).

2) forget about the use of the SPI library since the example shows the use of the ports to be applied in BUFFERED mode which will only complicate things if porting to the 4 bit port. That is, if you wish to extend the XMOS SPI library then you will have to rethink how to take the status of each SPI port pin and group into a format that will allow you to use the 4 bit port in BUFFERED mode. It can be done but will be a painful exercise. Consider instead to bitbang away at the target SPI device using the 4 bit port. This will be much more straightforward.

Here is one of many articles on the internet on how to bitbang the SPI protocol:

http://www.instructables.com/id/Interfa ... nding-SPI/

What is your target SPI device ?

The vendor should supply you with timing diagrams which can be used to create your code. In the process, you will learn a great deal on the SPI operation but at the minor expense of lack of speed since you will not be using buffered ports. With buffered ports, you will have the luxury of writing to the single or 4 bit ports, etc. and "walking away" to perform some other task. In the background, the ports will continue to send out data at the port width. For example, a single bit port which is defined to be a 32 bit buffered port = a 32 bit value written to this port will continue to automatically clock out a single bit on each clock cycle till all 32 bits are sent - automatically :) This will allow you to perform other code runs, etc.