9 years, 8 months ago.

How do I change polarity of the SPI data pin on the FRDM K64F

I'm using the SPI interface on PTD1-PTD3 and the I/O pin polarity is inverted, e.g. logic high between output words. How do I change the default polarity to be logic low?

Thanks!

Michael

3 Answers

9 years, 8 months ago.

I believe that is the default on the Freescale ones, high output when not used. The clock polarity/phase can be changed to comply with the required SPI waveforms, but I don't think the SPI data polarity is ever defined. I believe for example the NXP microcontrollers put the data pin in high-Z mode when they aren't used.

If it is important for you, you can manually switch it to a GPIO input node, or low GPIO output. (I have had for example a situation where the SPI device could be disabled by turning of the power supply, but due to the high data pin on Freescale devices it was still semi-powered via ESD diodes).

Accepted Answer

I used mode 3, it seems that the MOSI jumps up too early and makes the LSB always be "1". Please refer to the picture I attached below.

posted by Zhe Zhang 11 Mar 2015
9 years, 1 month ago.

/media/uploads/zhyena/frdm_k64f_spi_mode3.png

FRDM_K64F, SPI MODE 3 Supposed to send 170 ( 0xAA), but received 171. It seems that the MOSI jumps up too early and makes the LSB always be "1". How can I solve the problem?

FRDM_K64F, SPI MODE 3 Test

#include "mbed.h"
 
SPI device(PTD6,NC,PTD5);

int main() {
    int i = 0;
    device.format(8,3);
    while(1) {
        device.write(0x55);
        device.write(0xAA);
        wait(1);
    }
}
 

I think it might be related to: https://github.com/mbedmicro/mbed/issues/840. It seems KSDK SPI peripheral (although iirc K20 uses the same one) has some timing issues with current code. Should get a seperate bug report on github.

posted by Erik - 11 Mar 2015
9 years, 8 months ago.

not sure, but in PIC (wow a long long time ago)

you set mode 0..3 or 1..4

look at SPI Mode

:)

Ceri

posted by ceri clatworthy 20 Aug 2014

SPI mode only affects the SPI clock line though ;). Generally the SPI data line is dont care outside the SPI packets.

posted by Erik - 20 Aug 2014