I am working on my master's thesis using an Arduino Uno, but I am experiencing some difficulties as I am not very experienced with it. Specifically, I have four Hall sensors connected to a TLA2518 converter (SPI), which is in turn connected to the Arduino Uno using the following pins:
SCL pin 13 SDI pin 12 SDO pin 11 CS pin 10 I have also connected VD to V5 and GND to GND.
I am facing an issue where the readings on the serial monitor are always displaying as zeros when i use a magnet.
I am not sure if my code is correct, or if there is somethong wrong.
#include <SPI.h>
#define CS 10
void setup() {
// Initialize SPI communication
SPI.begin();
// Set the CS pin as an output
pinMode(CS, OUTPUT);
// Start serial communication
Serial.begin(9600);
}
void loop() {
// Select the first sensor
digitalWrite(CS, LOW);
// Send a command to read from the TLA2518
SPI.transfer(0b00001111);
// Read the data from the TLA2518
int msb = SPI.transfer(0x00);
int lsb = SPI.transfer(0x00);
int data = (msb << 8) | lsb;
// Deselect the TLA2518 converter
digitalWrite(CS, HIGH);
// Print the data to the serial monitor
Serial.println("Sensor 1: " + String(data));
// Select the second sensor
digitalWrite(CS, LOW);
// Send a command to read from the TLA2518
SPI.transfer(0b00011111);
// Read the data from the TLA2518
msb = SPI.transfer(0x00);
lsb = SPI.transfer(0x00);
data = (msb << 8) | lsb;
// Deselect the TLA2518 converter
digitalWrite(CS, HIGH);
// Print the data to the serial monitor
Serial.println("Sensor 2: " + String(data));
// Select the third sensor
digitalWrite(CS, LOW);
// Send a command to read from the TLA2518
SPI.transfer(0b00101111);
// Read the data from the TLA2518
msb = SPI.transfer(0x00);
lsb = SPI.transfer(0x00);
data = (msb << 8) | lsb;
// Deselect the TLA2518 converter
digitalWrite(CS, HIGH);
// Print the data to the serial monitor
Serial.println("Sensor 3: " + String(data));
// Select the fourth sensor
digitalWrite(CS, LOW);
// Send a command to read from the TLA2518
SPI.transfer(0b00111111);
// Read the data from the TLA2518
msb = SPI.transfer(0x00);
lsb = SPI.transfer(0x00);
data = (msb << 8) | lsb;
// Deselect the TLA2518 converter
digitalWrite(CS, HIGH);
// Print the data to the serial monitor
Serial.println("Sensor 4: " + String(data));
// Wait for a moment before sending another command
delay(1000);
}
there are link for Converter and hallsensor :
Hallsensor: https://www.mouser.de/datasheet/2/187/HWSC_S_A0012826248_1-3073340.pdf 2
The question is: why am I not getting any reaction from my sensor at serialmonitor ?
see the hallsesnor value at serialmonitor
This Answer uses the TLA2528 which exactly is the same as The TLA2518, but the TLA2518 uses SPI and is available in the European Market while the TLA2528 uses I2C and is available in the Chinese Market, but both have the same Registers for reading and resetting the ADC. here is the Code that I wrote in the Arduino IDE.
This was the first version that I used to test the logic and make sure that I am doing everything right! that's why you see me reading the MANUAL_CH_SEL Register to make sure that it selects the right channel.
The Code uses the Manual Mode to read each of the Channels, but the trick to make sure that it is working is to actually reset the ADC before every time you want to read from a new Channel!!
This ADC always works in a 2 frames configuration, whether it is to read the Registers, write them, read data.
I am gonna also add the c header file tla2528.c that you can find in the Texas Instruments Website. This file is written and published by them and I just used it for the addresses of the Registers.