TSYS01 using SPI

Hi there,

I am using TSYS01 with my Arduino nano using the SPI.
I am a beginner and it is my first time dealing with SPI. I googled the stuff on SPI etc and finally came up with me code that is mentioned below but I do not get anything out of it. I am sure the hardware connections are fine.

I start the conversion, and display the received conversion result on tera term. The code prints 0 all the time. The code is given below. Please help what I am doing wrong and how to fix that:

[color=red]
*/

// the sensor communicates using SPI, so include the library:
#include <SPI.h>


// pins used for the connection with the sensor

const int chipSelectPin = 7; //pin 7 is Chip select1 as there are two sensors on my board
const int chipSelectPin2 = 6; //pin 6 is Chip select2 as there are two sensors on my board
const int protocolSelect = 8; // PS pin
unsigned int data =0;         // ADC conversion data
//int data1 = 0; // PROM received data
//int data2 = 0;
//int data3 = 0;
//int data4 = 0;

void setup() {
  Serial.begin(9600);

  // start the SPI library:
  SPI.begin();
  SPI.setDataMode(2);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(LSBFIRST);

  pinMode(chipSelectPin, OUTPUT);
  pinMode(chipSelectPin2, OUTPUT);
  pinMode(protocolSelect, OUTPUT);

  delay(10);
}

void loop() {

    digitalWrite(protocolSelect, LOW);
    digitalWrite(chipSelectPin, LOW);
    digitalWrite(chipSelectPin2, HIGH);

  SPI.transfer(0x1E);    //reset temp sensor
  delay (10);
  SPI.transfer(0x48);  //Start ADC conversion
  delay(10);
  data = SPI.transfer(0x00);  // read ADC conversion result
  delay(100);
  Serial.print("I received: ");
  Serial.println(data, HEX);

  digitalWrite(chipSelectPin, HIGH);
  digitalWrite(protocolSelect, HIGH);
         
  }[/color]

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

Post a connection list that shows all your connections from arduino to the chip (or a hand drawn schematic of your wiring photographed with a cell phone)

Thank you for your guidance. I have made the changes as per your recommendation. Please find the schematics attached with this post.

Thanks
-Riz

This is not what I asked for.
Reread my last post.
This is from the dsta sheet .This only shows the chip connections.
What I need yo know ( as I said), is WHICH arduino pins did you connect to WHICH pins on the chip.

Oh sorry about that. Here it is.

Regards

Got a link to TSYS01?
One thing missing is that you need to set the SPI SS pin, 10 on an Uno, to Output, so that the Uno is SPI master. If the pin goes low, and undefined pins are inputs by default after a reset (chip feature), the pin will float. If it goes low it becomes an SPI slave.
Typically SPI devices use chip select (or slave select), goes low before the SPI.transfer, then high again after.

You don't need I/O pin (d8) for PS (TSYS01-pin-16) That pin is SPI/I2C select and should be tied to ground for SPI. You are not going to switch from SPI to I2C in the middle of your program so just connect PS to ground. You should use arduino pin-10 for your primary chip select (CSB1). Also your schematic isn't exactly correct is it? You are showing two CSB pins implying you have two chips (each chip only has one CSB , pin-2). You should redraw it showing two chips The schematic you already posted for two chips has too much information. We only want exactly what you did here with one small change: show two chips and show the two arduino chip selects (pin-10 =primaray,pin, one of the pins in the group 6-9 as the secondary chip select, ie: d6)

Get rid of this (tie pin-16 to ground)

 const int protocolSelect = 8; // PS pin

Change this:

 const int chipSelectPin = 7; //pin 7 is Chip select1 as there are two sensors on my board

and redraw your schematic showing two temp chips.

Thank you guys.

I am attaching the schematics with both the chips before and after the recommendations that you made. I am not using my chip 1 at the moment. I want data only from my chip 2 (primary slave, CSB pin attached to pin 10 of Arduino as per your recommendation).
After making modifications that you suggested, I am still getting 0 as my output. I have made changes to the code as per your recommendations.

[color=red]
/*

 CSB2: pin 10 // primary SS
 MOSI: pin 11
 MISO: pin 12
 SCK: pin 13
 CSB1: pin 6 //secondary SS
 
 */

// the sensor communicates using SPI, so include the library:
#include <SPI.h>


// pins used for the connection with the sensor

const int chipSelectPin = 10; //pin 10 is Chip select1 as there are two sensors on my board
const int chipSelectPin2 = 6; //pin 6 is Chip select2 as there are two sensors on my board
unsigned long data =0;         // ADC conversion data

void setup() {
  Serial.begin(9600);

  // start the SPI library:
  SPI.begin();
  SPI.setDataMode(2);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(LSBFIRST);
  pinMode(chipSelectPin, OUTPUT);
  pinMode(chipSelectPin2, OUTPUT);

  // initalize the  data ready and chip select pins:
  
  delay(10);
}

void loop() {
  //Select High Resolution Mode

    digitalWrite(chipSelectPin, LOW);
    digitalWrite(chipSelectPin2, HIGH);

  SPI.transfer(0x1E);
  delay (100);
  SPI.transfer(0x48);
  delay(100);
  data = SPI.transfer(0x00);
  
  delay(1000);
  Serial.print("I received: ");
  Serial.println(data, HEX);

  digitalWrite(chipSelectPin, HIGH);
        
  }
[/color]

photo 2.JPG

The second schematic is much easier to follow. Just the essentials.
It's looking like the issue may be the TSYS01 communication protocol. Where did you get the code you are using to talk to it?

I used Arduino SPI library from:

and had a look at the datasheet to see how to reset the TSYS01, start conversion and then read the results. This is what I am attempting to do with my code.

  SPI.transfer(0x1E); // reset the chip
  delay (100);
  SPI.transfer(0x48); // start temp conversion
  delay(100);
  data = SPI.transfer(0x00);// read the conversion results

then I print the value of data on tera term

  Serial.print("I received: ");
  Serial.println(data, HEX);

Can you please help in correcting the code if there are any issues? Any help will be great. Thanks

Can you please post your complete sketch. Something seems to be missing.

Just out of curiosity, how do you choose these ?

 SPI.setDataMode(2);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(LSBFIRST);

This is my complete sketch. When you say something seems missing, in what context do you say that?

The link I gave you about the SPI library explains the meaning of the code that you asked for.

Have you tried using I2C ?

Is you Nano 8MhZ or 16Mhz ?

Attached is a working sketch for five digital pots . It doesn't use Clockdivide or setSPImMode and it uses MSBFirst so I have to ask
why Mode 2? , Why LSBFIRST ? and why Clockdiiveby 2 ?

Look at the timing diagrams on your datasheet just to confirm you have all that correct and try experimenting with different changes of the three parameters I asked about. Google to see if you can find any example code for that chip (I couldn't).

FIVE_MCP4162_P_Digital_Pots_dly_10_ino.ino (2.54 KB)

Try this in your setup so that all SPI devices are disabled:

pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, HIGH);
pinMode(chipSelectPin2, OUTPUT);
digitalWrite(chipSelectPin2, HIGH);

Then all you need in the main loop is to wrap your SPI transactions like this:

digitalWrite(chipSelectPin, LOW);
// your SPI code
digitalWrite(chipSelectPin, HIGH);

why Mode 2?

Good point by raschemmel ... check the datasheet ... it says mode 0 or mode 3.

Read Page 8 about the temp calculation . Look at the algorithm shown and verify you are doing that. Look at the timing diagram and check your timing. Read the part about Internal/External sensor and ask yourself if you have that jumper on for Internal sensor.

When you say something seems missing, in what context do you say that?

I don't think the brain can distinguish between the feeling something is missing and the feeling something has been added.