Teensyview and using other SPI devices on the same bus

Status
Not open for further replies.

dmilrtime

Member
Hello All,

Using the Teensy 3.2 and Teensyview in addition to an SPI based Mouse Sensor.

My issue is when I only have the code setup to run just the Mouse Sensor via SPI it works fine. When I only have something like the Screen Demo example running it also works perfectly. Both applications are the exact same hardware just different code loaded.

When I combine them the mouse sensor stops working. The mouse sensor uses a different SPI mode and I have tried using the transactions with the SPI (https://www.pjrc.com/teensy/td_libs_SPI.html) and that does not seem to work.

What I am wondering is if there is a compatibility issue between the Teensyview library and the standard SPI library. I am thinking that the Teensview usage of the SPI hardware is overriding the standard SPI library??

Anyone have experience using the Teensyview and sharing the SPI bus with other devices? How did you get them to play nice?

Thanks,
Dave
 
KurtE worked with TeensyView more than anyone I suspect. More details would help.

A short sample of the code - that would show the two SPI modes in play - there was one case posted some weeks back where polarity change (?) caused trouble on the first transfer likely due to processor hardware issue - not sure if you can locate that post?

Also notes on the CS pins selected. And a photo might confirm some small detail if possible. With multiple devices they must properly go 'neutral' on the data lines when not selected.
 
Again hard to say without seeing more of your actual code. Usually Transactions help.

Yes, I have played with Teensyview and have my own versions... The question comes in how well things work when they both use different modes.

I remember a thread recently where someone was changing the mode on the SPI line and the change did not happen as quickly as was needed or some such thing and I believe they were able to resolve it in their case changing the mode, then sending a null character without the CS pins being selected and then do their SPI stuff with the CS selected.

Again don't remember which thread, or what hardware was involved, but you might do a search or just try doing something like I mentioned.

Alternatively you might try changing one of the libraries to try using the same modes and see if that helps.
 
Hello All,

Thanks for the tips. I actually resolved the issue and it had nothing to do with SPI but with the Mouse Sensor. I was reading the Mouse Sensor in Burst Mode and that wasn't clearing the Motion flag (and respective IO pin). So what looked like my SPI stopped working it turns out the sensor itself stopped. Once I change the way I read the sensor everything started working as I expected.

Dave
 
Oh and I did successfully implement the transactions and it worked very well.
Code:
byte adns_read_reg(byte reg_addr) {
 
  //Set the SPI bus for short term needs
  SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3));
  
  adns_com_begin();
  
  // send adress of the register, with MSBit = 0 to indicate it's a read
  SPI.transfer(reg_addr & 0x7f );
  delayMicroseconds(100); // tSRAD
  // read data
  byte data = SPI.transfer(0);
  
  delayMicroseconds(1); // tSCLK-NCS for read operation is 120ns
  adns_com_end();
  //Done with SPI so let it go
  SPI.endTransaction();
  delayMicroseconds(19); //  tSRW/tSRR (=20us) minus tSCLK-NCS

  return data;
}
 
Status
Not open for further replies.
Back
Top