Quantcast
Channel: Infineon Forums
Viewing all articles
Browse latest Browse all 9892

TLE5012B E1000 with Arduino Mega

$
0
0
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.

Code:

//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 <spi_helper.h>
#include <TLE5012.h>

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.

Viewing all articles
Browse latest Browse all 9892

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>