Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 3.6 is SRE configuration possible on SPI pins due to EMI issues?

  1. #1
    Junior Member
    Join Date
    Jun 2017

    Teensy 3.6 is SRE configuration possible on SPI pins due to EMI issues?

    Hi Paul/All,
    I've been playing around with what was suggested in another forum topic here to enable/disable the slew rate on digital pins of a Teensy 3.6 and I can easily do this in a sketch by simply changing the SRE bit in the port configuration register after my call to pinMode as shown here to enable/disable the feature:

    void setup(){
       uint8_t pin = 13;
       pinMode(pin, OUTPUT);
       volatile uint32_t* config = portConfigRegister(pin);     // setup pointer
       *config |= PORT_PCR_SRE;                                                     // disable slew rate
       // or to disable slew rate use the following line instead
       //*config &= ~PORT_PCR_SRE;                                               // disable slew rate
       bool pulse = true;
       while (true) {
          if (pulse) digitalWriteFast(pin, HIGH);
          else digitalWriteFast(pin, LOW);
          pulse = !pulse;
    void loop(){
       // never reached
    I'm doing this on pin 13 as a test since I want to try and implement the same when using this pin as the SCLK line for my SPI1 bus to a TFT. When I setup the sketch as noted above, I can clearly see the effect of this on my oscilloscope (200MHz). With slew rate turned off there is significant over/under shoot on the PWM signal, whereas when slew rate is enabled, this practically disappears (similar to what Paul and others have shown in the links above).

    Now I come to my problem, I'm getting some significant EMI issues from my setup when communicating with an FT813 display over SPI due to ringing / higher order harmonics from this over/undershoot with the PWM signal on SCLK and MOSI lines. So, since the sketch above was so successful in reducing (almost eliminating it), I'm trying to do the same when the pin is setup in SPI1 mode (I'm happy to reduce SPI freq a bit if needed as a result). Searching through the core I found how the SPI1 pin setup procedure differs from the normal pinMode() setup procedure, I believe the SPI setup is described in the SPCR1.enable_pins() function of avr_emulation.h (correct?). I don't see any calls to enable slew rate in the code while these pins are being initialized for SPI operation, so I tried adding similar code to that above after calling SPI.begin(), however the pins appear to be operating with slew rate disabled regardless of whether my code tries to enable it or not. I also tried editing the core library to enable the SRE bit during pin configuration but that had no effect either so returned the core to its original state.

    I did some searching on the K66 manual to see if I could find more information on it and it looked like it's possible there might be an issue using it while SPI mode is active (possibly due to the K66 using other elements of its internal hardware??). So my question is, do you know if can slew rate can be enabled when SPI1 mode is active? Any help or advice on how to enable it or even to tell me it isn't possible would be greatly appreciated.

  2. #2
    Junior Member
    Join Date
    Jun 2017
    Hello again,
    Sorry about this inquiry. Looked through it again, tracing my way through the libraries and I found that I was trying to set the SRE bit in the wrong place in the code. The pins and SPI settings are indeed setup directly in the SPI.cpp file at lines 289-301. When I inserted included code there to set the SRE bit, it worked. Quiet a difference in how clean the PWM becomes alright but of course max frequency now becomes limited by the slew rate, works fine up to 15MHz but PMW starts getting cropped above this due to slower rise times. Hopefully, it'll sort the EMI issues now! The info may still be of use to others that come across a similar problem so no harm but the issue can be closed now.
    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts