TLE5012B E1000 with Arduino Mega

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
I have recently purchased TLE5012B E1000 and trying to interface it with an Arduino Mega. I am receiving data but that seems like junk data. My SPI settings are SPI mode 0, SPI CLK 8 MHz. I am using the same circuit as in the datasheet for the SSC interface. I am using a delay of 10 microseconds before reading data from the sensor. The MOSI is configured as input before reading the data and then the data is read. Once the data is read MOSI pin is set back to output.
Below is the debug data I get on my serial monitor.
SPI: Sent 80, end of message
SPI: Sent 1, end of message
SPI: Received F0, end of message
SPI: Received 40, end of message
SPI: Received 5B, end of message
SPI: Received C9, end of message

This command is for enquiring the STAT register.


//read function in my library
void TLE5012::Read(char addr) {
uint8_t dataOut;
// variable to hold the command data
TLE5012_Command cmd;

// 1. Prepare command to be sent
// read one single word without safety word
cmd.Bits.len = 1;
// read updated values
cmd.Bits.upd = 0;
// set starting address
cmd.Bits.addr = addr;

// this is a magic cookie to lock access to sys regs.
if (addr > 4) {
cmd.Bits.lock = TLE5012_MAGIC_SYSREG;
} else {
cmd.Bits.lock = 0;
}

// read operation
cmd.Bits.rw = 1;

// 2. start SPI, enable CS
spiStart();

// 3. send data on MOSI pin
spiSend(cmd.w >> 8);
spiSend(cmd.w);

// 10 nops should cause about 250ns stall
//delayMicroseconds(10);
delay(2000);


// 4. read adat from TLE5012
dataOut = getByteFromSpi();
dataOut = getByteFromSpi();
dataOut = getByteFromSpi();
dataOut = getByteFromSpi();

// 5. Stop SPI, disable CS
spiEnd();

// return 0;
}

//main code
#include
#include

TLE5012 AngleSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
AngleSensor.Init();
// delay(100);
// AngleSensor.Read(AVAL);
delay(100);
AngleSensor.Read(STAT);

}

void loop() {
// put your main code here, to run repeatedly:

}


Can someone please help me out.
0 Likes
3 Replies
User270
Level 5
Level 5
5 solutions authored First solution authored
Hi,
Looking to the datasheet figure 4-7 SSC timing my guess is that the SPI mode should be 1 instead of 0. The TLE5012B is shifting out the data with the rising edge of the clock and the Arduino should read with falling edge of the clock.
0 Likes
Not applicable
forix wrote:
Hi,
Looking to the datasheet figure 4-7 SSC timing my guess is that the SPI mode should be 1 instead of 0. The TLE5012B is shifting out the data with the rising edge of the clock and the Arduino should read with falling edge of the clock.


Hi thanks for the reply. I am still unable to get valid data when I change SPImode to 1 instead of 0. below is the data for two different modes

//mode 0
MODE 4 reg
SPI: Sent D0, end of message
SPI: Sent E1, end of message
SPI: Received 94, end of message
SPI: Received 10, end of message
SPI: Received 5F, end of message
SPI: Received 35, end of message // crc from sensor

calculated CRC8 3B

//mode 1
SPI: Sent D0, end of message
SPI: Sent E1, end of message
SPI: Received 9C, end of message
SPI: Received 10, end of message
SPI: Received 7F, end of message
SPI: Received 3F, end of message //crc from sensor

calculated CRC8 B0
0 Likes
Not applicable
Hi ManikantaRaju,

Did you ever get this sensor to work?
0 Likes