How to configure K60 SPI PCSIS

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

How to configure K60 SPI PCSIS

1,332 Views
broccolee
Contributor III

Hi,

I am using TWR-K60N512, with PK60DN512Z VMD10 chip. I am trying to set up the SPI module to communicate with an IMU, which uses SPI mode 3, CPOL = 1, CPHA = 1. 

I chose SPI0_CS0_b as the slave select pin, which is PORTD11 according to the tower module user's manual, and the inactive state is when it is driven high.

How do I configure the SPI_MCR_PCSIS register? It says to assert if the inactive state of PCSx is high. How do I figure out which bits to assert? I am assuming it corresponds to 'x', but what is it? Is it '0' from the SPI0_CS0_b, or '11' from PORTD11?

According to the number of PCS signals for SPI0 on page 155 (I'm using this manual: K60P144M100SF2V2RM), there are SPI_PCS[5:0] signals. Really? 63 chip select signals?! The tower module manual only shows two options: SPI0_CS0_b and SPI0_CS1_b. Please clarify.

I have the same question for setting up SPI_PUSHR_PCS register. Please clarify the difference between PCSIS[4:0] and PCS[5:0], why is it fewer in PCSIS?

If you can't answer the above, please just show me how to configure both SPI_MCR_PCSIS and SPI_PUSHR_PCS with the IMU SPI mode.

Thanks.

0 Kudos
8 Replies

727 Views
egoodii
Senior Contributor III

You can apply 'any binary pattern you like' into PCS[5:0] to be transferred to the (potential!) associated pins as the command that is this SPIx_PUSHR to process.  That is, you MAY 'decode' said pattern externally, and yes, if the chip implementation defines all 6 pins for a module, you may externally decode 63 chip selects.  Now that all being said, just about anybody uses the CS bits just 'one at a time', and only sets one PCS bit (active state as defined by PCSIS -- why the 6th is 'not there' is an amusing question, probably a manual error and PCSIS[5:0] exist--SPI0_PCS5 seems to be missing other places too, but shows as ALT3 on PTB23).  For ME I actually 'cheat' and use one 'chip select' signal as a Command/!Data 'address bit' into my display module, and then assert either just 'chip select' for command-access-bytes, or both said chip-select AND this second 'chip select' (LOW) for data-port access -- that way said control stays directly with the SPI byte in the FIFO, with no external 'overhead'.

The named K60 has the potential for all 6 CS from SPI 0, 4 from SPI 1, and 2 from SPI 2.  Sending these controls to I/O pins is controlled under (mostly) ALT-2 of the table in 10.3.1.  All the pin-function options are probably NOT listed in the TWR-K60 document, and not ALL I/O pins come to 'where you can get at them' in said TWR-K60 PCB.

So to hit CS0, you put 0b000001 into PCS, with the PCSIS bits all set to '1'.

0 Kudos

727 Views
broccolee
Contributor III

Thanks for the info!

I can't seem to get my SPI module to work still. It gets stuck at line 81 in the attached code, this line:  "while ( ( SPI0_SR & SPI_SR_TCF_MASK ) == 0 );" .

I think I configured the settings correctly according to the IMU datasheet. I'm trying to read from ADIS16362 IMU (http://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16362.pdf ).

Any idea how I should go about troubleshooting and fix this?

Thanks.

0 Kudos

727 Views
egoodii
Senior Contributor III

Line 20 sets CS (D11) under SPI-module control, so HOPEFULLY your 'manual operations' on GPIOD are 'moot'.

Line 47 sets 'HALT', but the |= in line 67 will FAIL to clear said halt --- you need an &= of ~(( 1 << SPI_MCR_HALT_SHIFT ) | ( 1 << SPI_MCR_FRZ_SHIFT )) [or ~(SPI_MCR_HALT_MASK  |   SPI_MCR_FRZ_MASK ) ]  to clear some bits in a control register.  Probably same for line 68.

You might want to grab some driver code from a Kinetis example...

0 Kudos

727 Views
broccolee
Contributor III

I'm not sure my crazy operation on the chip select GPIO pin is doing anything, I was trying to follow the datasheet and drive the signal high and low for transmission. Sooo am I right to assume that you're implying that I don't need to do so when I've already configured the ports that are designated for SPI? =\

I did find an example SPI driver code for the TWR-K60(Kinetis 100MHz Rev 2 Example Projects ) and some related stuff (https://community.nxp.com/thread/372146#comment-562567), which is what I based my code on. I am really confused about the first example for TWR-K60, it uses the same ports that I'm using for the SPI module, but it's SPI2, whereas the user manual shows SPI0... Which is right? Also, the example didn't set up the clock for PORTD, maybe it didn't need to for this example??

Anyway, I have unstuck the process by changing initialization part of SP0I_MCR from '|=' to '=', that probably means I configured something wrong. This didn't matter because it's reading nothing, probably not reading at all. 

The examples communicate with the TWR-MEM module, which I don't have. Could you point me to an example that communicates with an external SPI device such as an IMU? Preferably baremetal project examples.

0 Kudos

727 Views
egoodii
Senior Contributor III

Correct -- the SPI module will do ALL CS setup/toggle/hold for you if muxed-in to do so, as you have.  GPIO will be disconnected.

The 'Rev 2' examples may NOT be your 'best' choice, as you are working with Rev 1 silicon (Z at the end of the part number).  By the same token, you probably shouldn't be using the 'V2RM' document you list---the Reference Manual for V2 silicon.  Your P/N isn't listed on the first page of THAT manual because you need K60P144M100SF2RM, plus the additional note that your chip starts with 'P' (Prototype) meaning 'very early silicon', and is subject to a 'number' of errata, based on the mask code you will find on it.

Be all that as it may, as far as I know pins PortD11-14 ARE muxed with SPI2 for either version of chip. and so the SPI2 example you have should work.

pastedImage_0.png

pastedImage_1.png

It is confusing, but note that while these 'Tower Elevator' SPI pin names all start with 'SPI0...', the TWR-K60 CPU module has them linked to SPI2, as in this bit of schematic:

pastedImage_0.png

0 Kudos

727 Views
broccolee
Contributor III

Good news! I am able to read something now that I've switched to SPI2. The output data such as supply voltage, product ID, accelerometer measurements are correct!  HOWEVER, it only works the first time after a USB plug cycle, so it outputs nothing if I were to reflash the code again without doing a USB plug cycle first. Sometimes, it still outputs nothing anyway...

How should I approach this different problem now? I've attached my code for your review, I've only made some minor changes.

Thanks.

0 Kudos

727 Views
egoodii
Senior Contributor III

Sorry, I think we have assume that such complicated interaction with 'other functions' is some 'higher level' giving you trouble...

0 Kudos

727 Views
broccolee
Contributor III

No problem, I'll start a different discussion on this. Thanks for your help and clarifications.

0 Kudos