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

Thread: Teensy 4.0 Chip Select Pins

  1. #1
    Junior Member
    Join Date
    Sep 2022
    Posts
    3

    Teensy 4.0 Chip Select Pins

    Hello PJRC Folk,

    I am attempting to use SPI to interface with a Pressure Sensor (https://invensense.tdk.com/wp-conten...20100-v1.4.pdf). There is only one using SPI communication. I have had multiple generations of this interface and the most recent does not work. I have pinpointed the problem to the Chip-Select pin - for some Chip-Select pin selections on Teensy 4.0 this code works, for others it does not. I was operating under the assumption that any Digital IO pin should function as a Chip-Select pin (excluding some libraries, but I'm only using the standard SPI library).

    I have searched through documentation on the forum and haven't found a similar issue for Teensy 4.0 as all information for standard SPI library, single device communication, says this should work.

    As an example, if I use chip-select pin 16 SPI communication works, however if I use pin 7 for chip-select SPI communication does not work.

    In general, the code selects parameters for the pressure sensor triggering an interrupt for each sample at 25Hz sample rate. The sensor drives a pin on Teensy low when new data is available, the interrupt triggers a data read, and the data is displayed in the next loop.

    I have attached my full source code as it includes a library I wrote myself.

    Thank you for any help

    ICP20100_Testing.ino
    ICP20100.h
    ICP20100.cpp

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,800
    I ran it here with nothing connected to the Teensy pins. These are the waveforms my scope sees on pins 7, 11, 12, 13.

    Click image for larger version. 

Name:	file.png 
Views:	3 
Size:	46.7 KB 
ID:	29423

    Looks like pin 7 is working as a chip select, though it might be good to first drive it to logic high before you initialize the hardware.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,800
    If pins 7 and 8 are shorted or interfering, and pin 8 stays low, maybe your could could get into an infinite interrupt loop? Might be better to use FALLING instead of LOW with attachInterrupt.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,967
    Sorry, I don't see anything obvious.

    As mentioned all digital pins should more or less act the same.

    So maybe hardware issue? A picture might help.

    for example, the picture might show if there is a bad solder joint on pin 7.

    Or maybe, that you have some other hardware setup with this. For example, the Teensy Audio board, which uses pins 7 and 8.

  5. #5
    Junior Member
    Join Date
    Sep 2022
    Posts
    3
    Thank you Paul and Kurt for your quick responses.

    At first glance, it does appear that the Chip select pin functions correctly - I am able to recreate your oscilloscope pattern, Paul - however, I am not able to consistently obtain measurements using Chip Select pin 7. To illustrate, here is the output from the exact same setup and code, only changing Chip Select from pin 16 to pin 7 on a breadboard:

    Click image for larger version. 

Name:	SPI_Issues.png 
Views:	4 
Size:	153.7 KB 
ID:	29426

    On the left of the figure is the good Chip-Select pin (e.g. pin 16), while the bad is shown on the right. In both cases I am able to initialize device communication, however programming the device settings often does not work using pin 7 chip-select, further when samples are taken (should be at 25Hz - 0.04s sample period) they are erratic indicating something is wrong with SPI communication.

    Also, per Kurt, I have attached a picture of my setup. I made a simple breakout PCB of the sensor and connections are via breadboard:

    Click image for larger version. 

Name:	ICP20100_Setup.jpg 
Views:	6 
Size:	119.8 KB 
ID:	29425
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	SPI_Issues.jpg 
Views:	4 
Size:	86.3 KB 
ID:	29424  

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,800
    Looked at the datasheet. Page 38 says the interrupt pin is open drain.

    You probably need to add a pullup resistor, like 4.7K to 10K. Or maybe using pinMode INPUT_PULLUP at the beginning of setup() could be enough?

    My guess is it's just barely working without this when not other signal is changing nearby. Maybe. At least that's my latest troubleshoot-electronics-over-the-internet guesswork.

  7. #7
    Junior Member
    Join Date
    Sep 2022
    Posts
    3
    Thank you again for your response, Paul. The sensor has an internal pull-up resistor on the interrupt pin so an external one is not needed - I added one just to confirm with no change.

    This is an interesting problem, I've noticed there are several pins which my code works every time. At this point, I'm not sure what else to look for, so I tested all Digital IO pins to see whether they could function as the Chip Select pin - this was the result:

    Click image for larger version. 

Name:	SPI_Issues_Pinout.jpg 
Views:	4 
Size:	128.4 KB 
ID:	29428

    If you're not sure still I will assume this is a device issue and continue to troubleshoot on my own - I'll update the forum if I'm able to figure out this issue.

    Thank you.

  8. #8
    Senior Member Marathonman's Avatar
    Join Date
    Sep 2020
    Location
    USA
    Posts
    129
    I had a bad 4.1 that did the same thing last year but got attacked on here when I brought it up. Come to find out the 4.1 had bad soldering done from the manufacture as I could not recreate the same issues with a new 4.1. It was freezing up when I used certain pins so I eventually desoldered all the usable parts and threw the rest in the trash. It was most likely a soldering issue when the chip was attached to the board and I have no way of doing that precision work and struggle at tssop, 603 but manage. I to had done a lot of troubleshooting but came to a point that all the time spent on the issue was not worth it in the long run.
    God luck on this issue.
    Regards,
    Marathonman

Posting Permissions

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