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:
*/
// 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);
}