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

Thread: SPI chip that works find on a Uno but will not work with teensy 3.6

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Posts
    7

    SPI chip works fine on a Uno but will not work with teensy 3.6

    People

    I could use some help. I designed a circuit board to drive motors using the teensy 3.6. I've been very happy with the teensies and use them to drive brushless gimbal motors for my robots: example.

    So I designed another PCB to drive motors similar to the video but in this case I wanted to use the AMS AS5048A position sensor.
    AS5048A brochure and datasheet.

    This chip is 3.2v, uses SPI, and seems to be used quite commonly for this application. I have bought several modules from mouser.

    There is a PWM out signal on the module that varies with position of a magnet. The module is also supposed to report the position via SPI. This works on the an Uno. When the module is connected to the teensy, the PWM out on the module still works - SPI does not. Indicating the chip is powered, and is reading the position properly, but communications seem to be broken.

    The code is at this github repo.
    The circuit is here
    Board layout is here

    The code engages in good SPI hygiene by opening and closing the connection with:

    SPI.beginTransaction(settings);
    //Send the command
    digitalWrite(_cs, LOW);
    SPI.transfer(left_byte);
    SPI.transfer(right_byte);
    digitalWrite(_cs,HIGH);

    //Now read the response
    digitalWrite(_cs, LOW);
    left_byte = SPI.transfer(0x00);
    right_byte = SPI.transfer(0x00);
    digitalWrite(_cs, HIGH);

    //SPI - end transaction
    SPI.endTransaction();
    Ths max serial clock period on the AS5048A is 100 ns.

    I am using the following pins on the teensy 3.6
    • SCK 13
    • MISO 12
    • MOSI 11
    • CS 25

    Pin behavior on the scope:
    • SCK - Sporadic spikes highly, normally low
    • MOSI - Sporadic spikes low, normally high
    • MISO - Remains low
    • CS - Sporadic spikes low, normally high

    Other debugging items:
    • Nothing else is on the SPI bus.
    • Yes, I have checked all my connections a million times.
    • No, I dont have a digital logic analyzer

    Please offer suggestions for things I could do to debug this thing either in software or hardware.

    Please help this monster come alive.
    Last edited by owhite; 04-21-2018 at 02:21 PM. Reason: changed title

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,396
    Might help to know how they are actually wired? Looks like the devices have 8 pins, but your encoder connections have 6? I am assuming you just wire both the 3.3v and 5v to each other to the unit, like the wiring diagrams show in pdf? How long are the wires? ...

    Also did you try just trying one unit wired to it?

    Also would try adding one or more Pull up resistors to the SPI setup. Probably for sure on MISO pin, maybe SCK as well?

    Search forum, to see if any other hints, like: https://forum.pjrc.com/threads/35882...48a#post112138

    Maybe try adding in some delays? With the code:
    Code:
    SPI.beginTransaction(settings);
    //Send the command
    digitalWrite(_cs, LOW);
    SPI.transfer(left_byte);
    SPI.transfer(right_byte);
    digitalWrite(_cs,HIGH);
    
    //Now read the response
    digitalWrite(_cs, LOW);
    left_byte = SPI.transfer(0x00);
    right_byte = SPI.transfer(0x00);
    digitalWrite(_cs, HIGH);
    
    //SPI - end transaction
    SPI.endTransaction();
    Maybe add something like: delayMicrosoconds(5);
    After setting the cs LOW?

    Maybe try slower SPI Clock speed. It says a minimum of 50+50ns for the clock but maybe nto working properly... Maybe try something like 8mhz...

    Again just doing shotgun answer hopefully something hits...

  3. #3
    Junior Member
    Join Date
    Apr 2018
    Posts
    7
    Thanks. I just discovered that before coming back to the forum - one of your suggestions is correct - the transition from the send to the read is too short. Adding a delayMicroseconds() did the trick. Thanks much.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    Quote Originally Posted by owhite View Post
    Please help this monster come alive.
    Wow, that's an awesome looking build.

    I hope you'll share some details when it's working!

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    Quote Originally Posted by bonifacio View Post
    In Tensy you have connected: SCK 13, MISO 12, MOSI 11 and CS 25. In the arduino UNO or MEGA which pins do I have to use? I need this a lot
    That is a question for the Arduino forums.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    maybe a spam bot? (2 out-of-place questions posted to old threads on same day registering the new account...)

  7. #7
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    Ok, I‘ll clean that up...

    Edit: Done. @Paul: if you‘ll need a short break from T4, you might perhaps consider processing the long, long ip blocklist...

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    Ha... I need to get *back* to working on T4. Have really fallen behind the last couple weeks with this damn cold.

    But yeah, seems spammers are getting back in lately. Will try to get to the IP list next weekend. Doing it in a hurry isn't effective, since the real long-term benefit comes from spending time really looking at patters in the geolocation info and ASN ownership.

Posting Permissions

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